Cursor Rules: How to Write, Scope and Maintain Them

You ask Cursor to add an API endpoint. The implementation looks reasonable, except it bypasses the validation helper your team uses everywhere else. You explain the convention, get the change fixed, then repeat the explanation on the next task.
Cursor rules give that instruction a home. The useful part isn't assembling a longer list of coding standards. It's deciding which guidance belongs with which work, making it specific enough to act on, and keeping it current. Start with one recurring correction. This guide shows how to turn it into a scoped rule, share it with teammates, and recognize when the agent needs more context than a file can provide.
What are Cursor rules?
Cursor rules are persistent instructions supplied to the agent as model context. They carry project conventions, personal preferences, or team guidance into coding conversations. For example, a rule can direct API work through an existing validation helper, so you don't have to repeat that instruction in each prompt. Cursor's rules reference explains the underlying behavior.
The four types of Cursor rules
Choose where an instruction lives by asking who needs it and what could make it wrong. “Keep explanations concise” can follow you between projects. “Use our catalog validation helper” belongs with the repository that contains it.
Team Rules are available on Team and Enterprise plans. Project Rules travel with the code when committed to Git; User Rules and Team Rules have separate account-level storage.
AGENTS.md is useful when several coding agents work in the same repository. In Cursor, nested files add instructions for their directory and its children, with more specific guidance taking precedence. A small root file might contain:
Use .mdc Project Rules when you need explicit activation controls. A plain .md file inside .cursor/rules is ignored by the rules system; changing the extension matters.
.cursorrules vs. .cursor/rules
The root .cursorrules file is the legacy format. Cursor's migration instructions say to copy its contents into a new Project Rule, select Always Apply to preserve the old behavior, and remove the old file. Cursor describes the format as slated for deprecation, without giving a removal date on that page.
Migrate first, then narrow the scope. Splitting an old all-purpose file into frontend, API, and testing rules is easier to review when you can distinguish the format change from changes to the instructions themselves.
How to create a Cursor rule
To add Cursor rules through the editor:
- Open Customize → Rules, then choose Add Rule (shown as New in some builds).
- Name the rule for the concern it covers, such as
api-validation. - Choose Apply to Specific Files and set the relevant file pattern.
- Write the instructions, then save the
.mdcfile under.cursor/rules. - Check its configuration and status in Customize before trying a representative task.
You can also type /create-rule in Agent and describe the rule you want. Review the generated file before committing it.
For an example repository with API handlers and shared validation helpers, .cursor/rules/api-validation.mdc could look like this:
The paths and helper names should point to real code in your project. The frontmatter controls inclusion; the Markdown body explains what to do. With alwaysApply: false and a glob, the rule attaches when a matching file is in context.
The @ reference gives Agent a file to read when needed. It doesn't copy that file's contents into the prompt automatically, so keep the essential instruction in the rule body. File references work this way across the editor, CLI, and Cloud Agents.
We tested this example in Cursor 3.27.6 with Cursor Grok 4.6 Medium, asking for a category endpoint in two identical synthetic TypeScript projects. Without the rule, Agent reused parseRequest and the ApiError shape and added success and missing-name tests. With the rule present, it produced identical code and tests; all four tests passed in each project. The neighboring endpoint already gave Agent a clear pattern for this task.
Test your recurring correction the same way. Compare the helper, error shape, and tests, rather than judging the response alone. If the instruction is missed, check the glob and try an explicit @api-validation mention.
Rule types by activation: always, auto-attached, agent-requested, manual
Storage and activation answer different questions. Project Rules live in one folder, but each rule can be included differently. Cursor's current UI uses the labels below; older guides often use “Auto Attached” and “Agent Requested.”
For file-scoped rules, choose patterns that reflect actual ownership:
src/components/**/*.tsxfor components below that directory.src/api/**/*.tsfor API code, including nested folders.docs/**/*.md, docs/**/*.mdxfor both documentation formats in one comma-separated string.
Cursor's glob examples distinguish *.ts, which matches root files, from **/*.ts, which reaches nested directories. A pattern that's too narrow can miss the code you meant to cover. One that's too broad brings unrelated instructions into the conversation.
Reserve Always Apply for guidance you want on every task. A migration checklist doesn't need to accompany a CSS change. For intelligent selection, describe the work that should trigger the rule: “Planning database schema changes and backfills” gives Agent more to go on than “Database best practices.” For an occasional checklist you deliberately invoke, omit both description and globs and use @migration-review.
How to write good Cursor rules
A useful rule makes a choice the agent otherwise has to guess. “Follow best practices” leaves that choice unresolved. “Use the existing ApiError response shape” identifies a local contract the reviewer can check.
Before:
After:
The improved version names an implementation path, a reference, and observable results. It also tells you when the rule needs maintenance: renaming parseRequest or changing the error contract should trigger an edit to this file.
Useful rule content usually includes:
- A local choice: which existing abstraction to use, including why an attractive shortcut would be wrong.
- A file pointer: one canonical example of the intended pattern.
- A relevant check: the repository's actual test or lint command, when it isn't obvious.
- A limit: what the change must leave alone, such as generated files or another service's storage layer.
Cursor recommends keeping each rule under 500 lines, splitting large rules, and referencing code instead of duplicating it. Treat that as an upper bound, not a writing target. A focused correction should take much less space.
Leave mechanical formatting to your formatter and linter. Use rules for the choices those checks don't explain: where error handling belongs, which shared component to extend, or why a dependency crosses an ownership boundary. If you're using spec-driven development, keep feature-specific acceptance criteria in the spec and enduring conventions in rules.
Review the rule alongside the code change it guided. Did it prevent the recurring mistake, or merely add instructions the reviewer still had to repeat? For architecture rules, also check whether the decision behind the instruction still holds; our architecture context becomes relevant when that answer depends on systems outside this repository.
Example Cursor rules
These examples assume a TypeScript application with separate component, API, test, and search directories. Replace the sample paths and names with your own. The API rule above covers validation; these three cover other recurring decisions. Their activation fields follow the documented Project Rule format.
Frontend components
Save this as .cursor/rules/components.mdc:
This is a project-specific code organization rule. It avoids repeating a general React tutorial while making the shared-component decision explicit.
Test conventions
Save this as .cursor/rules/tests.mdc:
Point at a test that demonstrates the pattern you actually want. An outdated fixture example spreads the same mistake more efficiently.
Architecture boundaries
Save this as .cursor/rules/search-boundary.mdc:
This gives Agent an approved route and a response when that route isn't sufficient. Pair the instruction with a dependency check in CI and test the check with a deliberately forbidden import. The instruction and the check serve different parts of the workflow: one guides the edit, while the other evaluates the resulting code.
Community collections such as awesome-cursorrules can suggest concerns you've missed. Read individual rules before adopting them, remove incompatible assumptions, and keep only guidance that explains your repository. Copying an entire collection makes someone else's technology choices your defaults.
Sharing and syncing rules across a team
“Global rules” can mean account preferences, local files, or organization policy. They don't all move between machines the same way. Cursor's storage and sync guidance makes these distinctions:
Project Rules: use Git. Commit .cursor/rules with the code, review edits through pull requests, and pull the current branch on each machine. Put the rule change in the same PR as a renamed helper or changed folder structure. A teammate on an older branch still has that branch's instructions.
Account User Rules: sign in to the same Cursor account. Preferences entered through Customize → Rules sync across devices. On the second machine, open that view and confirm the intended text is present. Use these for preferences that genuinely apply across all your projects.
Local user rule files: manage separately. Files under ~/.cursor/rules, or %USERPROFILE%\.cursor\rules on Windows, stay on that machine and don't sync through the account. If you maintain them, keep a deliberate backup or versioned source and copy updates to each machine. Profile exports don't include account User Rules or Team Rules either.
Team Rules: manage from the dashboard. An administrator can create and enable a shared rule, add a glob where appropriate, and choose whether to enforce it. Enabled rules sync to team members. Enforcement prevents members from disabling the instruction in Customize.
When guidance conflicts, Cursor documents precedence as Team Rules → Project Rules → User Rules, with applicable rules merged. Avoid relying on that ordering to clean up contradictory instructions: revise the weaker rule so the intended behavior is clear to humans too.
For rules distributed across repositories, Cursor also documents a plugin-based sharing route. Importing a GitHub repository through Customize requires a marketplace manifest; installing the plugin brings its rules with it. Don't assume a repository URL by itself imports a rules folder.
Give shared rules an owner. When the API team replaces its validation helper, someone should update both the implementation and the instructions that point at it. Otherwise, a successfully synced rule can still be wrong everywhere.
Where rules stop: architecture the agent can't see
A repository rule can describe a service boundary. Keeping every dependency, operational constraint, and design decision inside that file is another matter. If search starts reading a catalog replica, the old “use CatalogReader” instruction needs to be evaluated against that change, not copied into more prompts.
This is the architecture-context problem for coding agents. Local conventions tell the agent how your team usually implements a change. Current system context helps establish whether that change fits the services and dependencies around it.
Our Architecture IDE provides that decision context through its MCP connection. You need a Catio workspace containing the relevant architecture and requirements. To connect the Catio MCP to Cursor, follow the documented server setup, authenticate, select your organization and workspace, and verify the session before relying on its answers.
Among the tools the Catio MCP exposes, get_workspace_context retrieves requirements and architecture context. search_inventory_components finds components such as services and databases, while search_inventory_relationships retrieves dependencies and data flows. This lets a rule request current context rather than embed a dependency list that someone must maintain twice.
With Catio connected, a manual rule in .cursor/rules/architecture-review.mdc can encode that documented workflow:
Invoke @architecture-review when that review is needed. The rule supplies the trigger; the connected workspace supplies the facts.
Conclusion
Start with a correction your team keeps making, name the local convention, and scope it to the files where it matters. Test the result against the code you would approve, then maintain the rule in the same pull requests that change its helpers, paths, or contracts. Our API example produced the same result with and without the rule, which is a useful reminder to evaluate the actual change rather than the size of your rule collection.
Keep repository conventions in rules and retrieve system-level facts from their source. When a change depends on services and constraints outside the checkout, see how Catio brings architecture context into your coding IDE before expanding the rules file.
FAQ
Where do I put Cursor rules?
Put Project Rules in .cursor/rules as .mdc files. Use Customize → Rules for account User Rules, the dashboard for Team Rules, or AGENTS.md for plain Markdown project instructions. Rules guide Agent; they don't affect Cursor Tab completion.
Are .cursorrules files still supported?
Cursor's help page treats the root .cursorrules file as legacy and slated for deprecation. It recommends moving the contents to an Always Apply Project Rule, then removing the old file. The page doesn't specify a removal date.
How long should a Cursor rule be?
Cursor recommends fewer than 500 lines per rule. Aim for the shortest instruction that identifies the local choice, relevant example, and expected check. Split unrelated concerns rather than filling the available space.
Should I use Cursor rules or AGENTS.md?
Use AGENTS.md for straightforward instructions that several supported coding tools can read. Choose .mdc Project Rules when you need file-pattern matching, description-based selection, or manual activation. You can use both, provided their instructions stay consistent.

