GUIDE

Cursor Rules (.cursorrules): A Practical Guide

Learn what Cursor rules are, why they improve every AI suggestion, and how to write good ones with a worked example block and a table of common rule categories.

By Ian MacCallum··8 min read

Cursor rules are persistent, project specific instructions that tell the AI in Cursor how your codebase works: the stack you use, the conventions you follow, and the patterns you want it to prefer or avoid. Instead of re-explaining your standards in every chat, you write them down once, commit them to the repository, and let the editor apply them automatically to completions, edits, and agent runs. This guide explains what the .cursorrules file is, why rules matter, and how to write good ones, including a worked example and a table of common rule categories. Because Cursor evolves quickly, we teach the durable method and point you to the official documentation for the exact, current file formats.

Cursor Drops is an independent project and is not affiliated with or endorsed by Cursor (Anysphere). Always confirm the current rule formats and behavior in the official Cursor documentation, since these surfaces are refined often.

What are Cursor rules?

A rule is a piece of guidance the model reads as context before it suggests or writes code. Historically many teams kept this guidance in a single .cursorrules file at the root of the repository, a plain text file describing how the AI should behave in that project. Cursor has since expanded this into a more structured system of project rules (often stored under a dedicated rules folder) that can be scoped, named, and toggled, while still supporting the legacy single file approach for backward compatibility. The underlying idea is unchanged: rules are durable, versioned instructions that travel with your code so every contributor and every AI action shares the same expectations.

Think of rules as the onboarding document you would hand a new teammate, written for the model. They are not prompts you type once and lose; they persist across sessions and apply automatically. That persistence is what makes them powerful, and it is also why writing them carefully matters.

Why Cursor rules matter

Context quality is the single biggest lever on AI output, and good cursor rules are context you do not have to retype. Without rules, the model guesses at your conventions and you spend time correcting the same mistakes: the wrong package manager, a deprecated API, an inconsistent file layout, or a testing style your team abandoned. With rules in place, suggestions arrive already aligned with how your project is built, which means fewer corrections, more consistent code, and a smoother experience for everyone on the team.

  • Consistency: every contributor gets suggestions that follow the same standards, not whatever each person happens to prompt.
  • Less repetition: you stop re-explaining your stack and conventions in every conversation.
  • Fewer regressions: rules can steer the AI away from deprecated libraries, risky patterns, or banned APIs.
  • Shared knowledge: rules live in version control, so they review, evolve, and roll back like any other code.
A useful test: any time you find yourself typing the same correction or clarification into chat for the second or third time, that is a rule waiting to be written.

How to write good rules

The best rules read like clear, specific instructions a careful engineer could follow without asking questions. Vague guidance produces vague results, so prefer concrete statements over aspirations. "Write clean code" helps no one; "use named exports, group imports by standard, internal, then relative, and never import from a barrel file" gives the model something it can actually apply.

  1. Start from real pain. Capture the conventions you keep restating, not a wish list of everything you could imagine.
  2. Be specific and actionable. Name the libraries, patterns, and commands you prefer, and say what to avoid.
  3. Keep each rule short. Several focused rules beat one sprawling document the model has to wade through.
  4. Scope where you can. If your project supports scoped or path based rules, attach guidance to the files it applies to so it only activates where relevant.
  5. Commit and review. Treat rules like code: put them in version control, review changes, and prune anything stale.

A simple do and don't structure works well because it tells the model both the target and the boundary. Pair a positive instruction ("prefer the native fetch API") with its negative counterpart ("do not add axios or other HTTP client dependencies") so there is no ambiguity about intent.

An example rules block

Here is an illustrative .cursorrules style block for a TypeScript and React project. Treat it as a starting shape to adapt, not a fixed standard, and check the official docs for the current recommended file location and format in your version of Cursor.

# Project: Web app (TypeScript + React)

## Stack
- Use TypeScript in strict mode. No "any" unless justified with a comment.
- Use React function components and hooks. No class components.
- Use the project package manager (pnpm). Do not introduce npm or yarn lockfiles.

## Conventions
- Prefer named exports over default exports.
- Co-locate component, styles, and test in the same folder.
- Use the existing UI components in src/components before adding new ones.

## Style
- Match the configured Prettier and ESLint setup. Do not reformat unrelated code.
- Write descriptive names. Avoid one-letter variables outside short loops.

## Do
- Add or update a test when you change behavior.
- Handle loading and error states for any data fetching.

## Don't
- Do not add new dependencies without asking first.
- Do not call external APIs from UI components; use the data layer.
- Do not commit secrets, tokens, or hard-coded credentials.
Rules guide the AI, they do not enforce anything by themselves. Keep your linter, type checker, formatter, and code review in place. Always read the diff before you accept an agent's changes.

Common rule categories

Most effective rule sets cover a handful of recurring categories. The table below is a planning checklist: you rarely need all of it on day one, so start with the categories where your team disagrees most or corrects the AI most often.

CategoryWhat it coversExample rule
Stack and toolingLanguages, frameworks, package manager, runtimeUse pnpm and Node 20; do not add a different package manager.
Code styleNaming, formatting, imports, file structureUse named exports and group imports standard, internal, relative.
ArchitectureLayers, boundaries, where logic belongsKeep data fetching in the service layer, not in components.
DependenciesLibraries to prefer, avoid, or never addPrefer the built-in fetch; do not add a new HTTP client.
TestingFramework, coverage expectations, patternsAdd a test for any behavior change using the existing test setup.
Security and safetySecrets, input handling, dangerous operationsNever hard-code credentials; validate and sanitize external input.

Keeping rules effective over time

Rules are not a set and forget artifact. As your stack changes, old guidance can quietly steer the model wrong, telling it to prefer a library you have since dropped or a pattern you have replaced. Treat rules like documentation that ships with the code: revisit them when you make a significant architectural change, prune anything that no longer reflects reality, and keep each rule earning its place. A short, accurate rule set beats a long, stale one every time.

It also helps to pair rules with good habits at the prompt level. Rules set the defaults, but precise context and clear requests still matter for any individual task. For more on that, see our companion guide to Cursor tips and tricks, which covers context selection, picking the right AI surface, and running the agent carefully.

Cursor's rule formats and storage locations have shifted over time, from a single .cursorrules file toward a structured project rules system. The mechanism may keep evolving, so verify the current approach in the official documentation rather than assuming a specific file path.

Bottom line and how to stay current

Well written cursor rules are one of the highest leverage investments you can make in an AI assisted codebase. Capture your stack, conventions, style, and do and don't guidance once, commit it, and every suggestion gets a little more aligned with how you actually build. Because Cursor ships quickly and the rule system continues to evolve, the smartest move is to learn the method here and watch the official changelog for format changes rather than memorizing any single file layout. If you would rather get the highlights without combing through release notes, Cursor Drops summarizes new releases for you, and the in-app changelog keeps a running history. You can grab the app on the App Store, then bookmark the documentation for authoritative details whenever rules change.

Sources

  1. Cursor documentation
  2. Cursor rules documentation
  3. Cursor changelog (official)
  4. Cursor blog
IM

Ian MacCallum

Maintainer, Claude Drops

Ian builds Claude Drops and reads every Claude Code release so you don't have to. He writes plain-English guides to Claude Code's features, drawing directly from the official changelog and documentation.

Stay on top of Cursor

Get notified the moment a new version ships, and browse the full Cursor changelog.

Get Cursor Drops

FAQ

Frequently asked questions

What is a .cursorrules file?+
It is a plain text file, historically placed at the root of a repository, that holds project specific instructions telling the AI in Cursor how your codebase works: your stack, conventions, and the patterns to prefer or avoid. Cursor has since added a more structured project rules system, but the goal is the same, durable guidance that travels with your code and applies automatically.
Where do Cursor rules live and are they committed to git?+
Rules are meant to live in the repository so the whole team shares them, which means yes, you commit them to version control like any other source file. The exact location has evolved from a single .cursorrules file toward a dedicated rules folder, so check the official Cursor documentation for the current recommended path in your version.
How do I write a good Cursor rule?+
Be specific and actionable. Name the libraries, patterns, and commands you prefer, say what to avoid, and keep each rule short. A do and don't structure works well because it gives the model both a target and a boundary. Start from real, repeated corrections rather than trying to document everything at once.
Do rules guarantee the AI follows them?+
No. Rules strongly steer suggestions but they are guidance, not enforcement. Keep your linter, type checker, formatter, and code review in place, and always read the diff before accepting agent changes. Rules raise the baseline quality of output; your existing safeguards still catch what slips through.
Is Cursor Drops made by Cursor?+
No. Cursor Drops is an independent project and is not affiliated with or endorsed by Cursor (Anysphere). It summarizes public release information to help you stay current, and the official Cursor documentation is always the authoritative source.