
Short answer
Every time you type "we use pnpm, not npm" into a chat, you are writing a rule by hand. Cursor's own advice is to add one when you notice Agent making the same mistake repeatedly, and not before. That's the spirit of this guide: fewer, sharper rules, each with a clear trigger.
Language models don't remember anything between requests. Cursor's rules docs describe rules as persistent, reusable context: when a rule applies, its text is placed at the start of the model context, so Agent sees it before your prompt. Rules shape Agent (Chat). They do not change Tab completions, and Cursor's help center says they don't apply to Bugbot pull request reviews either.
A rule is not a prompt. A prompt describes today's task; a rule describes how your project always works. If you want task prompts, our Cursor prompts collection has 20 of them, including a few that turn repeated corrections into rules.
| Type | Where it lives | How it is applied | Best for |
|---|---|---|---|
| Project rules | .cursor/rules/*.mdc in the repository | Always, by relevance, by file pattern or by @-mention, set in frontmatter | Conventions for this codebase, shared through git |
| User rules | Customize, Rules (synced to your account); files in ~/.cursor/rules stay on the machine | Used by Agent (Chat) in every project | Your own tone and working preferences |
| Team rules | Cursor dashboard, on Team and Enterprise plans | All members; admins can enforce a rule so it can't be turned off; optional glob patterns | Organization-wide standards |
| AGENTS.md | Project root and any subdirectory | Plain markdown, no metadata; nested files combine with parents | Simple instructions, or repos also used with other agents |
| .cursorrules (legacy) | Project root | Called legacy; Cursor says it will be deprecated | Nothing new: migrate it to a project rule |
When guidance conflicts, Cursor applies Team Rules first, then Project Rules, then User Rules, and earlier sources win. Two more files are worth knowing. Cursor reads CLAUDE.md the same way it reads AGENTS.md and always applies it, which keeps one instruction file working in both Cursor and Claude Code (our Cursor vs Claude Code comparison covers the rest of that choice). And because AGENTS.md is also what OpenAI's Codex reads, a shared AGENTS.md is the easiest way to keep several agents on the same page; see Codex vs Claude Code for how the instruction files compare.
To migrate an old .cursorrules file, Cursor's help center lists four steps: create a new rule from the command palette ("New Cursor Rule"), paste in the old contents, set the type to Always Apply to match the old behavior, then delete .cursorrules.
Each project rule has a type, picked from a dropdown that sets three frontmatter fields behind the scenes: description, globs and alwaysApply. The combination decides when the rule is loaded.
| Rule type | Frontmatter | When it applies |
|---|---|---|
| Always Apply | alwaysApply: true | Every chat session; globs and description are ignored |
| Apply to Specific Files | alwaysApply: false, globs set | When a file matching the pattern is in context |
| Apply Intelligently | alwaysApply: false, description set, no globs | When Agent reads the description and decides it is relevant |
| Apply Manually | alwaysApply: false, no description, no globs | Only when you @-mention the rule in chat |
Pick the narrowest type that works. Always Apply costs context in every chat, so keep it for facts that are true everywhere. File patterns suit framework or folder conventions. Apply Intelligently suits topics that cut across folders, such as error handling. Apply Manually suits checklists you only want on demand.
Build this with a prompt on Greta.sh — describe the app, Greta writes and deploys it.A project rule is a markdown file with frontmatter at the top and the instructions underneath. It must use the .mdc extension: Cursor ignores a plain .md file in .cursor/rules because it has no frontmatter. You can name the file anything and organize rules in subfolders, though the help center suggests a flat folder is simpler. Cursor identifies rules by their full path, so two files with the same name in different folders both apply.
These are starting points. Swap the bracketed paths and commands for your own, delete lines that don't fit, and commit them so the whole team gets the same behavior. Rules 1 to 8 are .mdc project rules covering all four types; 9 is AGENTS.md and 10 is a user rule.
Save as .cursor/rules/project-basics.mdc. The few facts Agent needs in every chat. Keep it short, because it is loaded every time.
--- alwaysApply: true --- - Package manager is [pnpm]. Never use npm or yarn in commands or docs. - Before saying a task is done, run [pnpm typecheck] and [pnpm test] and report the result. - App code is in [src/], shared UI in [src/ui/], server code in [src/server/]. - Ask before adding a new dependency. Say what it does and why the existing code can't do it. - Keep changes to the files the task needs. List any other file you think should change instead of editing it.
Save as .cursor/rules/ui-components.mdc. Attaches only when a matching file is in context, so the backend never sees it.
--- globs: src/ui/**/*.tsx, src/app/**/*.tsx alwaysApply: false --- - Clickable things are <button> or <a>, never a div with an onClick. - Every <img> has alt text. Decorative images use alt="". - Use the color and spacing tokens from src/ui/tokens.ts. No raw hex values or pixel sizes. - Every form input has a visible <label>. Placeholder text is not a label. - Loading, empty and error states are part of the component, not a follow-up task.
Save as .cursor/rules/tests.mdc. Keeps generated tests from drifting into a style nobody on the team uses.
--- globs: **/*.test.ts, **/*.test.tsx alwaysApply: false --- - Test runner is [Vitest]. Import from "vitest", not from jest. - One behavior per test. Name tests as sentences: "returns 404 when the invoice does not exist". - Use the factories in [tests/factories/] for data. Do not hand-write large fixtures. - Do not mock the module under test. Mock only network calls and the clock. - A bug fix comes with a test that fails before the fix and passes after it.
Save as .cursor/rules/api-routes.mdc. No globs, so Agent reads the description and decides when it is relevant.
---
description: Conventions for HTTP API route handlers, request validation and error responses
alwaysApply: false
---
- Validate the request body with the schema in the same folder before using any field.
- Check the user's permission for the specific record, not just that they are signed in.
- Errors return JSON shaped as { "error": { "code": "...", "message": "..." } } with the right status code.
- Never return stack traces or raw database errors to the client.
- Look at @src/server/routes/invoices.ts as the reference handler before writing a new one.Save as .cursor/rules/errors-logging.mdc. Pulled in when Agent is writing code that can fail.
--- description: How to handle errors and write logs anywhere in the codebase alwaysApply: false --- - Use the logger from [src/lib/log.ts]. No console.log in committed code. - Log one line per failure with an event name and ids, never with emails, tokens or full request bodies. - Catch an error only where you can do something useful with it. Otherwise let it reach the request handler. - Retries need a limit and a delay. No infinite loops around network calls.
Save as .cursor/rules/db-schema.mdc. Schema edits are where a confident wrong answer costs the most.
--- globs: prisma/schema.prisma, db/migrations/** alwaysApply: false --- - Every schema change ships with a migration. Never edit a migration that has already been merged. - New columns on existing tables are nullable or have a default, so the migration runs on a full table. - Renames happen in two steps: add the new column and backfill, then remove the old one in a later change. - Add an index for any new column used in a WHERE clause on a large table, and say which query needs it.
Save as .cursor/rules/pr-description.mdc. No description, no globs: it applies only when you type @pr-description in chat.
--- alwaysApply: false --- Write the pull request description from the current diff. Sections: What changed (3 bullets max), Why, How to test (exact steps or commands), Risks, Screenshots needed (yes or no). Mention any migration, new environment variable or feature flag at the top. Do not describe files line by line. Do not claim tests pass unless you ran them in this chat.
Save as .cursor/rules/careful-mode.mdc. Mention @careful-mode when you are working in code nobody fully understands.
--- alwaysApply: false --- Before editing anything, explain how the code you are about to change works and list every caller you found. Propose the smallest change that solves the task and wait for my approval. Do not rename, reformat or reorganize anything that the task does not require. If you are unsure what a function does, say so instead of guessing.
Save as [packages/mobile]/AGENTS.md. Plain markdown, no frontmatter. Cursor combines it with any parent AGENTS.md, and the more specific file wins.
# Mobile app instructions ## Stack - React Native with Expo. Do not add native modules without asking. - Navigation lives in src/navigation. Add new screens there, not inline. ## Rules - Test layouts at small phone widths first. - Strings go in src/i18n/en.json. No hard-coded user-facing text. - Run [pnpm --filter mobile test] after changes in this folder.
Paste into Customize, Rules, under User Rules. It applies across all your projects and syncs with your account.
Reply in short paragraphs. Lead with the answer, then the reasoning. When you change code, end with a list of the files you touched and anything I should test by hand. If my request is ambiguous, ask one clarifying question before writing code. Use British spelling in comments and docs.Want to try one of these? Start on Greta.sh — no setup, no boilerplate — just a prompt.
Don't trust a rule until you've watched it change Agent's behavior. A quick routine:
Rules don't make output correct, they make it consistent. Keep reviewing diffs the way our AI coding best practices describe, and when a rule keeps getting ignored, rewrite it as a concrete instruction rather than a value ("Use the logger in src/lib/log.ts" beats "write clean logs").
Cursor also has skills: SKILL.md files in folders such as .cursor/skills/your-skill-name/ that hold multi-step workflows. The help center draws the line clearly. Rules are short guidelines included as context in every chat or every matching chat; skills are longer procedures invoked on demand with /skill-name or @skill-name. "Use TypeScript for new files" is a rule. "Run the tests, build, deploy to staging and check health" is a skill. You can convert a rule into a skill with /create-skill, and Cursor 2.4 and later includes /migrate-to-skills for rules that have no globs and are not always applied.
What are Cursor rules?
Cursor rules are persistent instructions for Cursor's Agent. When a rule applies, its contents are included at the start of the model's context, so you don't have to repeat the same guidance in every chat. Cursor supports project rules, user rules, team rules and AGENTS.md.
Where do Cursor rules go?
Project rules go in .cursor/rules inside your repository as .mdc files and are version-controlled. User rules are set in Customize, Rules and sync with your Cursor account; user rule files in ~/.cursor/rules stay on that machine. Team rules live in the Cursor dashboard. AGENTS.md goes in the project root or any subdirectory.
Is .cursorrules deprecated?
Cursor's help center calls the .cursorrules file in the project root legacy and says it will be deprecated. To migrate, create a new project rule, paste the old contents in, set the type to Always Apply (which matches the old behavior) and delete .cursorrules.
What is the difference between .mdc and AGENTS.md?
A .mdc project rule has frontmatter (description, globs, alwaysApply) that controls when it applies. AGENTS.md is plain markdown with no metadata, so it is simpler but always in play for its folder. Cursor supports AGENTS.md in the root and in subdirectories, with more specific files taking precedence.
Why is my Cursor rule not being applied?
Check three things. The file must use the .mdc extension, because a plain .md file in .cursor/rules is ignored. An Apply Intelligently rule needs a description. An Apply to Specific Files rule needs a glob that matches files in context. Rules also do not apply to Tab completions or Bugbot pull request reviews.
Does Cursor read CLAUDE.md?
Yes. Cursor's help center says it reads CLAUDE.md files the same way it reads AGENTS.md, and that CLAUDE.md is always applied to every conversation regardless of any alwaysApply setting. Use project rules when you need conditional behavior.
© 2026 Questera
Follow in Google