Pillar guide
Cursor Rules: How to Write .cursor/rules That Actually Work
Cursor rules are persistent instructions that teach Cursor your conventions: stack, patterns, do's and don'ts. The modern format is one or more .mdc files under .cursor/rules/. Good rules are short, scoped and specific. Vague or bloated rules get ignored.
On this page
- What are Cursor rules?
- What format do Cursor rules use now?
- How do I create a rule without hand-writing the file?
- How do I write rules Cursor will follow?
- When should I use a skill instead of a rule?
- What are the four kinds of rule and when does each fire?
- Should a rule live with you, the repo or the whole org?
- Why does Cursor ignore my rules?
What are Cursor rules?
Rules are reusable context Cursor loads automatically so you don't repeat yourself every prompt. They encode your conventions ("use our logger, not console.log", "prefer server components", "never edit generated files") and apply across the project or to matching paths.
Rules are one of three primitives, and the cleanest way to tell them apart is by analogy. A rule is you should always wear your seat belt, a standard Cursor abides by on every change. A skill is this is how you parallel park, a recipe the agent runs through when the task calls for it. A sub-agentA child agent a main agent spawns to work in parallel with its own context window, handing results back so the parent's context stays clean. Press Enter for the full definition. is your car on autopilot, parking on its own, a specialist persona you hand a job to. All three are just Markdown files that read differently. Reach for a rule when you want a standard that's always in force.
Interactive widget. Tab through its controls; the result updates in the panel below as you change them.
Rules are the standards you must follow; skills are an on-demand playbook a human or agent can invoke; sub-agents are specialists that follow your rules and can call your skills. Autonomy climbs left to right, direct control drops.
The analogy hides the cost. A seat belt is free to keep wearing and a rule is not, since every line of it sits in the prompt next to the work you actually asked for. Most of what follows is about narrowing when a rule fires rather than about what it says, and that emphasis is deliberate.
Rules that load before the edit
0:37 · narratedRead this demo as text
- Open Cursor Settings, Rules. search-scope is a project rule — it only applies under the file path src/components/search.
- Close Settings and open Agent chat. The prompt names the search-scope rule and AGENTS.md so you can see whether the agent loaded them.
- Send it. Watch the agent load search-scope and AGENTS.md, then edit EmptyState only — durable instructions beat retyping the same correction.
Practice next: Practice this yourself in the hands-on module.
Simulated Cursor 3.12 (macOS, light) — beta educational reconstruction, not the real product.
This is covered hands-on in Rules, Skills, Hooks and Subagents — 6 short modules, free to read.
What format do Cursor rules use now?
The current format is one or more `.mdcMarkdown-Cursor rule file. The file format for a Cursor rule; set always_apply to false and scope it so the rule only fires on the files that need it instead of burning context every request. Press Enter for the full definition.` files in a `.cursor/rules/` directory. Each file has frontmatter (a description and optional file globs that scope when it applies) and a Markdown body of instructions. The old single-file `.cursorrules` at the repo root is deprecated. Migrate to the directory format.
--- description: TypeScript & React conventions globs: ["**/*.ts", "**/*.tsx"] alwaysApply: false --- - Prefer function components and hooks. - Use our `@/lib/logger`, never console.log. - Validate all server-action inputs before use.
Splitting one file into several looks like busywork from the outside. What the directory format adds is the frontmatter block above, and those three fields are the entire mechanism: description, globs and alwaysApply are what decide whether a rule is included at all. Give your Python conventions their own globbed file and they stay out of context on every React edit.
If you still have a root .cursorrules file, split it into scoped .mdc files under .cursor/rules/. The directory format is what current Cursor expects and lets you target rules by path.
How do I create a rule without hand-writing the file?
Don't author the .mdc by hand. Cursor ships a default `/create rule` skill that generates the rule from code you already have. Point it at a file: /create rule create a generic API rule based on @main.py, and the agent writes the frontmatter and body for you. Then iterate the same way: ask the agent to update the rule until it captures the convention you mean.
One QA engineer generated a backend-unit-testing rule by pointing /create rule at an existing test file, then scoped it to the backend test directory so it auto-loads whenever the agent works near those files. The rule carried the framework choice (pytest), the required test structure, naming conventions, a sample per endpoint type and how to run the suite.
I actually cheated. I didn't write this rule myself. I used /create rule.
Then read what it wrote. A generated rule tends to describe the file it came from, and the part worth keeping is the part nobody could have inferred from the code around it, so most of the editing is deletion. Where the rule needs to show a shape rather than describe one, Cursor's docs suggest pointing at the file (@component-template.tsx) instead of pasting its contents in. The rule stays short that way, and it doesn't go stale when the template changes.
That's the case for a rule over inference: exotic conventions the agent can't guess from existing files. Team-specific practices, JSON-config test parameters, remote-deploy or dev-server setup steps that live outside the test code. Scope the rule to the directory it governs and it travels into context exactly when it's needed.
How do I write rules Cursor will follow?
Cursor follows rules that are easy to apply and hard to misread. Four habits get you most of the way:
- Scope with globs: a React rule shouldn't load for your SQL migrations.
- Be specific and short: concrete do/don't lines beat paragraphs of philosophy.
- One concern per file: testing rules, style rules and security rules separate.
- Show, don't lecture: a one-line example is worth a paragraph of description.
Short means shorter than you'd guess. Cursor's own open-source rules run about eight lines each. Context is a scarce resource, and every line of an always-on rule competes with the actual task for the model's attention.
I used to read "keep it short" as a token-budget argument. That's part of it and the smaller part: a short rule is also a rule with nowhere to hide a contradiction, and long rules usually got long by accreting exceptions that now disagree with each other. So read for contradictions first and cut for length second.
Contrary to popular belief, the rules Cursor ships are very short, often only eight lines long. If you have a rule that runs past 100 lines, trim it down or split it into several file-scoped rules. A glob-scoped rule with alwaysApply: false (say, a Java-import fixer that only fires on .java files) costs nothing until you touch a file it targets.
Cursor's docs carry a list of what to leave out, and I find it more useful than the list of what to put in. The agent already knows npm, git and pytest, so documenting your commands buys nothing. Edge cases you hit twice a year still cost context on every request that pulls the rule in. And anything already visible in the codebase should be pointed at rather than copied, because the copy stops matching the code the next time somebody edits it.
When should I use a skill instead of a rule?
Use a rule when you want guidance that's always in force; use a skill when you want a procedure the agent will reliably run through. A rule that says "use the development build profile" can work, but it's soft: the agent may or may not follow it. A skill encodes the definitive steps, so the agent runs the whole workflow rather than interpreting a hint.
Picking an iOS build variant (preview, development, production) is a good example. A rule can nudge the agent toward the right profile, but a skill makes the choice and the build steps deterministic.
Having a skill is a definitive workflow the agent will definitely run through, versus it being more guidance. So I find skills can be a lot more effective for that.
The reverse case gets less airtime. A skill has to be invoked, either by you or by the agent judging it relevant, which makes it a poor container for a constraint that has to hold on every change. Use our logger, never console.log is a standing condition on whatever work happens to be running, so it belongs in a rule and stays there.
What are the four kinds of rule and when does each fire?
A rule's frontmatter decides when it loads. Create rules from Settings > Rules, Skills, and Sub Agents > project > Rules > New, which writes an .mdc file under .cursor/rules/ with a name, description and apply header.
There are four apply modes, and they sit on a spectrum from always-on to never-unless-asked. Always loads into every prompt, apply intelligently lets the agent pull the rule in when the description matches, file-glob scopes it to matching paths, and manual waits for an @-mention. Pick the narrowest mode that still fires when you need it.
- Rule type
- Always
- Fires when
- Loaded into every prompt in the project. Use sparingly.
- Rule type
- Apply intelligently
- Fires when
- The agent reads the description and pulls it in when relevant.
- Rule type
- File-glob scoped
- Fires when
- Loads only when you touch matching paths (e.g.
**/*.tsx).
- Rule type
- Manual (@-mention)
- Fires when
- Loads only when you @-mention it, like a one-off checklist.
| Rule type | Fires when |
|---|---|
| Always | Loaded into every prompt in the project. Use sparingly. |
| Apply intelligently | The agent reads the description and pulls it in when relevant. |
| File-glob scoped | Loads only when you touch matching paths (e.g. **/*.tsx). |
| Manual (@-mention) | Loads only when you @-mention it, like a one-off checklist. |
Scope is the difference between a rule that helps and one that dilutes every prompt.
A rule that says "do this, and also these 300 other things" makes every answer worse, because the model spreads its attention across all of it. Add a rule when you catch the agent doing the wrong thing, not in anticipation of everything it might do. And don't reimplement your linter as a rule; let deterministic tools do deterministic work.
Manual (@-mention) rules aren't just one-off checklists. They're how you give agents running side by side distinct behavior. Tag a strict code-reviewing rule into one chat and it becomes your reviewer; tag a keep it simple rule into another and it stays terse; leave a third untagged and it inherits neither. One Markdown directive, dictated per agent, without anything going global.
Should a rule live with you, the repo or the whole org?
Where a rule lives decides who gets it. The same .mdc mechanics apply at every level, from rules that follow you personally to rules an admin sets for a whole org:
- User scope: personal rules that travel with you across projects.
- Repository scope: committed
.cursor/rules/every collaborator inherits. - Team scope: on Teams and Enterprise, rules saved in the codebase or pushed team-wide so anyone in the repo inherits them.
- Org scope: admins scope configs per group, so the design team, PMs and security each get their own set.
Rules and skills start local; to share them you promote them up that ladder. An org-wide security rule is the cleanest example: when writing SQL, don't allow injections, enforced across every team automatically rather than left to each developer to remember.
How far up to push depends on how many people sit downstream. On a team of four, committed repository rules cover it. Everyone touches everything, and a rule someone disagrees with gets argued out the same afternoon. The same rule pushed org-wide at four hundred people has no such loop, because the person it annoys has no obvious route back to whoever wrote it. Team RulesRules promoted to apply across a whole organisation and shared consistently between the Cursor IDE, Agent and Bugbot. Press Enter for the full definition. can be saved without enforcement, which leaves the on/off switch with each member, and on a large org that's where I'd start.
There's a sideways route as well. From Customize you can add a Remote Rule pointing at a GitHub repository you have access to, public or private, and Cursor pulls the .mdc files it finds there into .cursor/rules/imported/<repoName> and syncs them. Useful when one platform team maintains the rules and a dozen product repos consume them, though the imported copies do land in your tree.
Why does Cursor ignore my rules?
The common causes: the rule isn't scoped to the files you're editing (wrong or missing globs), the rule is too long or contradictory so it's diluted, the .mdc frontmatter is malformed or you're using the deprecated .cursorrules location. Tighten the glob, shorten the rule and confirm it's a valid .mdc under .cursor/rules/.
The first thing to rule out is the surface you tested on. Rules don't reach Cursor TabCursor's original autocomplete: multi-line, edit-aware suggestions you accept with the Tab key. Press Enter for the full definition. at all, and User Rules are read by Agent (Chat) and not by Inline Edit, so a User Rule you watched get ignored inside a ⌘K edit was never in scope there. Re-run the same request in the agent panel before you touch any frontmatter.
After that, the glob. When it isn't the glob, the rules fix page walks the remaining causes in the order they're worth checking.
In this guide
Copy-paste-ready .cursor/rules examples for TypeScript/React, Python, testing and security - with notes on scoping each rule so Cursor actually applies it.
Open guideWhat Cursor commands are and how to use them: reusable slash-menu prompts for multi-step jobs like running tests, fixing CI or opening a pull request.
Open guideHow Cursor's marketplace and plugins work: one-click bundles of rules, skills, sub-agents, commands, MCP servers and hooks, plus private team catalogues.
Open guideFrequently asked questions
Is .cursorrules deprecated?
The single-file .cursorrules is legacy. Current Cursor uses .cursor/rules/*.mdc files, which support per-path scoping via globs. Migrate existing rules into the directory format.
Where do I put Cursor rules?
In a .cursor/rules/ directory at your project root, as one or more .mdc files. You can also set global rules in Cursor's settings for conventions that apply everywhere.
Can I share rules across a team?
Yes. Commit .cursor/rules/ to your repo so every teammate gets the same conventions. Teams and Enterprise plans support centrally managed rules saved in the codebase or pushed team-wide, and admins can scope configs per group org-wide (for example, an enforced "no SQL injections" security rule).
Should I use a rule or a skill?
Use a rule for guidance that's always in force; use a skill for a definitive procedure the agent should run through. Rules nudge, skills execute. For deterministic workflows (like picking a specific build profile), a skill is more reliable than a rule.
Do Cursor rules cost tokens?
Only when they load. An always-apply rule is in every prompt's context, so it always costs tokens; a glob-scoped or manual rule costs nothing until you touch matching files or @-mention it. Scope rules tightly to keep prompts lean.
Why are my always-apply rules making the output worse?
Too much always-on instruction spreads the model's attention thin. Trim always-apply rules to the few that truly apply everywhere, scope the rest by glob, and add rules reactively when you see a real mistake rather than preemptively.
Sources & last verified
Cursor ships frequently. Last updated July 28, 2026.
Keep reading
Rather do it than read about it? Run 11 interactive Cursor walkthroughs in a simulated editor. Free, no account needed.