ContextPruner

Cursor rules explained: .cursor/rules with examples

How Cursor's project rules work — the .cursor/rules format, when each rule applies, example rules, and how to stop Cursor reading files it shouldn't.

·

Short answer

Cursor rules are Markdown files under .cursor/rules/ that tell Cursor how to work in your project. Each rule file has a type that controls when it applies — always on, automatically for matching files, on request, or by manual mention — so you can give Cursor project-wide conventions, per-directory instructions, and a list of files it shouldn't read.

Cursor rules are instructions you store in your repo to tell Cursor's AI how to work in your project — conventions to follow, context about the codebase, and files to leave alone. They're Cursor's version of AGENTS.md, with a slightly richer format that lets you control when each rule applies.

The .cursor/rules format

Modern Cursor keeps project rules in a .cursor/rules/ directory, one rule per .mdc file. Each file has a small frontmatter block followed by the rule text in Markdown. (The older single .cursorrules file at the repo root still works but is deprecated in favor of this directory.) A rule looks like this:

---
description: TypeScript conventions
globs:
  - "**/*.ts"
  - "**/*.tsx"
alwaysApply: false
---

- Server Components by default; add "use client" only when needed.
- Use the semantic color tokens in globals.css; never hard-code hex.
- Match the style of the file you're editing.

When a rule applies

The frontmatter decides how a rule gets pulled into context. There are four modes:

Here's an “always” rule for the repo overview:

---
description: Repo overview and ignore list
alwaysApply: true
---

Next.js 16 (App Router) + TypeScript. Source in app/, lib/, components/.

Don't read: package-lock.json, .next/, dist/, **/*.min.js —
generated files with no signal.

Stopping Cursor from reading the wrong files

A rule can tell Cursor to ignore files, but the stronger stop is a .cursorignorefile: Cursor itself blocks indexing and Agent access to matching paths, so the block no longer depends on the model's cooperation. It's a best-effort block, not a guarantee — Cursor's own docs note a terminal command or MCP server can still reach a file — but it's the right tool for lockfiles, build output, and anything sensitive. How enforcement works.

# .cursorignore — keep these out of Cursor's index and context entirely
package-lock.json
.next/
dist/
**/*.min.js

Between an always-on ignore rule and a .cursorignore, you stop Cursor spending its context budgeton files it can't learn anything from.

Generate your Cursor rules

ContextPruner writes a .cursor/rules/contextpruner.mdc for you — with the ignore list built from your actual file tree — plus the enforced .cursorignore above, alongside AGENTS.md, CLAUDE.md, GEMINI.md, and Copilot instructions: all nine files in one pass, so every tool your team uses gets the same guidance. Paste your file tree to try it, free and entirely in your browser. New to the shared format? Start with CLAUDE.md vs AGENTS.md.

Related guides