Advertise hereReach developers building with AI coding agents. →

Based on Anysphere’s official docs, checked

Cursor rules examples: .mdc files for each rule type

Cursor rules are short instruction files that Agent loads into context so it follows your project’s conventions. Project rules live in .cursor/rules as .mdc files (a plain .md file there is ignored). Each file’s frontmatter picks one of four types: Always Apply, Apply Intelligently, Apply to Specific Files, or Apply Manually. This page collects the official examples and the frontmatter table from Cursor’s rules docs, checked November 6, 2026. Prefer /agents/cursor/rules/ for the hub overview; this guide is the examples page because the site has no nested /agents/cursor/rules/examples/ route.

  1. 1. Create the rules folder

    Project rules go in .cursor/rules and are version-controlled. You can nest folders, for example frontend/components.mdc. Type /create-rule in Agent chat, or open Customize → Rules → Add Rule, to create a file with frontmatter.

    mkdir -p .cursor/rules
  2. 2. Always Apply rule

    Set alwaysApply: true so the rule is included in every chat. Cursor’s docs say globs and description are ignored when alwaysApply is true.

    ---
    alwaysApply: true
    ---
    
    - All source files must include the company copyright header
    - When you are unsure about implementation details, read the relevant source files before proposing changes
    - Never modify generated files in the dist/ or build/ directories
  3. 3. Apply to Specific Files

    Set globs and alwaysApply: false so the rule attaches when a matching file is in context. Separate multiple patterns with commas.

    ---
    globs: src/components/**/*.tsx
    alwaysApply: false
    ---
    
    - Use named exports, not default exports
    - Co-locate styles in a module CSS file next to the component
    - Keep components under 200 lines. Extract subcomponents into the same directory when a file grows beyond that
    - Prefer composition over prop drilling. Pass children or render props instead of threading data through multiple layers
  4. 4. Apply Intelligently

    Provide a description and omit globs, with alwaysApply: false. Agent reads the description and pulls the rule in when it looks relevant.

    ---
    description: RPC service conventions and patterns for the backend
    alwaysApply: false
    ---
    
    - Define each service in its own file under src/services/
    - Always validate inputs at the service boundary before passing data to internal functions
    - Return structured error objects with a code and message field, never throw raw strings
    - Read @service-template.ts for the standard boilerplate before creating a new service
  5. 5. Apply Manually

    Omit alwaysApply, description and globs, then @-mention the rule in chat when you need it.

    ---
    alwaysApply: false
    ---
    
    - Every database migration must have both up and down functions so it can be fully reversed
    - Never alter a column type in-place. Add a new column, backfill, then drop the old one in a separate migration
    - Read @migration-template.sql for the expected file structure before writing a migration

How the frontmatter fields combine

Cursor’s docs map the three fields to the four types: alwaysApply true always includes the rule; alwaysApply false with globs auto-attaches on matching files; alwaysApply false with a description and no globs lets Agent decide; alwaysApply false with neither description nor globs means you must @-mention it.

Project rules must use the .mdc extension. If you prefer plain markdown without frontmatter, use AGENTS.md in the project root or a subdirectory instead. Nested AGENTS.md files combine, with more specific directories taking precedence.

Referencing files from a rule

A mention like @service-template.ts tells Agent where to look; Agent reads the file with its tools when it needs the content. The file is not inlined into the prompt. Put anything that must always be in context directly in the rule body.

Official example themes

Cursor’s docs also show examples for frontend and API validation standards, Express and React templates, workflow automation (run the dev server, fetch logs, suggest improvements), documentation generation, and adding a new Cursor setting via reactiveStorageService. Use those as patterns; keep each rule focused on one concern.

Best practices from the same page: keep rules under 500 lines, split large rules, give concrete examples or referenced files, avoid vague guidance, and don’t paste whole style guides or every CLI command the model already knows.

Team Rules and User Rules

Team and Enterprise plans can manage Team Rules from the Cursor dashboard, with optional enforcement so members can’t turn them off. Team Rules are free-form text (not the .cursor/rules folder layout), can take globs, and take precedence over Project and User Rules when guidance conflicts.

User Rules are global preferences under Customize → Rules and apply across projects for Agent chat.

Tips

Next steps

Verified MCP servers for Cursor

→

Generate an MCP config for Cursor

→

Cursor hub

→

Cursor vs Claude Code: documented features compared

→

OpenAI Codex vs Cursor: documented features compared

→

Cursor vs GitHub Copilot: documented features compared

→

Google Antigravity vs Cursor: documented features compared

→

How to add an MCP server to Codex

→

How to add an MCP server to Cursor

→

How to add an MCP server to GitHub Copilot in VS Code

→

How to add an MCP server to Google Antigravity

→

How to migrate from Gemini CLI to Antigravity CLI

→

Portable agent skills: one SKILL.md for every coding agent

→

Safe “always allow” rules for Claude Code and Codex CLI

→

GitHub Copilot CLI yolo mode: --allow-all and safer tool rules

→

Codex sandbox modes and approval policies explained

→

How to install Claude Code on macOS, Linux and Windows

→

How to install the OpenAI Codex CLI

→

Claude Code auto mode: what runs, what gets blocked, how to turn it off

→

Agent Skills moves to the Agentic AI Foundation: what changes

→

MCP security: the risks in MCP servers and how to lock them down

→

Claude Code in VS Code: install, shortcuts and CLI differences

→

What is AGENTS.md? The open instruction file for coding agents

→

Claude Code on Windows: native, WSL and common errors

→

Codex skills: create, install and use SKILL.md skills in Codex

→

GitHub Copilot CLI: install, sign in and start using it

→

Cursor Agent SDK: build, test and deploy agents as code

→

GPT-6.1 Terra in Codex and the API: setup, pricing and limits

→

MCP OAuth: connect a remote MCP server in Claude Code, Codex and Cursor

→

Codex config.toml: location, precedence and the settings to change

→

Codex on Windows: native sandbox setup, WSL and fixes

→

Antigravity CLI (agy): install, sign in, modes and commands

→

Google Antigravity on Windows: install, WSL, sandbox and fixes

→

GitHub Copilot coding agent (now cloud agent): how to use it

→

GitHub Copilot agent mode: how to use it in your IDE

→

Claude Code tips from Anthropic’s best practices

→

Claude Code with OpenRouter: setup, models and troubleshooting

→

How to add an MCP server: Claude Code, Codex, Cursor, Copilot and Antigravity

→

Supabase RLS for AI-built apps: grants, policies and tests

→

Antigravity skills: create, store and run SKILL.md skills

→

Claude Code in JetBrains IDEs: install, connect and fix issues

→

GitHub Copilot skills: create, install and use agent skills

→

Claude Code subagents: create, configure and run them

→

Check which plugins, hooks and MCP servers your agent loads

→

Fix spawn npx ENOENT when starting an MCP server

→

Frequently asked questions

In .cursor/rules as .mdc files. A plain .md file in that folder is ignored because it has no frontmatter.

Sources