How to write Cursor rules: .mdc fields and examples

· 1 min read

Cursor rules are short instruction files in .cursor/rules/, one topic each. Cursor decides from each rule’s frontmatter when to add it to a request. This guide covers the fields and how to keep rules useful.

The file

---
description: Conventions for React components. Use when editing .tsx files.
globs: src/**/*.tsx
alwaysApply: false
---

- One component per file, named like the file.
- Props are typed with an interface next to the component.

The file name is the rule’s name: .cursor/rules/react-components.mdc.

When a rule applies

Set Cursor adds the rule
alwaysApply: true To every request
globs When files matching the patterns are in the request
description only When the agent decides the description fits the task
Nothing Only when you mention the rule yourself

Write globs without quotes, separated by commas. Cursor reads the text as written.

Keep rules useful

  • One concern per rule: React components, API handlers, tests.
  • Concrete instructions and a short example beat general advice.
  • Keep each rule well under 500 lines: it is added to every request it applies to.
  • Move long procedures into a skill, which Cursor loads only when needed.

Cursor also reads AGENTS.md at the root of the project. Put what every tool should know there, and only Cursor-specific rules here.

In Skill Builder

Add rules under Cursor in the Files panel. The checks warn about a rule that never applies and a pattern an always-on rule ignores. Export Ready for your project with Cursor ticked to get them in .cursor/rules/.

Check Cursor’s documentation for the current behaviour: rule handling changes between versions.

Next: Slash commands are skills now.