Cursor rules examples with .mdc files
Cursor project rules are .mdc files in .cursor/rules. Copy an always-on rule and a glob-scoped rule, see when AGENTS.md fits better, and test that each loads.
A Cursor rules example starts with the file format: a Markdown file with an .mdc extension in .cursor/rules/. Cursor ignores a plain .md file in that folder, so a misnamed file is the first thing to check when a rule never applies. The frontmatter at the top of each file decides when Cursor includes the rule in a chat, as Cursor's rules documentation describes.
What goes in the frontmatter of a Cursor rule?
Three fields control a rule: description, globs and alwaysApply. They combine like this:
alwaysApply |
globs |
description |
When Cursor includes the rule |
|---|---|---|---|
true |
ignored | ignored | In every chat |
false |
set | optional | When a file matching a glob is in context |
false |
empty | set | When the agent decides the description fits the task |
false |
empty | empty | Only when you @-mention the rule |
Globs are comma-separated, such as src/**/*.tsx or docs/**/*.md, docs/**/*.mdx. Rules can sit in subfolders of .cursor/rules/.
Cursor rules example: always-on and glob-scoped
An always-on rule is for the few lines that apply to every task. This one carries a build command and two conventions an agent can't guess:
---
alwaysApply: true
---
Run `make check` before you say a task is done. It runs lint, typecheck and tests.
Generated files in `src/gen/` are never edited by hand. Change the schema and run `make gen`.
Use `pnpm`, not `npm`. The lockfile is `pnpm-lock.yaml`.A glob-scoped rule is for conventions that belong to one kind of file. It loads when a matching file is in context, so it can be more detailed than an always-on rule:
---
description: Conventions for React components
globs: "src/components/**/*.tsx"
alwaysApply: false
---
- One component per file, named like the file: `UserCard.tsx` exports `UserCard`.
- Props are a `type` named `<Component>Props`, declared above the component.
- Fetch data in the route, not in a component. Components take props and render.
- Every component has a colocated `<Component>.test.tsx` that renders it and asserts on visible text.
- Style with Tailwind classes. Don't add CSS files.Cursor's guidance is to keep any one rule under 500 lines, to split large ones into several, and to point at files instead of copying their contents. One catch: an @file mention inside a rule isn't pasted into the prompt. The agent opens the file with its tools when it decides to, so anything it must see on every request belongs in the rule body.
Which type of Cursor rule should I use?
| Type | Use it for | Cost |
|---|---|---|
| Always apply | Commands and conventions that hold for every task | Uses context in every chat, so keep it to a few lines |
Specific files (globs) |
Conventions for one language, folder or file type | Loads only when a matching file is in context |
| Description only | A procedure for a task, such as "Use when adding a database migration" | Loads when the agent judges the description relevant, so write it as a trigger sentence |
| Manual | A long checklist you want only on request, like a release procedure | Loads only when you @-mention it |
The description is the weak point of the third type: a vague description means the rule rarely loads.
What happens when several Cursor rules apply?
Cursor merges every applicable rule. When they conflict, earlier sources win in this order: Team Rules, then Project Rules, then User Rules. Team Rules are managed from the Cursor dashboard on Team and Enterprise plans, and User Rules are your global preferences, set in Cursor's settings. Within project rules, avoid conflicts instead of relying on an order: two rules that give different test commands will make the agent's choice unpredictable.
Should I use AGENTS.md instead of .cursor/rules?
For project commands and shared conventions, yes. Cursor reads AGENTS.md in the project root and in subdirectories. A nested file applies to files in its own directory and below, it combines with the files above it, and the more specific one takes precedence. The file has no frontmatter, which also means Codex, OpenCode and Claude Code can read the same text. The AGENTS.md vs CLAUDE.md guide covers how those tools load it.
Keep .cursor/rules/ for what AGENTS.md can't express: a rule that should load only for certain files, or only when the agent judges it relevant. Older guides describe a single .cursorrules file at the repository root. Cursor's rules page documents only .cursor/rules/, so use that.
How do I check that a Cursor rule is applied?
Write a rule with an effect you can see, and remove it afterward. Put Start every reply with RULE-CHECK. in a temporary always-on rule, open a new chat and ask any short question. If the reply doesn't start with the marker, check the filename extension first, then the rule type.
For a glob-scoped rule, test both sides. Ask for a change with a matching file open, then ask an unrelated question with only a non-matching file in context. Cursor's FAQ points at the same two causes when a rule doesn't load: an "Apply Intelligently" rule needs a description, and an "Apply to Specific Files" rule needs a glob that matches.
Can stacks write Cursor rules for a new project?
Yes. Pass --agents cursor to stacks new and the stack's Cursor adapter writes .cursor/rules/*.mdc files, a .cursor/hooks.json that wires a guard against destructive commands and credential writes, and the shared AGENTS.md. A new TypeScript CLI project got an always-on agent-ops.mdc that points at AGENTS.md, plus glob-scoped rules for engineering conventions and Effect code. stacks show <id> lists every file a stack writes for each agent before you create anything.
The Cursor adapter is listed as unproven in the stacks documentation. It ships, but no project has been built to a green verify with Cursor yet, so expect rough edges. The Claude Code and Codex adapters have been.
Set this Go CLI up for Claude Code, Codex and Cursor.
I’ll generate all three adapters, then inspect where they point.
●Bash(stacks new go-cli team-cli --agents claude,codex,cursor --sandbox --no-launch)
●Bash(find team-cli/AGENTS.md team-cli/CLAUDE.md team-cli/.cursor team-cli/.codex team-cli/.claude -type f | sort)
Each agent gets its own config. AGENTS.md holds the shared project instructions.
●Bash(cat team-cli/CLAUDE.md)
●Bash(cat team-cli/.cursor/rules/agent-ops.mdc)
CLAUDE.md imports AGENTS.md, and Cursor’s rule points there too. I’ll fill the shared project details in AGENTS.md.