Issue 00 · Autumn 2026日本語 · RSS
AgentKoji

Cursor Rules: How to Write .cursor/rules Files

How to write Cursor Project Rules: .mdc files in .cursor/rules, the four rule types set by alwaysApply, description and globs, and when to use AGENTS.md instead.

TL;DR

  • Project Rules are .mdc files in .cursor/rules. A plain .md file there is ignored, because it has no frontmatter for description, globs and alwaysApply.
  • alwaysApply: true includes a rule every time. With it false, globs attach the rule to matching files, a description alone lets Agent decide, and neither means the rule applies only when you @-mention it.
  • Team Rules take precedence over Project Rules, which take precedence over User Rules. Rules don't affect Cursor Tab or other AI features.

To write a Cursor rule, create an .mdc file in .cursor/rules, add frontmatter, and write the instructions below it. The frontmatter fields alwaysApply, description and globs decide when the rule reaches Agent. If you don’t need that control, a plain AGENTS.md works instead. Everything here comes from Cursor’s Rules page, checked 2026-11-05. We haven’t tested these rules in Cursor.

The four kinds of rules

KindWhere it livesScope
Project Rules.cursor/rules, in version controlYour codebase
User RulesCustomize → RulesAll your projects. Used by Agent (Chat)
Team RulesThe Cursor dashboardThe whole team. Team and Enterprise plans
AGENTS.mdProject root and subdirectoriesA plain markdown alternative to .cursor/rules

When a rule applies, its contents go at the start of the model context, so Agent gets the same guidance every time.

Rules don’t affect Cursor Tab or other AI features. They are instructions for Agent.

Project rules: .mdc, not .md

Each project rule is an .mdc file, named however you like. A plain .md file in .cursor/rules is ignored by the rules system, because it has no frontmatter to set description, globs and alwaysApply. Folders are fine:

.cursor/rules/
  react-patterns.mdc       # Recognized as a project rule
  api-guidelines.md        # Ignored (wrong extension)
  frontend/                # Organize rules in folders
    components.mdc

You can create a rule in two ways. Type /create-rule in Agent and describe what you want, and Agent writes the file with frontmatter into .cursor/rules. Or open Customize in the sidebar, go to Rules and click Add Rule. Customize also lists every rule and its status.

The four apply types

In Customize, a type dropdown sets the three frontmatter fields for you:

Rule typeWhen it appliesalwaysApplydescriptionglobs
Always ApplyEvery chat sessiontrueignoredignored
Apply to Specific FilesA matching file is in contextfalse—set
Apply IntelligentlyAgent judges it relevant from the descriptionfalsesetomitted
Apply ManuallyYou @-mention it in chat, such as @my-rulefalseomittedomitted

Two of the official examples:

---
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
---
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

An Always Apply rule has only alwaysApply: true in its frontmatter. A manual rule has only alwaysApply: false.

Glob patterns

globs scopes a rule to files or directories. Separate several patterns with commas.

PatternMatches
*Any single file name segment
**Any number of directories (recursive)
*.ts.ts files in the root
**/*.ts.ts files in any directory
src/**/*.tsx.tsx files anywhere under src/
docs/**/*.md, docs/**/*.mdx.md and .mdx files under docs/
tailwind.config.*tailwind.config with any extension

Referencing files

A rule reaches Agent exactly as written. A mention like @migration-template.sql tells Agent where to look, and Agent reads the file with its tools when it needs it. The file isn’t inlined into the prompt, and that holds in the editor, the CLI and Cloud Agents. If something must always be in context, put it in the rule body.

Cursor recommends referencing files over copying them in. It keeps rules short and stops them from going stale as the code changes. Tell Agent what to look for in the referenced file.

What makes a good rule

The docs describe good rules as focused, actionable and scoped:

Keep these out:

Start small, and add a rule when Agent makes the same mistake more than once. Commit rules to git so the team shares them. You can also tag @cursor on a GitHub issue or PR to have Agent update a rule.

Team Rules

On Team and Enterprise plans, admins create rules in the Cursor dashboard, and the rules apply to every team member.

Team Rules are free-form text and don’t use the Project Rules folder layout. They support globs such as **/*.py. A rule with a glob applies only when matching files are in context, and a rule without one applies to every conversation. An enabled Team Rule goes into the context for Agent (Chat) across all of the team’s repositories.

Rules apply in this order: Team Rules, then Project Rules, then User Rules. All applicable rules are merged, and when they conflict, the earlier source wins. The docs also warn that AI guidance shouldn’t be your only security control.

To bring in rules from a GitHub repository, package them in a plugin and publish it through a marketplace. You can import the repository in Customize with From GitHub Repository (it needs a .cursor-plugin/marketplace.json) or add it as a team marketplace, then install the plugin. Rules aren’t imported on their own.

AGENTS.md

AGENTS.md is plain markdown with no metadata, for projects that need simple instructions. Cursor reads it in the project root and in subdirectories. A nested AGENTS.md applies when you work with files in its directory or below. Its instructions combine with those from parent directories, and the more specific file takes precedence.

project/
  AGENTS.md              # Global instructions
  frontend/
    AGENTS.md            # Frontend-specific instructions
    components/
      AGENTS.md          # Component-specific instructions
  backend/
    AGENTS.md            # Backend-specific instructions

Source: https://cursor.com/docs/context/rules (checked 2026-11-05)

Summary

FAQ

Where do Cursor rules go?
Project Rules go in .cursor/rules as .mdc files, and you can organize them in subfolders. User Rules live in Customize → Rules and apply across all projects. Team Rules are managed from the Cursor dashboard on Team and Enterprise plans. AGENTS.md can sit in the project root and in subdirectories.
Why isn't my Cursor rule being applied?
Check the rule type. Apply Intelligently needs a description, and Apply to Specific Files needs a glob that matches the files in context. Also check the extension: a .md file in .cursor/rules is ignored, so project rules must be .mdc.
Can a Cursor rule reference other files?
Yes. Mention a file such as @service-template.ts and Agent reads it with its tools when it needs the content. The file isn't inlined into the prompt, so put anything that must always be in context directly in the rule body.
Do Cursor rules affect Cursor Tab?
No. Cursor's docs say rules don't affect Cursor Tab or other AI features.
What is the difference between .cursor/rules and AGENTS.md?
Project Rules are .mdc files with frontmatter that controls when each rule applies. AGENTS.md is plain markdown with no metadata, for simple instructions. Nested AGENTS.md files in subdirectories combine with their parents, and the more specific one takes precedence.