Welcome to HowToShipIt — practical how-to guides for developers: code, AI tools, and servers, explained step by step.

Cursor Rules: How to Write and Share Configs That Actually Work

You have probably had this moment: you spend twenty minutes explaining your stack, your conventions, and your non-negotiables to Cursor’s Agent, it generates something great, and then the next day — or the next tab — you start all over again. Cursor rules are how you stop repeating yourself. They are persistent, project-level instructions that live in your repo, travel through Git, and get injected into the Agent’s context automatically.

But there is a gap between “rules exist” and “rules work.” A bloated, vague rules file is just documentation the model skimmed. A tight, well-scoped set of rules changes the code the Agent writes every single day. This guide shows you the exact format Cursor uses in 2026, the four rule types, and how to write and share configs that your whole team will actually benefit from.

What Cursor Rules Actually Are (and Aren’t)

Rules are system-level instructions for Cursor’s Agent. When a rule is applied, its contents are included at the start of the model context, giving the AI consistent guidance for generating code, interpreting edits, and running workflows. Think of them as the persistent memory LLMs don’t have on their own.

Project rules live in .cursor/rules as .mdc files and are version-controlled alongside your code. Each rule is a markdown file with YAML-style frontmatter that controls when the rule loads, and markdown content that says what the rule teaches.

Two things rules are not:

  • They are not a replacement for a linter. Cursor’s own docs warn against copying entire style guides into rules — use ESLint or Prettier for formatting. Rules are for the judgement calls a linter can’t make: architecture, patterns, domain conventions.
  • They don’t affect Tab or Inline Edit. Rules apply to the Agent (Chat). User Rules don’t even apply to Cmd/Ctrl+K inline edit. If you’re wondering why your rule “doesn’t work” in Tab completion, that’s why.

The Four Rule Types and the Frontmatter That Picks One

Every .mdc file carries three frontmatter fields: description, globs, and alwaysApply. Their combination decides when the rule gets injected. Cursor gives you four types:

Rule type Frontmatter When it fires
Always Apply alwaysApply: true Every chat session, regardless of context
Apply Intelligently description only, no globs The Agent reads the description and pulls the rule in when it judges it relevant
Apply to Specific Files globs set Auto-attached when a matching file is in context
Apply Manually Neither description nor globs Only when you @-mention the rule in chat

Note the gotchas the official docs spell out: when alwaysApply is true, globs and description are ignored entirely. And a plain .md file dropped into .cursor/rules is ignored by the rules system — it has no frontmatter to parse, so the extension must be .mdc.

Glob patterns are comma-separated, not YAML arrays. Here are patterns straight from the docs:

  • **/*.ts — all TypeScript files in any directory
  • src/** — everything under src/
  • docs/**/*.md, docs/**/*.mdx — both extensions under docs/
  • tailwind.config.* — the config file with any extension

Your First Rule: A Template You Can Copy Today

Don’t start with a 300-line constitution. Start with one small, always-applied rule that captures the conventions you already repeat in every chat. Create .cursor/rules/project-conventions.mdc:

---
description: Core conventions for this codebase — package manager, code quality bar, imports
alwaysApply: true
---

# Project Conventions

- Use pnpm for all installs and scripts. Never suggest npm or yarn commands.
- TypeScript strict mode. No `any` — prefer `unknown` with narrowing.
- Absolute imports from `@/` only. No relative `../../` chains.
- Every new module gets colocated tests in the same directory.
- Before deleting a file or refactoring more than 3 files, summarize the plan and wait for confirmation.

Then add one scoped rule. Create .cursor/rules/api-conventions.mdc for your backend:

---
description: API route conventions for the backend service
globs: src/app/api/**/*.ts, src/server/**/*.ts
alwaysApply: false
---

# API Conventions

- Validate all request bodies with zod schemas before touching business logic.
- Return errors as `{ "error": { "code": "...", "message": "..." } }` with the correct HTTP status.
- Never expose stack traces or internal error details to clients.
- Log with request context: requestId, userId, route.

That pairing — one always-applied rule for the universal stuff, one scoped rule per domain — is the shape most good rulesets take. When you’re adding a third or fourth scoped file, add a short index rule with alwaysApply: true that maps what lives where, so the Agent knows the territory even before any glob matches.

How to Write Rules That Actually Change Behaviour

This is the part Cursor’s docs are unusually honest about. Their guidance on good rules:

  • Keep each rule under 500 lines. Split large rules into multiple, composable files instead.
  • Be specific and actionable. Write rules like clear internal docs, not like aspirations. “Prefer small functions” is a wish; “Keep React components under 80 lines; extract hooks into use*.ts files when a component grows past that” is an instruction.
  • Use concrete examples, not descriptions. Models match patterns from real code far better than from prose about code.
  • Reference files instead of copying their contents. Point the rule at canonical examples with @filename.ts syntax. This keeps rules short and stops them going stale as the code evolves.
  • Don’t duplicate what the codebase already says. Point to the canonical example instead of re-explaining it.
  • Reuse rules when repeating prompts in chat. The fastest way to find what your next rule should say: notice which prompt you typed three times this week, and move it into a rule.

The highest-leverage workflow the docs suggest is also the simplest: when you catch the Agent making a mistake, update the rule on the spot. Check your rules into Git like any other source of truth and review them in code reviews, just like config files. You can even tag @cursor on a GitHub issue or PR to have the Agent update the rule for you.

One more practical note: type /create-rule in Agent chat and describe what you want — Cursor generates the rule file with proper frontmatter and saves it to .cursor/rules for you. It’s the fastest way to bootstrap a file you’ll then refine by hand.

Sharing Rules Across a Team

Rules in .cursor/rules/ sync across the team through version control — no extra setup needed for project-level rules. That alone is the biggest win: a new hire pulls the repo and immediately gets the same AI behaviour as everyone else.

Beyond plain Git, you have three more sharing mechanisms:

1. Team Rules (Team and Enterprise plans)

Admins can create and enforce rules across the whole organisation from the Cursor dashboard. Team Rules work alongside project and user rules, but they take precedence — the merge order is Team Rules, then Project Rules, then User Rules, with earlier sources winning when guidance conflicts. Admins can choose whether a team rule is merely enabled or fully enforced (team members can’t toggle enforced rules off). They also support glob patterns for file-scoped application.

2. Plugins and marketplaces

Rules don’t import on their own. To bring rules in from a GitHub repository, package them as a plugin — the repo needs a .cursor-plugin/marketplace.json — and import it in Customize via “From GitHub Repository”, or add it as a team marketplace and install the plugin. The rules arrive with the plugin and appear in Customize alongside the rest.

3. User Rules for personal preferences

Global preferences that should follow you across every project — communication style, favourite testing library, “always explain before writing code” — belong in Customize → Rules as User Rules, not in any single repo. Keep secrets and environment-specific details out of committed rules; personal or machine-specific config belongs in User Rules or a gitignored file.

Borrowing Rules From the Community

You don’t have to write everything from scratch. Two community resources are worth bookmarking:

  • Cursor Directory (cursor.directory) — a searchable library of community-contributed rules you can copy into your .cursor/rules/ folder.
  • awesome-cursorrules on GitHub — a curated collection of .mdc rules organised by stack, with a contributing guide that enforces the same frontmatter discipline this guide covers.

The workflow is the same either way: browse, copy the .mdc file into .cursor/rules/, then customise it. A rule written for someone else’s stack is a starting point, not a finished product. Trim anything that doesn’t match your codebase — an irrelevant rule is context-window noise that makes every response slightly worse.

When to Use AGENTS.md Instead

Cursor also supports AGENTS.md — a plain markdown file at the project root (and now in subdirectories too) with no frontmatter and no configuration. The docs position it as the simple alternative: if your instructions are straightforward and you don’t need the four activation modes, skip the .mdc machinery entirely.

A practical rule of thumb: if what you need fits in about ten lines that should apply everywhere, AGENTS.md (or one always-applied rule) is enough. When you need different guidance for React files, API routes, and migrations, that’s when scoped .mdc files earn their keep.

The Checklist Before You Commit

  • One always-applied rule with your universal conventions (package manager, language settings, import style, quality bar).
  • One scoped rule per domain (components, API routes, migrations, tests) with accurate globs.
  • Each rule under 500 lines; split anything bigger.
  • Examples are real code from your repo, referenced with @ mentions — not pasted duplicates.
  • Nothing in the rules that ESLint, Prettier, or your type checker already enforces.
  • .cursor/rules/ committed to Git; reviewed like any other config change.
  • Personal preferences moved to User Rules; secrets nowhere near the repo.

Cursor rules are a compounding asset. Every correction you encode today is a correction you never have to type again — and when the whole team shares the same ruleset, the Agent starts behaving like it actually works there. That’s the difference between a config that exists and a config that works.

Further Reading & References

Last verified: October 3, 2026. Cursor’s docs evolve quickly — if a detail here looks stale, check the official rules documentation linked above.

Leave a Comment