blog
/
Product
Product
November 15, 2026

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.

Type

Where it lives

Who it applies to

Good use

Project Rules

.cursor/rules/*.mdc in the repository

People working with that checkout

Local commands, code organization, architectural conventions

User Rules

Customize → Rules in your Cursor account

You, across projects

Communication preferences and personal working habits

Team Rules

The Cursor team dashboard

Members of that team

Organization-wide coding guidelines

AGENTS.md

Plain Markdown in the project root or subdirectories

Agents working in the relevant directory

Readable project instructions shared across supported coding tools

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:

# Project instructions
- Read CONTRIBUTING.md before changing code organization.
- Use the test commands defined in package.json.
- Keep generated clients unchanged; edit their source schemas.

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:

  1. Open Customize → Rules, then choose Add Rule (shown as New in some builds).
  2. Name the rule for the concern it covers, such as api-validation.
  3. Choose Apply to Specific Files and set the relevant file pattern.
  4. Write the instructions, then save the .mdc file under .cursor/rules.
  5. 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:

---
description: Conventions for catalog API request validation
globs: src/api/**/*.ts
alwaysApply: false
---
# API validation
- Read @src/api/catalog/create-item.ts before adding an endpoint.
- Use the existing parseRequest helper for request validation.
- Keep validation failures in the existing ApiError response shape.
- Add tests for malformed input and the successful response.

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.”

Current label

Familiar name

Frontmatter

When included

Always Apply

Always

alwaysApply: true

Every chat session; description and globs are ignored

Apply to Specific Files

Auto Attached

alwaysApply: false plus globs

A matching file is in context

Apply Intelligently

Agent Requested

alwaysApply: false plus description, without globs

Agent selects it based on the description

Apply Manually

Manual

alwaysApply: false, without description or globs

You @-mention it in chat

For file-scoped rules, choose patterns that reflect actual ownership:

  • src/components/**/*.tsx for components below that directory.
  • src/api/**/*.ts for API code, including nested folders.
  • docs/**/*.md, docs/**/*.mdx for 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:

Write clean code. Follow our coding standards.
Use good error handling and maintain type safety.

After:

- Use parseRequest from the existing API validation module.
- Return validation failures through ApiError, matching create-item.ts.
- Derive request types from the existing schema; don't duplicate them.
- Add a malformed-input test beside the endpoint's existing tests.

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:

---
globs: src/components/**/*.tsx
alwaysApply: false
---
- Reuse @src/components/ui/Button.tsx for button interactions.
- Keep application data fetching out of shared UI components.
- Follow the adjacent component's naming conventions and test layout.

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:

---
globs: tests/**/*.ts
alwaysApply: false
---
- Read @tests/catalog/create-item.test.ts for fixture setup.
- Use the existing makeCatalog fixture rather than shared mutable data.
- Add a regression case for the reported bug before changing behavior.

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:

---
globs: src/search/**/*.ts
alwaysApply: false
---
- Read @docs/decisions/catalog-access.md before changing catalog access.
- Read catalog data through CatalogReader.
- Do not import from src/catalog/db in search code.
- If CatalogReader lacks a needed operation, propose the API change.

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:

---
alwaysApply: false
---
Before proposing a service-boundary change:
- Call get_workspace_context for the current requirements.
- Use search_inventory_components and search_inventory_relationships
  to inspect the affected services and their dependencies.
- Explain how the proposal fits the returned constraints.
- Flag missing architecture context rather than assuming it.

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.

Share this Post

Related posts