Cursor Rule Template: Write Rules the Model Follows
You wrote a rule that says "write clean, maintainable code," and Cursor kept generating the same sprawling components anyway. The rule was loaded. It just gave the model nothing to act on. Every vague rule you keep also takes up space in the context window that a sharper rule could have used.
A Cursor rule template is a fixed structure you use for every rule you write, so each one carries a scope, one instruction, a reason, an example and a way to check it. This article gives you that structure, a before-and-after comparison, and a short process for rewriting the rules you already have.
What makes a Cursor rule get followed or ignored?
A Cursor rule gets followed when it names one concrete action the model can take or avoid in the file it is editing right now. It gets ignored when it describes a quality, such as "clean" or "idiomatic," instead of a behavior.
The model reads your rule as text in its prompt, next to your code and your request. It has no separate rule engine. So a rule competes with everything else in the prompt, and the rules that win are the ones that map directly onto a decision the model is about to make: which import to use, which function to call, which pattern to avoid.
Three properties separate rules that work from rules that do not:
- Specificity. "Use named exports" is checkable. "Keep exports tidy" is not.
- Scope. A rule about React hooks has no business being loaded while the model edits a SQL migration.
- Evidence. A short example of the right output gives the model something to copy, which is stronger than a description of it.
What is the five-part Cursor rule template?
The five-part template is scope, directive, reason, example and check, in that order. Each part has one job, and a rule that skips a part is usually the one that misfires.
Here is a complete rule in the template, written as an .mdc file in .cursor/rules/:
---
description: Data fetching in Next.js App Router pages and layouts
globs: ["app/**/*.tsx"]
alwaysApply: false
---
Fetch data in Server Components with async/await. Do not add
useEffect plus fetch to load data a page needs on first render.
Why: client-side fetching on first render adds a request waterfall
and ships fetch code to the browser for no benefit.
Correct:
export default async function Page() {
const posts = await getPosts();
return <PostList posts={posts} />;
}
Incorrect:
'use client';
useEffect(() => { fetch('/api/posts')... }, []);
Check: grep app/ for "useEffect" next to "fetch(" in page files.Walk through the five parts one at a time.
1. Scope: the frontmatter
Scope is the description, globs and alwaysApply fields at the top of the file. They decide when the rule is loaded at all, which matters more than any wording below them. Globs attach a rule to file paths, the description lets Cursor pull a rule in by topic, and alwaysApply loads it on every request, so reserve that last one for the few rules that truly apply everywhere.
2. Directive: one imperative sentence
The directive is a single instruction in the imperative mood, with its negative counterpart if there is an obvious wrong way. One rule, one directive. If you find yourself writing "and also," split the file in two.
3. Reason: one sentence
The reason tells the model what the rule protects. This matters at the edges: when a request is ambiguous, a model that knows why a rule exists can apply it sensibly, while a model that only has the command applies it mechanically or drops it. Keep it to one sentence.
4. Example: correct and incorrect
Show a short correct snippet and a short incorrect one. Two to six lines each is enough. The incorrect example is the part people skip, and it is the part that prevents the specific mistake you wrote the rule to stop.
5. Check: how you would know
The check is a line a human can verify in under a minute, such as a grep pattern, a lint rule name or a command. You do not have to paste the check into every rule, but writing it forces you to confirm the rule is testable. A rule you cannot check is a rule you cannot debug.
How does a weak rule compare to a rewritten one?
A rewritten rule replaces a quality word with an action, adds a scope, and attaches an example. The table below shows four common weak rules and what each becomes.
| Weak rule | What is wrong | Rewritten directive |
|---|---|---|
| Write clean code | No action; "clean" is subjective | Keep functions under 40 lines; extract a helper when a block needs a comment to explain it |
| Use best practices for TypeScript | Unbounded; the model picks its own | Use unknown instead of any, and narrow with a type guard before use |
| Handle errors properly | No definition of properly | Wrap every fetch call in try/catch and return a typed Result; never swallow an error silently |
| Follow our naming conventions | The conventions are not in the prompt | Name React components in PascalCase, hooks as useThing, and files in kebab-case |
The 40-line threshold in the first row is an example, not a universal number. Pick a limit your team will actually enforce, and state it. A stated number the model can count against beats an adjective every time.
How do you rewrite your existing Cursor rules?
You rewrite them one file at a time, starting with the rules you suspect are being ignored. Use this order:
- Open one rule file and highlight every sentence that describes a quality instead of an action.
- Replace each highlighted sentence with one imperative directive and its negative form.
- Add a one-sentence reason after the directive.
- Write a correct and an incorrect example, each a few lines long.
- Tighten the
globsso the rule only loads for files it applies to. - Run the check, then ask Cursor for a change that should trigger the rule and confirm the output follows it.
Step six is the one that tells you whether the rule works. Make the test request narrow and realistic, such as "add a posts page that lists recent posts," and compare the output against the correct and incorrect examples in the rule. If the output matches the incorrect example, the rule is either not loading or not specific enough. The BuyCoded blog has separate posts on testing rules and on scoping them with globs if you want the detail.
Doing this for ten rules is an afternoon. Doing it for a rule set that covers several stacks, with scoped globs and examples for each, is weeks of careful writing and testing. That is the gap BuyCoded's Cursor Rules Mega-Pack fills: the product page lists 1,057 rules across 20 stacks, supplied in both Cursor formats, so you start from rules that already follow a consistent structure and edit them to fit your project. You can read the Cursor Rules Mega-Pack details before deciding whether it saves you the time.
What if my rules still do not work after rewriting?
If a well-formed rule is still ignored, the cause is almost always loading, not wording. Check that the rule is actually attached to the current file, that the globs match the path, and that you have not loaded so many rules that the important one is buried.
Rule volume is a real constraint, because every loaded rule consumes context. If rules worked on one stack and degraded when you added another, the usual cause is overlapping scopes: two rules that give different advice for the same file. Narrow the globs until each file matches only the rules meant for it.
Will a template make my rules too rigid or too long?
The most likely objection is that five parts per rule is heavy, and that you will end up with a folder of bloated files. It is a fair worry, and the answer is that the template is for rules that matter, not for every preference you have.
A one-line rule such as "use pnpm, not npm" does not need an example or a reason. Use the full template where the model has repeatedly got something wrong, or where the mistake is expensive: security, data access, build config. For everything else, one clear directive and a tight scope is enough. A short rule that is specific still beats a long rule that is vague.
What should you do next?
Pick the three rules you most often see Cursor break, rewrite them with the template above, and re-test each with a request that should trigger it. If you would rather start from a structured, stack-by-stack rule set than write from scratch, browse the BuyCoded product catalog, open the Cursor Rules Mega-Pack page, and check whether your stack is covered. Each product page lists what is included, and the catalog states a 14-day refund policy.
Frequently asked questions
How long should a Cursor rule be?
A Cursor rule should be as short as it can be while still holding one directive, a one-sentence reason and a brief example. Most effective rules fit in a dozen or so lines. If a file needs several unrelated instructions, split it into separate rules so each one can be scoped and tested on its own.
Should I put examples in every Cursor rule?
No, add examples where the model has made a specific mistake or where the right pattern is not obvious. A rule like 'use pnpm, not npm' needs no example. A rule about data fetching, error handling or security benefits from a short correct snippet and a short incorrect one.
What is the difference between a Cursor rule description and its globs?
The description tells Cursor what the rule is about so it can be pulled in when relevant, while globs attach the rule to files matching a path pattern. Globs are deterministic and tied to file paths. Use globs when a rule belongs to a file type, and a description when it belongs to a topic.
Why does Cursor ignore a rule I wrote?
Usually the rule is not loaded for the file you are editing, or it is too vague to act on. Check the frontmatter scope first, then confirm the globs match the path. If it is loaded, rewrite the wording as one specific imperative instruction with a short example of correct output.
Can I use the same rule template for Claude Code skills?
The principle carries over: one clear instruction, narrow scope and an example. The file format and trigger mechanism differ, though. Claude Code skills use their own structure and a description that decides when they fire, so write the description carefully and keep each skill focused on one job.