Version-controlled Agent instructions under .cursor/rules with scoped globs and apply modes
Follow Cursor's official Rules documentation when you want persistent Agent guidance tied to a repository. Project rules encode architecture expectations, risky-folder guardrails, or repeatable workflows; Cursor applies them via Always Apply, intelligent relevance, glob-scoped attachments, or manual @mentions. Use .mdc frontmatter for finer control and reference templates with @file instead of pasting large snippets.
使用场景
- Enforcing migration patterns only inside `database/` directories
- Documenting RPC conventions so Cursor Agent pulls guidance automatically during backend edits
- Blocking edits to generated output folders stated explicitly in Always Apply rules
- Providing onboarding checklists referenced via `@template.md` snippets
- Aligning frontend conventions whenever `*.tsx` files under `src/components/` enter context
主要功能
- Create `.cursor/rules/` in the repo root (Cursor Settings → Rules also exposes Add Rule)
- Author `.md` rules for simple prose guidance or `.mdc` rules with YAML frontmatter (`description`, `globs`, `alwaysApply`) matching Cursor's documented matrix
- Pick an apply strategy per rule: always-on, intelligent description-driven pulls, glob attachment when matching paths are open, or manual `@rule-name` mentions
- Keep each rule focused—Cursor recommends staying roughly under 500 lines and splitting oversized guides into composable files
- Reference canonical files via `@filename.ts` per docs rather than duplicating entire style manuals inside rules
- Commit `.cursor/rules` so teammates inherit identical Agent guardrails
相关推荐
相关推荐
3 收录条目