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. Keep rare edge cases out. A rule earns its place when it prevents a repeated mistake.
On this page
- What is the working pattern for AI coding agent rules?
- Can I adapt the prompt to my repo?
- How should a team run AI coding agent rules?
- What should you keep after the run?
- What are the four rule types and how do I 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 is the working pattern for AI coding agent rules?
The working pattern for AI coding agent rules is small enough to review and specific enough to repeat. Give the agent a named task and only the context it needs, then tie the result to a check you can rerun. The table below breaks that into moves.
- 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 |
A good AI coding workflow is specific enough to review and small enough to recover.
Each of those moves fails in its own particular way, and the order they come in is doing more work than it looks like it is. Skip the boundary and you get a diff nobody wants to read, because the agent has quietly rewritten files you never meant to open. Thin context fails more quietly: the code compiles, the tests pass, and it ignores every pattern the rest of the repo follows. Then there's the check, which to me is the real one, because it's the whole difference between a result you verified and a result you're taking someone's word for.
The step people skip is the plan. I think it's because it feels like overhead, thirty seconds of nothing visibly happening while you're trying to get work done. Actually, that's not quite the reason. It's that the cost of skipping it lands much later, so it never registers as the mistake it was. If the plan names files you didn't expect, you've learned something for free. If it names the right ones, you've got a reference to check the diff against when it arrives. And once there are four hundred lines on the screen, changing the approach means throwing that work away, which nobody is good at.
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: Project Rules and AGENTS.md — about 5 minutes, free to read.
Can I adapt the prompt to my repo?
Yes. The frame below is a starting point, not a script. 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.
The Boundary line is the one people leave out, and probably the one doing the most work. Without it every file the agent can reach is fair game, so you end up reviewing incidental edits to config and imports and some helper you'd forgotten existed, all mixed in with the change you actually wanted. Naming what not to touch takes a few seconds. Reverting it afterwards does not.
"Done when" has to name something you can run. A test name, a typecheck, a command whose output you can read, a screenshot of one specific state. "Done when the bug is fixed" doesn't count, and I'd say that's the single most common version of this mistake, because it quietly hands the judgment back to the agent, and the agent is going to tell you it's finished either way.
How should a team run AI coding agent rules?
Running AI coding agent rules as a team comes down to one habit: leave a trail the next reviewer can follow. The steps below keep the prompt and its proof attached to the change, so nobody has to reverse-engineer what the agent did.
- 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.
Task, context, constraints, done state and checks.
Open the diff, read changed files and rerun the check yourself.
Prompt, diff, test output and the review note that proved the result.
What should you keep after the run?
Keep whatever lets you rerun the work or hand it to someone else. A finished task is the merged code plus the short trail that explains 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.
What are the four rule types and how do I keep rules clean?
Rules are persistent directives Cursor injects into prompts to supplement what the model already knows. There are four types, and the difference is when each one fires.
- Rule type
- Always Apply
- When it fires
- Attached to every single prompt - keep this one tiny.
- Rule type
- Apply Intelligently
- When it fires
- You write a description; the agent invokes the rule when it judges it relevant.
- Rule type
- Apply to Specific Files
- When it fires
- One or more glob patterns (e.g.
*.tsx); pulled in only when a matching file is touched.
- 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 single prompt - keep this one tiny. |
| Apply Intelligently | You write a description; the agent invokes the rule when it judges it relevant. |
| Apply to Specific Files | One or more glob patterns (e.g. *.tsx); pulled in only when a matching file is touched. |
| Apply Manually | Invoked on demand with an @-mention while you prompt. |
Create rules via Settings > Rules, Skills and Sub Agents > Project rule, which writes an MDC file under .cursor/rules.
Build rules reactively, not preventively
Models do best with the least to pay attention to. An always-apply rule with 300 directives silently appends "…and also do these 300 other things" to every prompt, which dilutes every answer. Keep always-apply to the basics - tech stack, what you are building, key constraints - and add a directive only after the model makes the same mistake more than a few times. Do not write "just in case" rules.
Don't reimplement your linter as a rule. The linter already catches it deterministically; a rule just injects that content into every call and wastes tokens.
Rules cost tokens only when loaded. An always-apply rule is paid on every submission; a glob-scoped rule is paid 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. As models improve they need fewer preventative and behavioral instructions than they 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. In chat - and in the CLI - you can run create rule, create skill, or create 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., and Cursor hands you a built-in template plus a prompt that scaffolds it for you. From there you iterate conversationally 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 templates 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 it's one of the highest-value rules to write. 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. has an ask-clarification tool that lets Cursor solicit direction before building. It surfaces on its own when a prompt is vague, or you can invoke it explicitly ("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."). You can also pin the behavior in a skill so it fires 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.
Why it works: the questions surface the assumptions the model would otherwise guess at, and you correct them before any code exists. That is cheaper 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?
Start with one real repo task, capture the prompt and review the result before scaling the workflow.
How do I get the agent to ask clarifying questions before it builds?
Use plan mode's ask-clarification tool, and pin the behavior in a skill. Plan mode can solicit direction before building - it surfaces on vague prompts or when you invoke it explicitly. A reusable pattern is a skill that tells Cursor to ask six or seven questions any time it enters plan mode, so assumptions get surfaced and corrected before any code is written.
Do rules cost tokens?
Yes, but only when loaded into context. An always-apply rule is included with every prompt, so it costs tokens each time. A glob-scoped or manually invoked rule costs nothing until a matching file is touched or you @-mention it. This 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 ships frequently. Facts verified against primary sources on July 9, 2026.
Keep reading
Rather do it than read about it? Run 11 interactive Cursor walkthroughs in a simulated editor. Free, no account needed.