TaskPrio

Cursor rules (.cursor/rules) — format, examples, best practices

Cursor rules are reusable instructions you give Cursor's AI so it follows your project's conventions. Project rules live in .cursor/rules/ as .mdc files — each with frontmatter that decides when it's applied. Here's the format, the four rule types, a copy-paste example, and how it relates to .cursorrules and AGENTS.md.

Generate your .cursor/rules — free →

What are Cursor rules?

Large models don't retain context between sessions. Rules solve that: a rule is persistent, reusable context Cursor pulls into the model prompt so it codes the way your project expects — your stack, conventions, and the things to avoid. There are two kinds:

The .mdc format

Project rules use the .mdc extension (Markdown + metadata) inside .cursor/rules/. A plain .md file there is ignored by the rules system — it has no frontmatter. Each rule has three frontmatter fields:

FieldWhat it does
descriptionOne line on what the rule is for. Used when the agent decides whether to pull the rule in.
globsFile patterns (e.g. src/**/*.ts). The rule auto-attaches when a matching file is in context.
alwaysApplytrue = always in context (globs + description are then ignored). false = applied conditionally.

The four rule types

Which fields you set determines the rule type — Cursor exposes this as a dropdown:

TypeHow it's setWhen it applies
AlwaysalwaysApply: trueEvery request — use sparingly, it costs context on every call.
Auto-attachedglobs set, alwaysApply: falseWhen a file matching the glob is in context.
Agent-requesteddescription set, no globsWhen the agent judges it relevant from the description.
Manualnone of the aboveOnly when you @-mention the rule in chat.

Example: .cursor/rules/project.mdc

---
description: Project conventions for the web app
globs: ["**/*.ts", "**/*.tsx"]
alwaysApply: false
---

# Web app — conventions

## Stack
Next.js 14 (App Router), TypeScript, Tailwind, Drizzle + Postgres.

## Conventions
- Server Components by default; add "use client" only when you need state or effects.
- No `any` — type everything; prefer `unknown` + a narrow.
- Co-locate tests as `*.test.ts` next to the file.

## Don't
- Don't touch `/legacy` — it's being removed.
- Don't add a dependency without checking it's not already in package.json.

That rule auto-attaches whenever a .ts/.tsx file is in context. For rules that should always apply (a short house style), set alwaysApply: true and drop the globs.

Where they live + nesting

.cursorrules vs .cursor/rules

.cursorrules (a single file at the repo root) is the legacy format. It still works for backward compatibility, but Cursor has superseded it with Project Rules in .cursor/rules/ — which give you multiple scoped files, globs, rule types, and per-directory nesting instead of one monolithic file. New projects should use .cursor/rules/; to migrate, move your .cursorrules content into a .cursor/rules/project.mdc with appropriate frontmatter.

Cursor rules vs AGENTS.md

Cursor reads both. AGENTS.md is the open, tool-agnostic standard read by Cursor and 28+ other agents — keep your shared, cross-tool instructions there so they work in Claude Code, Copilot, Gemini, etc. too. Use .cursor/rules/*.mdc for Cursor-specific power: glob-scoped rules, agent-requested rules, and nesting. Many teams keep one lean AGENTS.md plus a few scoped .mdc rules. See AGENTS.md vs CLAUDE.md for the cross-tool picture.

Best practices

Generate it from one source

Maintaining .cursor/rules and AGENTS.md and CLAUDE.md and Copilot instructions by hand means they drift. Write your project rules once and compile all of them:

Open the free Agent Memory Compiler →

It outputs .cursor/rules/project.mdc + AGENTS.md + CLAUDE.md + .github/copilot-instructions.md + GEMINI.md from one input, with a token-budget warning. If you run TaskPrio, a project's context exports the same files automatically — over MCP (export_memory) or one click in the app.

FAQ

What is the Cursor rules file extension?

.mdc (Markdown with metadata), inside .cursor/rules/. Plain .md there is ignored — it has no frontmatter.

Is .cursorrules deprecated?

It's the legacy single-file format. Still supported for backward compatibility, but superseded by Project Rules in .cursor/rules/. Use the directory format for new projects.

Can I have different rules per folder?

Yes — nest a .cursor/rules/ folder in a subdirectory and those rules scope to that subtree.

Generate your agent rules — free →   What is AGENTS.md →