Skip to content

Context in practice For engineers

Cursor rules best practices: what to put in .cursor/rules

Cursor rules best practices come down to small, focused .mdc files in .cursor/rules, one concern per file, each scoped so it loads only when it is relevant. Rules shape Agent (Chat) only, not Tab completion. Start with one rule for a mistake Agent repeats, then check that it actually applied.

Short answer: what makes a good Cursor rule?

Following Cursor rules best practices means writing focused, actionable, scoped rules: one concern per .mdc file in .cursor/rules, under 500 lines, with a type that controls when the rule loads. Cursor's rules documentation recommends referencing files by path instead of pasting their contents, and adding rules when Agent repeats the same mistake.

Rules are prompt context for Agent (Chat). According to Cursor's documentation, they do not affect Tab completion or Bugbot PR reviews, so a rule cannot fix an autocomplete habit. Checked against Cursor's official docs on 26 November 2026.

Which Cursor rule types exist, and when does each load?

A project rule has one of four types, set from a dropdown in the editor or by three frontmatter fields: alwaysApply, description and globs. The type decides whether the rule costs context in every chat or only when it matters, so pick the narrowest one that still fires when needed.

Prefer Apply to Specific Files for code conventions, because the glob ties the rule to the files it describes. Use Apply Intelligently for workflows that do not map to paths, and write the description as a sentence Agent can match against the task.

Rule typeFrontmatterWhen it loads
Always ApplyalwaysApply: trueEvery chat session; globs and description are ignored
Apply to Specific FilesalwaysApply: false, globs setWhen a file matching the glob is in context
Apply IntelligentlyalwaysApply: false, description set, no globsWhen Agent judges it relevant from the description
Apply ManuallyalwaysApply: false, no description or globsOnly when you @-mention the rule in chat

Where do project, user and team rules live?

Project rules live in .cursor/rules as .mdc files and are version-controlled with the repository. A plain .md file in that folder is ignored, because it has no frontmatter. Subfolders work, but Cursor's help center suggests a flat folder with descriptive names such as api-validation.mdc.

User rules are personal preferences set under Customize, then Rules, and they apply across all your projects and sync with your Cursor account. Rule files in ~/.cursor/rules also act as user rules but stay on that machine. Team rules, on Team and Enterprise plans, are managed from the Cursor dashboard, can be enforced so members cannot turn them off, and support globs. When guidance conflicts, precedence is Team Rules, then Project Rules, then User Rules.

Cursor also reads a plain AGENTS.md in the project root and in subdirectories, where nested files combine with parent files and the more specific one wins. According to the help center, Cursor reads CLAUDE.md the same way and always applies it, so a repository shared with Claude Code needs no duplicate file.

What should go in a Cursor rule, and what should not?

Put in a rule the conventions Agent cannot infer and keeps getting wrong: where a service file goes, how errors are shaped, which template to start from. Leave out anything a linter, the code or Agent's general knowledge already covers. Cursor's documentation lists four things to avoid.

Referenced files are not inlined. A mention such as @service-template.ts tells Agent where to look, and Agent reads the file with its tools when it needs it. Anything that must always be in context belongs in the rule body itself.

  • Do not copy a whole style guide; use a linter.
  • Do not document common commands such as npm, git or pytest.
  • Do not add instructions for edge cases that rarely apply.
  • Do not duplicate code; point to a canonical example file.

Example: a scoped rule for API handlers

Example (fictional): a team keeps seeing Agent return raw error strings from new API handlers. The rule below loads only when a handler file is in context, states three checkable conventions and points to a template file instead of pasting it. Save it as .cursor/rules/api-handlers.mdc and adjust the paths.

---
description: Conventions for HTTP API handlers in src/api
globs: src/api/**/*.ts
alwaysApply: false
---

- Validate the request body at the handler boundary before calling a service.
- Return errors as { code, message } objects; never throw raw strings.
- One handler per file under src/api/handlers/.
- Start new handlers from @src/api/handlers/_template.ts and read it first.

How do you migrate from a legacy .cursorrules file?

Cursor's help center calls the root .cursorrules file legacy and says it will be deprecated. Moving it takes four steps, and the result behaves like the old file until you split it.

After the move, split the single Always Apply rule into scoped rules one concern at a time, so each part loads only when its files are in context.

  • Open the command palette and run New Cursor Rule.
  • Copy the .cursorrules content into the new rule file.
  • Set the rule type to Always Apply, which matches the old behavior.
  • Delete .cursorrules from the project root.

How do you check that a Cursor rule actually applied?

Start in Customize, then Rules, which lists every rule and its status. Cursor's troubleshooting advice is to check the rule type first: an Apply Intelligently rule needs a description, and an Apply to Specific Files rule needs a glob that matches the files you are working with.

Then test the behavior, not the file. Open a chat with a matching file in context and give a task the rule governs, such as adding a handler. If the output ignores the rule, @-mention the rule to apply it manually and compare. A rule that works only when mentioned most likely has a scoping problem, not a wording problem.

Where native tools are enough

For one engineer or a small team on one repository, project rules, AGENTS.md and team rules cover most needs. Run /create-rule in Agent to draft a rule with correct frontmatter, commit it, and update it when Agent makes a new mistake. If the same repository also uses Claude Code, the companion guide on CLAUDE.md best practices covers that file.

Rules record what to do. They are the right tool for conventions, templates and workflows that change slowly. Nothing more is needed until the guidance you keep adding is really a record of past decisions and why they were made.

CLAUDE.md best practices, with a template

Where Shifu fits

A rule says to return { code, message } errors. It rarely says which incident led there or which alternative the team rejected. Shifu is a context engine for AI coding teams. It is designed to retrieve the decisions, constraints and reasoning relevant to the task at hand, with sources, and serves them to coding tools including Cursor through MCP. We have not published customer results. Retrieval still needs an applicability check against the current code.

Ask about a four-week team pilot

Cursor rules checklist

Run this before you commit a new or changed rule.

  • Save the rule as an .mdc file in .cursor/rules, not .md.
  • Give it one concern and keep it under 500 lines.
  • Pick the narrowest type: globs for code, a description for workflows.
  • Reference template files by path instead of pasting them.
  • Move any remaining .cursorrules content into a rule and delete the file.
  • Confirm the rule shows in Customize and changes Agent's output on a test task.

Frequently asked questions

What is the difference between .cursorrules and .cursor/rules?

The .cursorrules file is a single legacy file in the project root that Cursor's help center says will be deprecated. The .cursor/rules folder holds separate .mdc project rules, each with frontmatter that controls when it loads. To migrate, copy the old content into a new rule, set it to Always Apply to match the old behavior, and delete .cursorrules.

Why is my Cursor rule not being applied?

Check the rule type first. An Apply Intelligently rule needs a description so Agent can judge relevance, and an Apply to Specific Files rule needs a glob that matches the files in context. Also confirm the file uses the .mdc extension, because Cursor ignores plain .md files in .cursor/rules. Rules apply only to Agent (Chat), not Tab completion.

How long should a Cursor rule be?

Cursor's documentation recommends keeping each rule under 500 lines and splitting large rules into smaller, composable ones, each covering a single concern. Shorter rules also stay accurate longer. Reference template or example files by path rather than pasting them, and put only content that must always be in context directly in the rule body.

Does Cursor read AGENTS.md and CLAUDE.md?

Yes. Cursor reads a plain AGENTS.md in the project root and in subdirectories, combining nested files with their parents, with the more specific file taking precedence. According to Cursor's help center, CLAUDE.md is read the same way and always applied. For rules that load conditionally by file pattern or relevance, use .mdc project rules in .cursor/rules instead.

Sources and further reading

Prepared with AI assistance and reviewed for source fidelity and practical usefulness. Examples marked fictional are illustrations, not customer results.

PUT THE CONTEXT TO WORK

Try it on one feature.

If your team keeps adding Cursor rules to explain past decisions, ask about a four-week team pilot for 2 to 4 engineers on one project.

Ask about a team pilot

Keep reading