Cursor project rules: a setup guide

Small, scoped rules that load when they matter, and a shared record for what must outlive Cursor.

By · Published

Cursor project rules are instruction files stored in .cursor/rules in your repository, one .mdc file per topic. Each file starts with frontmatter that tells Cursor when to include it: in every request, when the agent judges it relevant, when matching files are involved, or only when you mention it. Versioned files reach every teammate and every new conversation.

This guide shows the file format, the four rule types, examples, what to do when a rule does not apply, and how rules fit with context shared across agents.

How do Cursor project rules and .mdc files work?

A project rule is a Markdown file with an .mdc extension in .cursor/rules; the Cursor rules documentation notes that plain .md files in that folder are ignored. The frontmatter has three fields:

Field What it does
description Tells the agent what the rule is about, so it can decide whether to include it
globs File patterns, such as src/api/**/*.ts, that make the rule apply
alwaysApply true includes the rule in every request

Together they give four rule types, named in Cursor's rule editor:

  • Always Apply: alwaysApply: true, included in every request.
  • Apply Intelligently: a description and no globs; the agent includes it when relevant.
  • Apply to Specific Files: globs; included when matching files are involved.
  • Apply Manually: included only when you mention the rule with @.

User rules or project rules: which should you use?

User rules are global preferences, set in Cursor under Customize → Rules, and apply to every project you open. Project rules live in the repository. If a rule makes sense for any codebase, such as "show the diff before applying", it is a user rule. If it depends on this repository's stack, conventions or traps, it is a project rule.

Project rules last longer: they survive a new conversation, a new machine and a teammate cloning the repository. When guidance conflicts, Cursor applies team rules first, then project rules, then user rules.

What are the best practices for structuring project rules?

Treat rules like code: small files, one concern each, scoped so they load only where they apply.

  • One concern per file. One rule for tests, one for error handling, one for the Git workflow. Give each an accurate description: a vague description with no globs means the rule is either everywhere or nowhere.
  • Keep them short. Cursor recommends staying under 500 lines and splitting large rules. Every included rule spends the same context window the agent needs for code, so remove anything your linter already enforces.
  • Link instead of copying. For decisions that must outlive Cursor, keep the reference version in one place, such as AGENTS.md or a shared project workspace, and have the rule point to it.

What do good project rule examples look like?

Three files cover most needs: one always-applied stack rule, one rule scoped to test files, and one rule the agent pulls in for migrations.

Always-applied stack rule

---
description: Stack and conventions for this repository
alwaysApply: true
---

- Next.js App Router, TypeScript strict, Tailwind. No other CSS.
- Server Components by default; "use client" only when state or effects need it.
- Never edit prisma/migrations by hand. Generate with prisma migrate dev.

alwaysApply: true is the blunt instrument: Cursor includes this file in every request, even when it is irrelevant. That is why it stays under ten lines and holds only what the agent would otherwise get wrong. Leave out bullets like "write clean code": they cost tokens and change nothing. A useful test is to delete any rule you cannot link to a mistake it would have prevented.

Rule scoped to test files

---
description: Vitest conventions for test files
globs: ["**/*.test.ts", "**/*.test.tsx", "tests/**"]
alwaysApply: false
---

- Use vitest and testing-library. No jest syntax.
- Mock the network with msw handlers, never with fetch stubs.
- One describe block per exported function.

It applies only when matching files are involved, so it costs nothing during other work.

Migration rule the agent requests

---
description: Database migration procedure
alwaysApply: false
---

When a change requires a schema change:
1. Run `npx prisma migrate dev --name <change>` and show the output.
2. Never hand-write SQL files in prisma/migrations.
3. If the migration fails, stop and report. Do not drop tables to fix it.

With no globs and alwaysApply: false, the agent includes it when the description matches the task. Keep the description concrete, or the agent will never match it.

How do you organize rules in a repository?

Group rules in subfolders of .cursor/rules, for example .cursor/rules/frontend/components.mdc and .cursor/rules/api/errors.mdc, and scope each with globs such as packages/api/**/*.ts so it applies only to that part of the code. Commit the whole folder: it is project documentation.

Cursor also reads AGENTS.md files at the project root and in subdirectories, with the more specific file taking precedence. That makes AGENTS.md a good place for conventions you also want Codex and Claude Code to read.

Why are your project rules not applying?

Most cases come down to a few causes. Check them before assuming the model ignores the rule:

  1. Location and extension. The file must be in .cursor/rules and end in .mdc. A rule.md, a rule.mdc.txt or a .cursor/rule/ folder is not read.
  2. Frontmatter. description, globs and alwaysApply must be valid YAML. A missing colon or a broken quote can make the file unusable.
  3. Globs. Test the pattern against real paths. A rule scoped to packages/api/** does nothing while you edit packages/web/.
  4. Description. With alwaysApply: false and no globs, a vague description means the agent may never include the rule.

To confirm a rule arrived, ask the agent to quote it word for word. If it cannot, the rule was not included.

How do you generate rules for an existing codebase?

Cursor's documentation describes /create-rule in chat and an Add Rule button under Customize → Rules. You can also ask, in a new conversation at the repository root: "Read the repository structure and recent commits. Propose five to eight rule files, each scoped with globs, covering the stack, testing patterns and the mistakes agents keep making here."

Then expect to delete half. Generated rules tend to restate the obvious, such as "use TypeScript", or repeat what the linter enforces. Keep the ones that state project decisions an agent cannot infer from the code: the test setup that does not work, the reason a module is frozen. Make each survivor concrete, with a description that says when it applies.

How do project rules fit with context shared across agents?

Cursor rules help inside Cursor. Open Claude Code or Codex on the same repository and they start without them. Two layers solve this:

  1. In the repository: an AGENTS.md with build commands and conventions, which Cursor and Codex read, and which Claude Code reads when there is no CLAUDE.md. Rules can point to it instead of repeating it.
  2. Outside the repository: decisions, current state and history in a project workspace every agent can query. Fileaify holds that record and serves it to Claude Code, Codex and Cursor through its MCP connector or REST, so a new conversation in any tool starts from the same published decisions. The comparison with AGENTS.md and CLAUDE.md shows what goes where.

Sources

Try it

The demo runs on a prepared project, with no account. To share one project record across Cursor, Claude Code and Codex, create a free workspace and give your agent https://fileaify.com/agent.

Common questions

Where do Cursor project rules live?

In .cursor/rules at the project root, as .mdc files. Cursor ignores plain .md files in that folder. You can group rules in subfolders such as .cursor/rules/frontend.

What is the difference between user rules and project rules?

User rules are global preferences set in Cursor under Customize, then Rules. Project rules are files in the repository, versioned and shared with everyone who clones it. When guidance conflicts, team rules come first, then project rules, then user rules.

How long should a rule file be?

Cursor's documentation recommends keeping rules under 500 lines and splitting large rules into smaller ones. Shorter is better: a rule that applies to every request costs context on every turn.

How do I share the same rules with Claude Code or Codex?

Keep durable conventions in an AGENTS.md file, which Cursor and Codex read and Claude Code reads when there is no CLAUDE.md. Keep decisions and project state in a shared workspace the agents query over MCP or REST, and let rules point to it.

Written with AI assistance, reviewed by Stéphane Mermet and checked against the product. Fileaify publishes this guide and sells the service it describes.