DEV Community

吴冲
吴冲

Posted on

How to Create Cursor Project Rules with .mdc Files

Cursor project rules work best when they are small, scoped and easy to maintain. Instead of keeping every instruction in one large file, split your rules into focused .mdc files.

Suggested structure

project/
  .cursor/
    rules/
      project-overview.mdc
      code-style.mdc
      framework-rules.mdc
      testing.mdc
Enter fullscreen mode Exit fullscreen mode

Example .mdc rule

---
description: "React component conventions"
globs: "**/*.tsx"
alwaysApply: false
---

- Use functional components.
- Define explicit TypeScript props.
- Keep components focused and testable.
- Prefer accessible HTML before custom abstractions.
Enter fullscreen mode Exit fullscreen mode

When to use globs

Use globs when a rule only applies to a subset of the project:

globs: "**/*.tsx"
Enter fullscreen mode Exit fullscreen mode
globs: "src/**/*.{ts,tsx}"
Enter fullscreen mode Exit fullscreen mode
globs: "app/**"
Enter fullscreen mode Exit fullscreen mode

When to use AGENTS.md

Use AGENTS.md when you want a simpler markdown instruction file that can be read by coding agents and does not need MDC frontmatter.

Free generator

I made a free generator that creates .cursor/rules/*.mdc, AGENTS.md and legacy .cursorrules output:

https://www.cursorgenerator.dev/

Top comments (0)