Cursor Agent Mode and .cursor/rules/*.mdc: frontmatter, globs, and personality rules.
By Bernard Huang · Updated
Stop Cursor Agent from making unrequested refactors or writing essay summaries—configure alwaysApply, glob-scoped .mdc rules, and User Rules cleanly.
On this page
Build a ready-to-paste .cursor/rules/*.mdc file.
Generate a properly formatted .cursor/rules/agenttune.mdc file (with YAML frontmatter pre-configured) or switch output to AGENTS.md, Windsurf, or Cline:
All four Cursor rule attachment modes (.mdc frontmatter).
| Rule type | YAML frontmatter fields | When Cursor Agent loads it | Best used for |
|---|---|---|---|
| Always | alwaysApply: true | Every Agent & Chat turn | Core repo test commands, diff scope limits, communication style |
| Auto Attached | globs: ["src/api/**/*.ts"], alwaysApply: false | Whenever a matching file is in context | API validation schemas, SQL migrations, React/CSS conventions |
| Agent Requested | description: "...", alwaysApply: false | Agent chooses to pull it when relevant | Release checklists, deployment steps, design-system patterns |
| Manual | No globs, alwaysApply: false | Only when invoked via @rule-name | Occasional migration scripts or strict security audit passes |
Three battle-tested .cursor/rules/*.mdc templates for Agent Mode.
1. Safe Autonomous Execution (.cursor/rules/agent-guardrails.mdc)
2. Glob-Scoped Backend Route Rules (.cursor/rules/api-routes.mdc)
3. User-Global Personal Tone (Cursor Settings → Rules for AI)
Using Cursor alongside Claude Code, Codex CLI, Windsurf, or Cline? See our 7-agent coding rules matrix so your repo stays synced via one root AGENTS.md.
Questions people ask.
Did .cursor/rules/*.mdc replace the legacy .cursorrules file?
Yes. Modular .cursor/rules/*.mdc files let you separate always-on guardrails from glob-scoped language or directory rules so you don't waste context window tokens on irrelevant instructions.
Does Cursor Agent Mode read AGENTS.md too?
Yes. Modern Cursor versions support root AGENTS.md files alongside .cursor/rules/*.mdc, making AGENTS.md an ideal shared baseline for teams mixing Cursor, Codex CLI, and Claude Code.
Where do I put personal Cursor communication preferences without committing them to git?
Paste personal tone, brevity, and pushback rules into Cursor Settings → Rules for AI (user-level), or add .cursor/rules/personal-*.mdc to your local .git/info/exclude file.
How do I stop Cursor Agent Mode from rewriting working code outside my task?
Add an alwaysApply: true guardrail rule: 'Keep edits tightly scoped to the requested bug or feature; never refactor or reformat unrelated files unless explicitly asked.'
What changed.
- First published covering Cursor Agent Mode .cursor/rules/*.mdc frontmatter modes, interactive builder, and safe autonomous guardrails.