Set up reusable project rules in Cursor
Write a project rule for specific files, check its frontmatter and status, inspect a small edit, and switch to manual attachment when needed.
Before you start · 1. Write down the one problem to fix · 2. Choose how it applies and set the frontmatter
At a glance
Project rules live in .cursor/rules and are version-controlled with the code. State the convention for the target files, choose its application mode, then check configuration and the task diff. Use manual mode to stop automatic attachment. A matching output alone does not prove the rule was attached.
Workflow
Conventions for the rule
The documentation suggests starting simple and adding a rule only when Agent repeats the same mistake. A one-off request can go straight into the chat.
Choose an application mode
Three fields, alwaysApply, description and globs, decide when a rule enters the context: always, chosen by description, matched by file pattern, or only when you @-mention it.
Check configuration and changes
Use a fresh chat with a matching file in context and see whether the output follows the rule. If it does not, check the type and the pattern first.
Before you start
- A local project already open in Cursor, with access to an Agent chat.
- One specific, repeated problem you can describe, rather than a vague goal like "keep code clean".
- Git or another version control, so the rule file can be committed and reverted along with the code.
1. Write down the one problem to fix
In a note, write one sentence: which files, what Agent keeps doing wrong, and what the right behavior is. For example: "In .tsx files under src/components, Agent uses default exports; it should use named exports." One rule covers one kind of problem, and the documentation recommends splitting large rules into smaller composable ones.
2. Choose how it applies and set the frontmatter
Choose frontmatter for the intended mode: alwaysApply: true always attaches the rule and ignores globs and description; file matching uses alwaysApply: false with nonempty globs; intelligent application uses alwaysApply: false, nonempty description and no globs; manual application uses alwaysApply: false with neither description nor globs. Remove fields that no longer apply when changing an existing rule. File matching attaches when a matching file is in context; multiple patterns can be comma-separated.
3. Create the rule file
There are two entry points. You can type /create-rule in an Agent chat and describe what you want, so Agent generates the file with frontmatter and saves it to .cursor/rules. Or you can open Customize in the sidebar, go to Rules and click Add Rule. Either way the file must use the .mdc extension, because the rules system ignores a plain .md file in that folder.
4. Write a short, actionable body
List the practices as bullets, keep the rule under 500 lines, and avoid vague wording. When a template matters, point to it with @filename instead of pasting it; the documentation states a mentioned file is not inlined into the prompt and Agent reads it only when needed. Anything that must always be in context goes directly into the rule body.
5. Verify in a fresh chat
Start a new Agent chat, open or reference a file that matches your globs, and ask for a small task that would trigger the problem, such as "add a title prop to this component". Check whether the change follows the rule. If not, use the FAQ checks: an intelligently applied rule needs a description, and a file-matched rule needs a pattern that really matches the file in context. Also inspect the rule and its status in Customize → Rules. Check its path, extension, frontmatter and whether a matching file is in context. Compliance in the output is a task check, not independent proof that this rule was attached.
6. Commit, iterate and stop
After checking configuration and the diff, commit the rule. Revise the existing rule when needed and avoid duplicates. To stop automatic attachment, set alwaysApply to false and omit description and globs. This is manual mode, so an @ mention can still attach the rule; it is not fully disabled. Recheck the status in Customize and the frontmatter.
Original example
Synthetic example: a fictional small storefront front end with components under src/components/.
Input: create .cursor/rules/components-tsx.mdc with this content.
---
globs: src/components/**/*.tsx
alwaysApply: false
---
- Use named exports, not default exports
- Keep styles in a module CSS file next to the component
- When a component passes 200 lines, extract subcomponents into the same directory
Action: open a new Agent chat, open src/components/PriceTag.tsx, and enter "Add a currency prop to PriceTag and keep the existing style".
What to check: whether the export is still a named export and the styles stayed in the sibling module file. If Agent still uses a default export, confirm the extension is .mdc, the path is under .cursor/rules, and the globs match PriceTag.tsx, then retry. This is an illustrative input, not a real output from a run.
Completion checks
- The rule file sits in .cursor/rules and ends in .mdc, not .md.
- Frontmatter matches the mode. Intelligent application uses alwaysApply: false, nonempty description and no globs. Fields that no longer apply are removed after a mode change.
- The glob really covers the file you test with; ** means any number of directories.
- The fresh-chat task diff follows the convention. Check configuration with the Customize status and matching file; matching output alone does not establish attachment.
- The body is short and does not copy a whole style guide or large code blocks.
Limits
- Rules are prompt-level guidance; the documentation says AI guidance should not be your only security control.
- Rules do not affect Cursor Tab or other AI features; they guide Agent chats.
- A file mentioned with @ is not inlined; content that must always be visible belongs in the rule body.
- This covers project rules only. Team Rules need a team plan and the dashboard, and
AGENTS.mdis a simpler alternative; both are outside these steps.
Verification scope
Only Cursor's official rules documentation was read. Login, installation, product API execution, file upload and generated output were not tested, and no rule was actually created. The example file is an original illustration; check the current documentation and your Cursor version for actual behavior.
Article sources
Original editorial content; official descriptions and checking suggestions are distinguished.