Cursor Rules (.mdc): how it works
Cursor project rules live in .cursor/rules/ as .mdc files: Markdown with a short frontmatter block. The frontmatter decides when a rule reaches the model. alwaysApply: true adds it to every request, globs attach it when matching files are in play, and a description lets the agent pull it in when the task fits. A rule with none of these is used only when you @-mention it. The single .cursorrules file in the repo root still works but is deprecated, so new projects should use .cursor/rules/.
Where the file goes
.cursor/rules/nextjs.mdcglobs: app/**/*.tsxFramework conventions that load only when route or component files are in play..cursor/rules/testing.mdcglobs: **/*.test.tsTest runner commands and mocking rules, attached when a test file is in the request.packages/api/.cursor/rules/api.mdcNested folderIn a monorepo, a.cursor/rulesfolder inside a package applies to files in that package.
What goes in it
alwaysApply false and use globs for anything that only matters to part of the codebase.--- description: Next.js App Router conventions for routes and server code globs: app/**/*.ts,app/**/*.tsx alwaysApply: false ---
- Server Components by default; add "use client" only for state, effects or browser APIs. - Validate Server Action input with Zod safeParse and return typed errors. - Never import from next/router; use next/navigation. - Run `pnpm lint && pnpm test` before finishing.
Tips
- Write one rule per concern (framework, data layer, tests) instead of one long file, so each loads only where it applies.
- Keep
alwaysApply: truefor the few lines every request needs, such as the package manager and test command. - Write the
descriptionas when-to-use text; the agent reads it to decide whether to pull the rule in. - Reference real files (
@components/ui/button.tsx) instead of pasting long examples into the rule. - Commit
.cursor/rules/so the whole team gets the same rules.
Cursor Rules presets (32)
Each one opens the generator with that file filled in for the stack. Change what you need, then copy or download it.
- Next.js 15 App Router
Frontend
- React 19 & Vite
Frontend
- Python FastAPI & Pydantic v2
Backend
- Supabase & PostgreSQL
Fullstack & DB
- Prisma ORM
Fullstack & DB
- Drizzle ORM
Fullstack & DB
- Go (Golang) & Fiber
Backend
- Rust & Axum
Backend
- Tailwind CSS v4
Frontend
- Vue 3 & Nuxt 3
Frontend
- SvelteKit 5 & Svelte 5
Frontend
- Universal Cursor Pro
Specialist Persona
- Pragmatic Rapid Prototyping
Specialist Persona
- Zero-Trust Security
Specialist Persona
- Docker & CI/CD
DevOps & Tooling
- Vitest & Playwright TDD
Specialist Persona
- Automated Code Reviewer
Specialist Persona
- Multi-Agent System Orchestration
Specialist Persona
- Django 5 & Ninja / DRF
Backend
- Bun & Elysia / Hono
Backend
- React Native & Expo Router
Frontend
- Flutter 3 & Riverpod / Dart
Frontend
- Kubernetes & Helm Charts
DevOps & Tooling
- Terraform & OpenTofu IaC
DevOps & Tooling
- Playwright End-to-End Testing
DevOps & Tooling
- Spring Boot 3 & Java 21
Backend
- .NET 8 & C# 12 Minimal APIs
Backend
- Pull Request & Diff Review
Specialist Persona
- Root-Cause Debugging
Specialist Persona
- Commit Messages & Pull Requests
Specialist Persona
- Behavior-Preserving Refactoring
Specialist Persona
- Dependency Upgrades & Migrations
Specialist Persona
Which file do I need?
Each AI coding tool reads its own file from its own place. Find your tool, put the file where the table says, and check when it actually gets loaded. Every file name opens a generator for that format.
| AI tool | File | Where it goes | When it's loaded |
|---|---|---|---|
| Agent rules and tool config | |||
| Cursor | <rule-name>.mdc | Goes in: .cursor/rules/ | Loaded: Per rule: always, when globs match the files in play, when the agent finds the description relevant, or on @-mention. |
| Claude Code | SKILL.md | Goes in: .claude/skills/<skill-name>/, or ~/.claude/skills/ for all projects | Loaded: Name and description at startup. The full file only when a task matches or you run /skill-name. |
| Claude Code | CLAUDE.md | Goes in: Repo root, or ~/.claude/CLAUDE.md for all projects | Loaded: Every session, in full. A CLAUDE.md in a subfolder loads when Claude works there. |
| Codex, Cursor, Copilot coding agent and others | AGENTS.md | Goes in: Repo root. Nested files cover their subfolder. | Loaded: At the start of each task. For Claude Code, add @AGENTS.md to CLAUDE.md. |
| Claude Code, Claude Desktop, Cursor | .mcp.json | Goes in: Repo root for Claude Code. Claude Desktop uses claude_desktop_config.json; Cursor uses .cursor/mcp.json. | Loaded: At startup, so restart after editing. Claude Code asks before using servers from .mcp.json. |
| Windsurf | <rule-name>.md | Goes in: .windsurf/rules/ | Loaded: Per rule trigger: always on, glob match, model decision, or manual @-mention. |
| GitHub Copilot | copilot-instructions.md | Goes in: .github/ | Loaded: With every Copilot Chat, code review and coding agent request in the repo. Not used for inline completions. |
| ChatGPT / OpenAI API | openai-custom-instructions.md | Goes in: prompts/, as a copy you version | Loaded: Only when pasted into ChatGPT custom instructions or sent as the system message. |
| Gemini API / AI Studio | gemini-system-instructions.json | Goes in: prompts/, as a copy you version | Loaded: Only when passed as systemInstruction or pasted into AI Studio. |
| Ignore files | |||
| Cursor | .cursorignore | Goes in: Repo root | Loaded: Always. Indexing and AI features skip matching files (best effort: terminal commands can still read them). |
| Claude Code | .claudeignore | Goes in: Repo root | Loaded: Keep it as your pattern list, and mirror secret paths in permissions.deny in .claude/settings.json, the setting Claude Code documents for blocking reads. |
| Reference docs | |||
| Any LLM or crawler | llms.txt | Goes in: Repo root, or your site root as /llms.txt | Loaded: Only when a tool or person fetches it. Nothing loads it automatically. |
| Any agent | ARCHITECTURE.md | Goes in: Repo root | Loaded: When your rules file points to it, or when the agent explores the repo. |
| Planning docs | |||
| Any agent | PRD.md | Goes in: Repo root | Loaded: When your rules file tells the agent to read it. |
| Any agent | DESIGN.md | Goes in: Repo root | Loaded: When your rules file tells the agent to read it, usually before UI work. |
| Any agent | TASK.md | Goes in: Repo root | Loaded: At the start and end of a task, if your rules say to read and update it. |
| Any agent | MEMORY.md | Goes in: Repo root | Loaded: At session start, if your rules say so. Agents add lessons as they go. |
What a good rule looks like
Agents follow rules they can check. Swap advice for commands, paths and explicit “never” lines.
Give commands, not wishes
CLAUDE.md or AGENTS.md## Guidelines - Write clean code. - Follow best practices. - Make sure tests pass.
## Commands - Test one file: pnpm vitest run src/lib/date.test.ts - Typecheck: pnpm tsc --noEmit - Never run pnpm db:reset. It wipes the shared dev database.
Why it works: The agent can run each line as written, and the "never" rule names the exact command and the reason.
Scope rules to the files they cover
.cursor/rules/components.mdc--- alwaysApply: true --- Use React best practices.
--- globs: src/components/**/*.tsx alwaysApply: false --- - Reuse Button and Input from @/components/ui; never add a UI library. - One component per file, named export, props typed with an interface.
Why it works: It loads only when a component file is in play, and every line is something the model can check.
Tell a skill when to run
SKILL.md--- name: helper description: Helps with code. ---
--- name: db-migration description: Writes and reviews Prisma migrations. Use when schema.prisma changes or the user asks for a migration. ---
Why it works: Claude picks a skill by its description, so say what it does and when to use it.
Copy-ready starters
Complete files from the preset library. Copy one as it is, or open it to change the stack, commands and rules before you download it.
- Next.js 15 App RouterCursor Rules
.cursor/rules/nextjs-15.mdc
Enforce React Server Components (RSC) by default; restrict 'use client' strictly to interactive leaf components.
- Automated Code ReviewerClaude Skill
.claude/skills/codebase-auditor/SKILL.md
Scope scanning to the repository and skip .env files, keys, and credential stores.
- Multi-Agent System OrchestrationAGENTS.md
AGENTS.md
Define subagent roles: Lead Architect, Frontend Engineer, Backend Specialist, Security Reviewer.
- Python FastAPI & Pydantic v2Cursor Rules
.cursor/rules/fastapi.mdc
Use strict Pydantic v2 BaseModels with Field validation for all input and output schemas.
- React 19 & ViteCopilot
.github/copilot-instructions.md
Use React 19 action hooks (useActionState, useOptimistic, useFormStatus) for async mutations.
- Tailwind CSS v4Cursor Rules
.cursor/rules/tailwind-v4.mdc
Configure themes directly in globals.css using
@themeand@import 'tailwindcss';. - GitHub Operations MCPMCP Config
.mcp.json or claude_desktop_config.json
Uses official
@modelcontextprotocol/server-githubpackage via npx.
Frequently asked questions
.cursorrules vs .cursor/rules: which should I use?
Use .cursor/rules/*.mdc. The single .cursorrules file is still read but deprecated, and it applies to every request. Project rules can be scoped with globs, loaded on demand and split by concern.
Does Cursor read AGENTS.md too?
Yes. Cursor reads AGENTS.md in the project root as a plain Markdown alternative to project rules, without frontmatter or scoping. Use it for instructions you share with other agents, and .mdc rules for scoped ones.
Why is my Cursor rule not being applied?
Check the frontmatter first: a rule with alwaysApply: false, no globs and no description loads only when you @-mention it. Then check that the glob matches the files in your request and that the file sits in .cursor/rules/ with the .mdc extension.
CLAUDE.md vs AGENTS.md: which do I need?
Claude Code reads CLAUDE.md. AGENTS.md is the shared file that OpenAI Codex, Cursor, GitHub Copilot's coding agent and a growing list of other agents read. If your team uses more than one tool, put the rules in AGENTS.md and add the line @AGENTS.md to CLAUDE.md so Claude Code imports the same file.
Why is Cursor ignoring my rules?
Usually it's the frontmatter. A rule with alwaysApply: false and no globs only loads when the agent decides its description is relevant, or when you @-mention it. Check that the file is in .cursor/rules/, that globs match the files you are editing, and that the description says when the rule applies. Rules don't affect Tab autocomplete at all.
How long should CLAUDE.md be?
Aim for under 200 lines. Claude Code loads the whole file into every session, so each line costs context and competes with the others for attention. Keep build and test commands, the folder layout and hard "never" rules in it. Move long procedures into skills or separate docs that the file points to.
Where do Claude Code skills go?
Each skill is a folder with a SKILL.md inside: .claude/skills/<skill-name>/SKILL.md for one project, or ~/.claude/skills/<skill-name>/SKILL.md for all of your projects. Claude Code keeps only each skill's name and description in context, and loads the full file when a task matches it or when you type /skill-name.
How do I stop AI tools from reading my .env files?
For Cursor, list secrets such as .env*, *.pem and *.key in .cursorignore at the repo root. For Claude Code, add deny rules like Read(./.env) and Read(./.env.*) under permissions.deny in .claude/settings.json, which is the setting Claude Code documents for blocking file reads. Neither replaces keeping secrets out of the repo.
Do AI tools read PRD.md, TASK.md or ARCHITECTURE.md automatically?
No. Agents load their own rules file (CLAUDE.md, AGENTS.md or Cursor rules) and nothing else on their own. Name the other docs in that file, for example "Read PRD.md and TASK.md before you start", and the agent opens them when it needs them. In CLAUDE.md you can also write @PRD.md, but that loads the file into every session.
Can it write rules from my existing code?
Yes. Click Read your code and point it at a GitHub repository or a local folder. Besides the manifest, it reads a sample of your source files and any existing CLAUDE.md, AGENTS.md or Cursor rules, then writes only the conventions most of the code follows, such as test layout, file naming, import alias, error classes and logger, each with how many files back it. The examples in the file quote a real function from your code.
Does AI Skill Studio upload my code?
No. Presets, code reading, editing and ZIP export all run in your browser, and nothing you type or import is sent to DevScratchpad. Reading a local folder happens entirely in your browser. Reading a GitHub repository is the only network call, and your browser sends it straight to GitHub.