Guide
How to Write Rules for AI Coding Agents
Good AI coding rules are short, specific and tied to files, commands or patterns the agent can follow. Put stable project behavior in rules, and keep rare edge cases out. A rule earns its place when it prevents a mistake the agent has already made more than once.

On this page
- What does a reviewable agent task look like?
- Can I adapt the prompt to my repo?
- How should a team run each agent task?
- What should you keep after the run?
- What are the four rule types, and how do you keep rules clean?
- How do I start a rule when I'm staring at a blank page?
- Can a rule make the agent ask questions before it builds?
What does a reviewable agent task look like?
Give the agent one named task, only the context it needs and a check you can rerun. A task shaped this way produces a diff small enough to review and a result you can repeat.
- Move
- Start with a bounded task
- Use this when
- You have a named owner, target files and a clear done state
- Proof to save
- Issue, files, checks and owner are named
- Move
- Give the agent context
- Use this when
- The repo has patterns the agent must follow
- Proof to save
- Prompt cites files, errors and constraints
- Move
- Review the diff
- Use this when
- The task changes production code
- Proof to save
- Changed files, test output and risks are visible
| Move | Use this when | Proof to save |
|---|---|---|
| Start with a bounded task | You have a named owner, target files and a clear done state | Issue, files, checks and owner are named |
| Give the agent context | The repo has patterns the agent must follow | Prompt cites files, errors and constraints |
| Review the diff | The task changes production code | Changed files, test output and risks are visible |
Each move leaves proof that a reviewer can check later.
Each move fails in its own way. Without a boundary, the agent edits files you never meant to open, and the diff becomes hard to read. Thin context fails more quietly: the code compiles and the tests pass, but the change ignores patterns the rest of the repo follows. Without a check you can rerun, you are taking the agent's word that the work is done.
Asking for a plan before the agent writes code is the easiest step to skip. It means a short wait while nothing visible happens, and the price of skipping it shows up later, in review.
If the plan names files you didn't expect, you learn that before any code exists. If it names the right files, you have a list to check the diff against. Once four hundred lines of diff are on screen, changing the approach means throwing that work away.
Interactive widget. Tab through its controls; the result updates in the panel below as you change them.
Open each stage to see what a reviewer should be able to inspect.
This exact topic is a hands-on Lesson: Rules and AGENTS.md — about 7 minutes, free to read.
Rather do it than read about it? Run 11 interactive Cursor walkthroughs in a simulated editor. Free, no account needed.
Can I adapt the prompt to my repo?
Yes. Treat the frame below as a starting point. Fill in your own files, constraints and done state, and keep the plan step, so the agent commits to an approach before it writes code.
Task: [one outcome] Context: [files, errors, docs and examples] Boundary: [what not to touch] Done when: [test, typecheck, screenshot or review proof] Before editing, write a short plan with files, risk and checks.
Fill the Context line with things the agent can open: file paths, the exact error text and the doc or example to follow. Paste errors instead of paraphrasing them, because a paraphrase drops the detail the agent needs to trace the cause.
The Boundary line is easy to leave out, and in our view it does the most work. Without it, every file the agent can reach is fair game. You end up reviewing incidental edits to config, imports and helpers you had forgotten about, mixed in with the change you wanted. Naming what not to touch takes a few seconds, and reverting stray edits afterwards takes far longer.
"Done when" has to name something you can run or look at: a test name, a typecheck, a command whose output you can read, or a screenshot of one specific state. "Done when the bug is fixed" doesn't count. It hands the judgment back to the agent, and the agent will report that the work is finished either way.
How should a team run each agent task?
The habit that matters most for a team is leaving a trail the next reviewer can follow. The steps below keep the prompt and its proof attached to the change.
- 1Pick one real backlog item with a clear owner and expected result.
- 2Add only the context the agent needs: files, failing output, constraints and done state.
- 3Ask for a plan before code when the task touches more than one file.
- 4Run checks that match the risk: unit test, typecheck, visual pass or review checklist.
- 5Capture the prompt, diff, result and reviewer note so the workflow can be repeated.
Match the effort to the change. A one-file fix needs a clear done state and a typecheck, and a plan adds little. A change across several files is where a plan pays for itself, and where the check should include tests and a reviewer who knows that code.
What should you keep after the run?
Keep whatever lets someone rerun the work or pick it up later. A finished task is the merged code plus a short trail that shows how it got there.
- The prompt or plan that shaped the work.
- The files changed and the reason each file changed.
- The command, screenshot or review note that proved the result.
- The rule, checklist or template you would reuse next time.
The last item pays off over time. A rule or template saved from one good run means the next run starts from what already worked, not from a blank prompt.
What are the four rule types, and how do you keep rules clean?
Rules are persistent instructions that Cursor adds to the model's context. They apply in Agent chat, in every mode, but not to Tab completions or BugbotCursor's automated PR reviewer that posts inline findings and can push fix commits from isolated VMs. Press Enter for the full definition.'s pull request reviews. A project rule has one of four types, and the types differ in when the rule applies. If your repo still has a .cursorrules file, Cursor calls it legacy and says it will be deprecated, so move its contents into a project rule set to Always Apply.
- Rule type
- Always Apply
- When it fires
- Attached to every prompt, so keep it tiny.
- Rule type
- Apply Intelligently
- When it fires
- You write a description, and the agent applies the rule when it judges it relevant.
- Rule type
- Apply to Specific Files
- When it fires
- One or more glob patterns (such as
*.tsx). The rule loads only when a matching file is in context.
- Rule type
- Apply Manually
- When it fires
- Invoked on demand with an
@-mention while you prompt.
| Rule type | When it fires |
|---|---|
| Always Apply | Attached to every prompt, so keep it tiny. |
| Apply Intelligently | You write a description, and the agent applies the rule when it judges it relevant. |
| Apply to Specific Files | One or more glob patterns (such as *.tsx). The rule loads only when a matching file is in context. |
| Apply Manually | Invoked on demand with an @-mention while you prompt. |
Create a rule with /create-rule in chat, or from Customize > Rules > Add Rule. Both write the rule file to .cursor/rules.
Build rules reactively, not preventively
Cursor's field engineers warn that models do best with the least to pay attention to. In their example, an always-apply rule with 300 directives silently adds "…and also do these 300 other things" to every prompt, which dilutes every answer. Keep always-apply to the basics, such as your tech stack, what you are building and key constraints. Cursor's rules docs say to add a rule only when you notice the agent making the same mistake repeatedly, so don't write "just in case" rules.
Don't reimplement your linter as a rule. The linter already catches the problem deterministically, while an always-apply rule injects that content into every call and wastes tokens.
Rules cost tokens only when they load. You pay for an always-apply rule on every submission, and for a glob-scoped rule only when a matching file is in play. Scope rules to files so unrelated work stays cheap.
Revisit rules on long projects so they don't go stale or conflict. Field engineers also find that newer models need fewer preventive and behavioral instructions than models did a year or two ago.
How do I start a rule when I'm staring at a blank page?
Don't write it from scratch. Cursor ships built-in skills for this: type /create-rule, /create-skill or /create-subagent in Agent chat and describe what you want. The agent writes the file with the right frontmatter and scope. From there you refine it in the same chat: "help fix the linting errors," then "I don't like this part, add that." The blank page is the hard part, and these skills remove it.
Reach for the template first, then refine in conversation until the rule is right.
You can actually go to the chat and hit create rule, create sub agent, create skill. There's already a built-in template within Cursor that helps with a prompt that helps you start creating this rule.
Can a rule make the agent ask questions before it builds?
Yes, and in our view it is one of the most useful rules you can write. Agent has a built-in tool for asking clarifying questions, and Plan modeA mode that makes no edits: it researches the codebase and produces an editable plan you review before any code changes. Press Enter for the full definition. asks them before it writes the plan. A short rule or a skill can tell the agent to ask every time. A presenter in Cursor's data science workshop calls the tool by name ("feel free to use the ask clarification toolA Plan-mode tool that lets the agent pause and ask you for direction before building; it surfaces on vague prompts or when you invoke it explicitly. Press Enter for the full definition.") and built a skill so the questions come every time.
One data-science practitioner built a skill that does exactly this. The questions it generated were concrete, like how charts should handle multiple user IDs, or which extra domains to include (sleep, heart rate, active minutes).
I actually have a skill... that tells Cursor that anytime you use plan mode, ask me at least six or seven questions before going in and making the plan.
The questions surface the assumptions the model would otherwise guess at, and you correct them before any code exists. That costs less than auditing a plan built on the wrong premises.
Frequently asked questions
Who is this guide for?
Teams creating shared Cursor rules or agent instructions.
What should I do next?
Find one mistake your agent has made more than once and write a short, file-scoped rule for it with /create-rule. Leave everything else out until the agent repeats a mistake.
How do I get the agent to ask clarifying questions before it builds?
Use Plan mode, which asks clarifying questions before it writes the plan, and ask for the questions in a rule or a skill. One Cursor workshop presenter uses a skill that tells Cursor to ask at least six or seven questions whenever it enters Plan mode, so assumptions get corrected before any code is written.
Do rules cost tokens?
Yes, but only when they load into context. An always-apply rule is included with every prompt, so you pay for it each time. A glob-scoped or manually invoked rule costs nothing until a matching file is in context or you @-mention it, which is why you scope rules to files and keep always-apply minimal.
Sources & last verified
- Cursor agent best practices
- Cursor Learn: working with agents
- Cursor Learn: context
- Cursor docs: prompting agents
- Cursor docs: Rules
- Cursor Help: Rules
- Cursor docs: Skills
- Cursor docs: Agent overview
- Cursor docs: Plan Mode
Cursor ships frequently. Facts verified against primary sources on October 28, 2026.