Cursor Rules provide a powerful way to customize how AI interacts with your code. By creating project-specific or global rules, you can dramatically improve AI assistance quality and make the AI understand your project's specific requirements.
Project rules are stored in the .cursor/rules
directory and are automatically included when working with matching files. They offer granular control with:
Project rules are the recommended way to use Cursor Rules. They offer more flexibility and control compared to global rules and the older .cursorrules
format. .cursorrules
is now considered deprecated and project rules are the preferred method for defining project-specific AI behavior.
Best Practices for Project Rules (MDC Rules)
Based on community experiences and best practices 1, here are some recommendations for effectively using project rules:
File Format: Project rules must be saved as YAML files with the .mdc
extension. Simply placing other file types in the .cursor/rules
directory will not work.
Filename Numbering: Rules are loaded and potentially prioritized based on the numerical prefix in their filenames. It's suggested to use a three-digit numbering system for organization, such as:
001-099
for Core Rules100-199
for Integration Rules200-299
for Pattern/Role Rules001-Core-Security.mdc
, 110-CLI-Handler.mdc
, 200-File-Pattern-Rule.mdc
YAML Format: While other formats might technically work, YAML is highly recommended for its readability and support for comments, which can greatly aid in rule management.
Rule Creation: Using the Settings UI within Cursor is the most reliable method for creating rules and avoids potential errors. If creating files directly, ensure they end with .mdc
.
Example Rule Structure: A basic rule file structure in YAML would look like this:
---
name: Example Pattern Rule
version: "1.0"
globs:
- "src/**/*.py"
triggers:
- file_change
---
rule_definition:
description: "This rule applies to Python source files in the src directory."
Saving Issues Workaround: If you encounter issues where changes to .mdc
rule files are not being saved, a known workaround is to close Cursor completely. When prompted with the "Unsaved Changes" popup, select "Override" and then reopen Cursor.
Global rules apply to all your projects and are configured in Cursor Settings > General > Rules for AI. Perfect for:
Creating effective Cursor Rules is simple with our Cursor Rules Generator:
Start using Cursor Rules to make AI truly understand your project requirements and coding style. Generate your custom rules now to experience more accurate, project-aware AI assistance.
For users looking to further enhance their Cursor Rules workflow, the open-source project Cursor Agile Workflow Template by bmadcode offers a powerful solution for automated rule generation and agile workflow integration.
Key Features:
Rule Types Explained:
The template categorizes rules into five types, offering flexibility in how rules are applied:
Rule Type | Usage | description Field | globs Field | alwaysApply field |
---|---|---|---|---|
Agent Selected | Agent sees description and chooses when to apply | critical | blank | false |
Always | Applied to every chat and cmd-k request | blank | blank | true |
Auto Select | Applied to matching existing files | blank | critical glob pattern | false |
Auto Select+desc | Better for new files | included | critical glob pattern | false |
Manual | User must reference in chat | blank | blank | false |
Getting Started:
To explore and utilize this template, you can visit the GitHub repository for detailed instructions, quick start options, and documentation. It provides a valuable starting point for users aiming to implement a more sophisticated and automated Cursor Rules management system.
Based on community discussion in Cursor Community Forum: My Best Practices for MDC rules and troubleshooting ↩