Rules provide system-level instructions to Agent and Inline Edit. Think of them as persistent context, preferences, or workflows for your projects.

Cursor supports three types of rules:

Project Rules

Stored in .cursor/rules, version-controlled and scoped to your codebase.

User Rules

Global to your Cursor environment. Defined in settings and always applied.

.cursorrules (Legacy)

Still supported, but deprecated. Use Project Rules instead.

How rules work

Large language models don’t retain memory between completions. Rules provide persistent, reusable context at the prompt level.

When applied, rule contents are included at the start of the model context. This gives the AI consistent guidance for generating code, interpreting edits, or helping with workflows.

Rules apply to Chat and Inline Edit. Active rules show in the Agent sidebar.

Project rules

Project rules live in .cursor/rules. Each rule is a file and version-controlled. They can be scoped using path patterns, invoked manually, or included based on relevance. Subdirectories can include their own .cursor/rules directory scoped to that folder.

Use project rules to:

  • Encode domain-specific knowledge about your codebase
  • Automate project-specific workflows or templates
  • Standardize style or architecture decisions

Rule anatomy

Each rule file is written in MDC (.mdc), a format supporting metadata and content. Control how rules are applied from the type dropdown which changes properties description, globs, alwaysApply.

Rule TypeDescription
AlwaysAlways included in model context
Auto AttachedIncluded when files matching a glob pattern are referenced
Agent RequestedAvailable to AI, which decides whether to include it. Must provide a description
ManualOnly included when explicitly mentioned using @ruleName
---
description: RPC Service boilerplate
globs: 
alwaysApply: false
---

- Use our internal RPC pattern when defining services
- Always use snake_case for service names.

@service-template.ts

Referenced files like @service-template.ts are included as additional context when the rule triggers.

Nested rules

Organize rules by placing them in .cursor/rules directories throughout your project. Nested rules automatically attach when files in their directory are referenced.

project/
  .cursor/rules/        # Project-wide rules
  backend/
    server/
      .cursor/rules/    # Backend-specific rules
  frontend/
    .cursor/rules/      # Frontend-specific rules

Creating a rule

Create rules using the New Cursor Rule command or going to Cursor Settings > Rules. This creates a new rule file in .cursor/rules. From settings you can see all rules and their status.

Generating rules

Generate rules directly in conversations using the /Generate Cursor Rules command. Useful when you’ve made decisions about agent behavior and want to reuse them.

Best practices

Good rules are focused, actionable, and scoped.

  • Keep rules under 500 lines
  • Split large rules into multiple, composable rules
  • Provide concrete examples or referenced files
  • Avoid vague guidance. Write rules like clear internal docs
  • Reuse rules when repeating prompts in chat

Examples

Many examples available from providers and frameworks. Community-contributed rules are found across crowdsourced collections and repositories online.

User Rules

User rules are global preferences defined in Cursor Settings → Rules that apply across all projects. They’re plain text and perfect for setting preferred communication style or coding conventions:

Please reply in a concise style. Avoid unnecessary repetition or filler language.

.cursorrules (Legacy)

The .cursorrules file in your project root is still supported but will be deprecated. We recommend migrating to Project Rules for more control, flexibility, and visibility.

FAQ