固化 · 用 Rules 和 AGENTS.md 钉住偏好Pin It Down · Locking Preferences into Rules and AGENTS.md.
同一句要求你跟它说了十遍:用这个库、按这个风格、别碰那个目录。模型不跨会话记事,但你可以把这些钉进文件。Rules(.cursor/rules 里的 .mdc)和 AGENTS.md 就是项目的长期记忆 —— 每次开工自动加载。这一章讲什么该写进去、什么不该,四种触发怎么选,以及固化的落点如何从 Rules 扩到 skills、subagents、hooks 与 Customize 面板。You've told it the same thing ten times: use this library, follow this style, don't touch that directory. Models don't remember across sessions — but you can pin it into files. Rules (.mdc files under .cursor/rules) and AGENTS.md are a project's long-term memory, loaded automatically each time. What belongs in them, what doesn't, how to pick a trigger — and how pinning now widens past Rules into skills, subagents, hooks, and the Customize panel.
同一句要求你跟它说了十遍:用这个库、按这个风格、别碰那个目录。模型不跨会话记事,但你可以把这些钉进文件。Rules(.cursor/rules 里的 .mdc)和 AGENTS.md 就是项目的长期记忆 —— 每次开工自动加载,不用你再交代一遍。You've told it the same thing ten times: use this library, follow this style, don't touch that directory. Models don't remember across sessions — but you can pin it into files. Rules (.mdc files under .cursor/rules) and AGENTS.md are a project's long-term memory, loaded automatically each time, so you never re-explain.这件事在非代码项目里同样成立:一个写作或调研文件夹里放一份 AGENTS.md,写清口吻、引用格式、文件命名,agent 的产出就按你的规矩来。这一章讲什么该钉、用哪种触发钉、以及为什么钉多了反而没用。This holds for non-code projects too: drop an AGENTS.md in a writing or research folder spelling out tone, citation format, and file naming, and the agent's output follows your rules. This chapter covers what to pin, which trigger to pin it with, and why pinning too much backfires.
— I
Rules 是项目的长期记忆Rules Are a Project's Long-Term Memory.
说十遍不如钉一遍。Pinning it once beats saying it ten times.三层各管一摊:Project Rules 放在 .cursor/rules 下、是 .mdc 文件、随仓库走、团队共享;User Rules 是你的全局个人偏好(口吻、习惯);Team Rules 从 dashboard 下发、是组织标准、优先级最高。1注 1Note 1Cursor Docs · Rules —— 模型不跨会话记忆;Rules 在 prompt 层提供持久、可复用的上下文。Project Rules 放 .cursor/rules 下的 .mdc(随仓库版本化),User Rules 全局,Team Rules 走 dashboard、优先级最高。触发由 frontmatter 控制:alwaysApply / description(智能判断)/ globs(按文件)/ 手动 @。截至 2026-07-10。Cursor Docs · Rules — models don't remember across sessions; Rules provide persistent, reusable context at the prompt level. Project Rules live as .mdc under .cursor/rules (version-controlled), User Rules are global, Team Rules come from the dashboard with top precedence. Triggers are set in frontmatter: alwaysApply / description (intelligent) / globs (by file) / manual @. As of 2026-07-10.它们都在 prompt 层提供持久上下文,每次开工自动注入 —— 这就是你不用每次重新交代「这个项目用 pnpm 不用 npm」的原因。Three layers, each with its turf: Project Rules live under .cursor/rules as .mdc files, travel with the repo, and are shared by the team; User Rules are your global personal preferences (tone, habits); Team Rules come down from the dashboard as org standards with the highest precedence.1注 1Note 1Cursor Docs · Rules —— 模型不跨会话记忆;Rules 在 prompt 层提供持久、可复用的上下文。Project Rules 放 .cursor/rules 下的 .mdc(随仓库版本化),User Rules 全局,Team Rules 走 dashboard、优先级最高。触发由 frontmatter 控制:alwaysApply / description(智能判断)/ globs(按文件)/ 手动 @。截至 2026-07-10。Cursor Docs · Rules — models don't remember across sessions; Rules provide persistent, reusable context at the prompt level. Project Rules live as .mdc under .cursor/rules (version-controlled), User Rules are global, Team Rules come from the dashboard with top precedence. Triggers are set in frontmatter: alwaysApply / description (intelligent) / globs (by file) / manual @. As of 2026-07-10. All supply persistent context at the prompt level, injected automatically each session — which is why you stop re-saying 'this project uses pnpm, not npm.'一个容易踩的点:User Rules 不作用于 Cmd+K 的行内编辑,只对 Agent 生效。所以你那条「永远用中文注释」写成 User Rule,Cmd+K 不一定听 —— 想让它在所有地方生效,写进项目里。An easy trip-up: User Rules don't apply to Cmd+K inline edits, only to the Agent. So your 'always comment in Chinese' written as a User Rule may not reach Cmd+K — to make it hold everywhere, put it in the project.
— II
四种触发,别全设成 alwaysFour Triggers — Don't Make Everything Always.
rule 设得越多、always 设得越多,它越读不过来。The more rules you write, and the more you mark always, the less it can actually read.每条 rule 的触发由 frontmatter 决定,四种:alwaysApply: true(每次都加进上下文,且会让同一条里的 globs / description 失效)、description(让 agent 按描述智能判断相不相关)、globs(按文件路径,如 src/components/**/*.tsx)、手动(只在 @ 提到时进)。1注 1Note 1Cursor Docs · Rules —— 模型不跨会话记忆;Rules 在 prompt 层提供持久、可复用的上下文。Project Rules 放 .cursor/rules 下的 .mdc(随仓库版本化),User Rules 全局,Team Rules 走 dashboard、优先级最高。触发由 frontmatter 控制:alwaysApply / description(智能判断)/ globs(按文件)/ 手动 @。截至 2026-07-10。Cursor Docs · Rules — models don't remember across sessions; Rules provide persistent, reusable context at the prompt level. Project Rules live as .mdc under .cursor/rules (version-controlled), User Rules are global, Team Rules come from the dashboard with top precedence. Triggers are set in frontmatter: alwaysApply / description (intelligent) / globs (by file) / manual @. As of 2026-07-10.判断很简单:一条 rule 只挑一种触发 —— 全局铁律才 always,其余按需或按文件。下面是一条按文件触发的项目 rule:Each rule's trigger is set in frontmatter, four kinds: alwaysApply: true (always included in context, which makes globs / description in the same rule moot), description (the agent judges relevance from the description), globs (by file path, e.g. src/components/**/*.tsx), and manual (only when @-mentioned).1注 1Note 1Cursor Docs · Rules —— 模型不跨会话记忆;Rules 在 prompt 层提供持久、可复用的上下文。Project Rules 放 .cursor/rules 下的 .mdc(随仓库版本化),User Rules 全局,Team Rules 走 dashboard、优先级最高。触发由 frontmatter 控制:alwaysApply / description(智能判断)/ globs(按文件)/ 手动 @。截至 2026-07-10。Cursor Docs · Rules — models don't remember across sessions; Rules provide persistent, reusable context at the prompt level. Project Rules live as .mdc under .cursor/rules (version-controlled), User Rules are global, Team Rules come from the dashboard with top precedence. Triggers are set in frontmatter: alwaysApply / description (intelligent) / globs (by file) / manual @. As of 2026-07-10. The call is simple: give each rule just one trigger — only global iron laws are always; the rest are intelligent or by-file. Here's a by-file project rule:
.cursor/rules/components.mdc —— 只在改组件文件时注入.cursor/rules/components.mdc — injected only when editing component files
把所有 rule 都设成 always,等于把整本规范每次全塞进上下文 —— 又占额度,又稀释重点,它反而抓不住真正要紧的那几条。always 留给「永远成立」的三五条,其它交给触发条件。Marking every rule always is stuffing the whole rulebook into context each time — it spends quota, dilutes focus, and it ends up missing the few that matter. Reserve always for the three-to-five that are always true; let triggers handle the rest.
— III
AGENTS.md:简单到该先写AGENTS.md: Simple Enough to Write First.
复杂的 .mdc 之前,先写一份 AGENTS.md —— 一份纯 markdown,门槛最低。Before any complex .mdc, write an AGENTS.md first — plain markdown, the lowest barrier.AGENTS.md 就是项目里一份简单的 markdown,写明 agent 该守的规矩;它可以按子目录嵌套,子目录里的就近覆盖父级。2注 2Note 2Cursor Docs · Rules / AGENTS.md —— AGENTS.md 是放在项目里的一份简单 markdown,定义 agent 指令,支持项目根目录与子目录;是相对 .mdc 更轻量的写法。注意:User Rules 不作用于 Inline Edit(Cmd/Ctrl+K),只对 Agent 生效。截至 2026-07-10。Cursor Docs · Rules / AGENTS.md — AGENTS.md is a simple markdown file in the project that defines agent instructions, supported at the project root and in subdirectories; a lighter-weight alternative to .mdc. Note: User Rules don't apply to Inline Edit (Cmd/Ctrl+K), only to the Agent. As of 2026-07-10.什么时候上 .mdc:你需要按文件 glob、或按描述智能触发,而不是「永远生效」时。多数项目,一份根目录的 AGENTS.md 加一两条按文件的 .mdc,就够了。AGENTS.md is just a simple markdown file in the project stating the rules the agent should keep; it nests per subdirectory, with the nearer one overriding the parent.2注 2Note 2Cursor Docs · Rules / AGENTS.md —— AGENTS.md 是放在项目里的一份简单 markdown,定义 agent 指令,支持项目根目录与子目录;是相对 .mdc 更轻量的写法。注意:User Rules 不作用于 Inline Edit(Cmd/Ctrl+K),只对 Agent 生效。截至 2026-07-10。Cursor Docs · Rules / AGENTS.md — AGENTS.md is a simple markdown file in the project that defines agent instructions, supported at the project root and in subdirectories; a lighter-weight alternative to .mdc. Note: User Rules don't apply to Inline Edit (Cmd/Ctrl+K), only to the Agent. As of 2026-07-10. When to reach for .mdc: when you need glob-by-file or description-based intelligent triggering rather than 'always on.' For most projects, one root AGENTS.md plus a by-file .mdc or two is enough.
# Project Agent Guide## Scope- This repository is <what this project is>.- Before editing, read <canonical docs / architecture file>.## Commands- Install: pnpm install- Test: pnpm test- Lint: pnpm lint- Typecheck: pnpm typecheck## Style- Follow existing patterns before introducing abstractions.- Keep changes scoped to the requested files and nearby tests.- Prefer small diffs and explain trade-offs.## Safety- Do not read .env* or private keys.- Do not run destructive shell commands without explicit approval.- Do not push, deploy, or change production resources.## Done Means- Relevant tests pass.- Diff is explained.- Risks and follow-ups are listed.
AGENTS.md 起手式 —— 放项目根目录,agent 每次开工先读AGENTS.md starter — at the project root; the agent reads it at the start of every session
坏规则Bad rule
写高质量代码,注意性能,风格要好,尽量不要出 bug。Write high-quality code, care about performance, use good style, avoid bugs if possible.
好规则Good rule
修改 `src/api/**` 时必须新增或更新同路径 `*.test.ts`;如果不加测试,解释具体原因。不要改 `lib/db.ts` 的连接生命周期。When changing `src/api/**`, add or update a same-path `*.test.ts`; if not, explain why. Do not change `lib/db.ts` connection lifecycle.
诚实的边界:rules 会腐烂。项目变了、约定改了,旧 rule 还在误导 agent —— 它比没有 rule 更糟,因为你信它。定期删一条过期的,比一直加新的更重要。钉得太多又没人读,等于没钉。The honest boundary: rules rot. The project shifts, conventions change, and a stale rule keeps misleading the agent — worse than no rule, because you trust it. Deleting one stale rule regularly matters more than always adding new ones. Pin too much and nothing gets read, which is the same as not pinning.
— IV
固化的落点,从「说法」扩到「做法」Pinning Widens: From Sayings to Doings.
Rule 钉的是「怎么说」;现在可钉的还有「怎么做、谁去做、什么绝不许做」。A rule pins how to say it; now you can also pin how it's done, who does it, and what must never happen.2026 年年中起,Cursor 把可固化的东西扩成了一族原语,并给了它们一个统一的家:Customize 页(3.9 起)把 plugins、skills、MCPs、subagents、rules、commands、hooks 收进一个面板,按 user / team / workspace 三层管理,还能从 Marketplace 一键装、看团队排行榜。3注 3Note 3Cursor Docs · Customize Cursor —— Customize 页(3.9,2026-06-22 起)把 plugins、skills、MCPs、subagents、rules、commands、hooks 收进一个面板,按 user / team / workspace 三层管理;可从 Cursor Marketplace 一键安装,并有团队最常用插件的排行榜。截至 2026-07-10。Cursor Docs · Customize Cursor — the Customize page (3.9, since 2026-06-22) gathers plugins, skills, MCPs, subagents, rules, commands, and hooks into one panel, managed at the user / team / workspace level; one-click installs from the Cursor Marketplace, plus a leaderboard of what your team uses most. As of 2026-07-10.别被名词吓到 —— 它们都是同一件事的延伸:把你不想重复交代的东西写成文件。区别只在钉的是什么:Since mid-2026, Cursor has widened what can be pinned into a family of primitives and given them one home: the Customize page (since 3.9) gathers plugins, skills, MCPs, subagents, rules, commands, and hooks into a single panel, managed at the user / team / workspace level, with one-click installs from the Marketplace and a team leaderboard.3注 3Note 3Cursor Docs · Customize Cursor —— Customize 页(3.9,2026-06-22 起)把 plugins、skills、MCPs、subagents、rules、commands、hooks 收进一个面板,按 user / team / workspace 三层管理;可从 Cursor Marketplace 一键安装,并有团队最常用插件的排行榜。截至 2026-07-10。Cursor Docs · Customize Cursor — the Customize page (3.9, since 2026-06-22) gathers plugins, skills, MCPs, subagents, rules, commands, and hooks into one panel, managed at the user / team / workspace level; one-click installs from the Cursor Marketplace, plus a leaderboard of what your team uses most. As of 2026-07-10. Don't let the nouns scare you — each is an extension of the same move, writing down what you refuse to keep re-explaining. They differ only in what gets pinned:
Skill —— 钉一类活怎么做Skill — pins how a kind of work is done
一个装着 SKILL.md 的文件夹,可带脚本和模板,按需加载、/ 一下调用。4注 4Note 4Cursor Docs · Agent Skills —— skill 是一个装着 SKILL.md 的文件夹(可带脚本、模板、参考资料),从 .cursor/skills / .agents/skills(项目级)与 ~/.cursor/skills 等(用户级)自动发现,兼容 .claude/skills / .codex/skills;agent 按相关性自动选用,也可用 / 手动调用;内置 /automate、/babysit、/review、/create-rule、/create-skill、/create-subagent 等。截至 2026-07-10。Cursor Docs · Agent Skills — a skill is a folder holding a SKILL.md (plus optional scripts, templates, references), auto-discovered from .cursor/skills / .agents/skills (project) and ~/.cursor/skills etc. (user), compatible with .claude/skills / .codex/skills; the agent picks skills by relevance, or you invoke them with /; built-ins include /automate, /babysit, /review, /create-rule, /create-skill, /create-subagent. As of 2026-07-10.你反复贴的那段长 prompt ——「按这个步骤出报告」「照这套规范迁移」—— 升格成 skill,流程本身成了资产。A folder holding a SKILL.md, with optional scripts and templates, loaded on demand or invoked with /.4注 4Note 4Cursor Docs · Agent Skills —— skill 是一个装着 SKILL.md 的文件夹(可带脚本、模板、参考资料),从 .cursor/skills / .agents/skills(项目级)与 ~/.cursor/skills 等(用户级)自动发现,兼容 .claude/skills / .codex/skills;agent 按相关性自动选用,也可用 / 手动调用;内置 /automate、/babysit、/review、/create-rule、/create-skill、/create-subagent 等。截至 2026-07-10。Cursor Docs · Agent Skills — a skill is a folder holding a SKILL.md (plus optional scripts, templates, references), auto-discovered from .cursor/skills / .agents/skills (project) and ~/.cursor/skills etc. (user), compatible with .claude/skills / .codex/skills; the agent picks skills by relevance, or you invoke them with /; built-ins include /automate, /babysit, /review, /create-rule, /create-skill, /create-subagent. As of 2026-07-10. The long prompt you keep pasting — 'produce the report by these steps,' 'migrate to this spec' — graduates into a skill, and the workflow itself becomes an asset.
Subagent —— 钉谁去做Subagent — pins who does it
给一类活配一个专职角色:自己的 prompt、工具、模型,独立上下文、可并行。5注 5Note 5Cursor Docs · Subagents —— subagent 是可委派的专职 agent:独立上下文窗口、可并行、可前台或后台跑,能配自己的 prompt、工具与模型;内置 Explore / Bash / Browser 三个;自定义放 .cursor/agents/(兼容 .claude/agents / .codex/agents);编辑器、CLI、Cloud Agents 里都能用。截至 2026-07-10。Cursor Docs · Subagents — a subagent is a delegatable specialist agent: its own context window, parallelizable, foreground or background, with its own prompt, tools, and model; three built-ins (Explore / Bash / Browser); custom ones live in .cursor/agents/ (compatible with .claude/agents / .codex/agents); available in the editor, CLI, and Cloud Agents. As of 2026-07-10.内置的 Explore / Bash / Browser 就是三个官配 —— 把搜代码、跑命令、开浏览器这些吵闹的中间过程隔离在主会话之外。Give a kind of work its own specialist: its own prompt, tools, and model, in an isolated context, runnable in parallel.5注 5Note 5Cursor Docs · Subagents —— subagent 是可委派的专职 agent:独立上下文窗口、可并行、可前台或后台跑,能配自己的 prompt、工具与模型;内置 Explore / Bash / Browser 三个;自定义放 .cursor/agents/(兼容 .claude/agents / .codex/agents);编辑器、CLI、Cloud Agents 里都能用。截至 2026-07-10。Cursor Docs · Subagents — a subagent is a delegatable specialist agent: its own context window, parallelizable, foreground or background, with its own prompt, tools, and model; three built-ins (Explore / Bash / Browser); custom ones live in .cursor/agents/ (compatible with .claude/agents / .codex/agents); available in the editor, CLI, and Cloud Agents. As of 2026-07-10. The built-in Explore / Bash / Browser are three stock examples — keeping the noisy middle work of searching, shelling, and browsing out of your main conversation.
Hook —— 钉铁律Hook — pins the iron laws
hooks.json 里的脚本挂在 agent loop 的节点上,能观察、拦截、改写:改完自动跑 formatter、扫密钥、把危险写入挡在闸前。6注 6Note 6Cursor Docs · Hooks —— 在 hooks.json(项目或用户级,也可随插件装)里定义脚本,挂在 agent loop 的节点上,可观察、拦截、改写行为:改完跑 formatter、扫 PII / 密钥、把危险操作(如 SQL 写入)挡在闸前;cloud agents 也会执行仓库里 command 型的 hooks。截至 2026-07-10。Cursor Docs · Hooks — scripts defined in hooks.json (project or user level, or installed via plugins) attach to points in the agent loop and can observe, block, or modify behavior: run formatters after edits, scan for PII / secrets, gate risky operations like SQL writes; cloud agents also run command-based hooks from your repo. As of 2026-07-10.rule 是请求,模型可能没听;hook 是强制,代码替你把门。Scripts in hooks.json attach to points in the agent loop and can observe, block, or modify: run the formatter after edits, scan for secrets, gate dangerous writes.6注 6Note 6Cursor Docs · Hooks —— 在 hooks.json(项目或用户级,也可随插件装)里定义脚本,挂在 agent loop 的节点上,可观察、拦截、改写行为:改完跑 formatter、扫 PII / 密钥、把危险操作(如 SQL 写入)挡在闸前;cloud agents 也会执行仓库里 command 型的 hooks。截至 2026-07-10。Cursor Docs · Hooks — scripts defined in hooks.json (project or user level, or installed via plugins) attach to points in the agent loop and can observe, block, or modify behavior: run formatters after edits, scan for PII / secrets, gate risky operations like SQL writes; cloud agents also run command-based hooks from your repo. As of 2026-07-10. A rule is a request the model might miss; a hook is enforcement — code holds the gate for you.
Command —— 钉常用的那句话Command — pins the sentence you reuse
一个 markdown 文件、/ 调用,装一段复用 prompt。3注 3Note 3Cursor Docs · Customize Cursor —— Customize 页(3.9,2026-06-22 起)把 plugins、skills、MCPs、subagents、rules、commands、hooks 收进一个面板,按 user / team / workspace 三层管理;可从 Cursor Marketplace 一键安装,并有团队最常用插件的排行榜。截至 2026-07-10。Cursor Docs · Customize Cursor — the Customize page (3.9, since 2026-06-22) gathers plugins, skills, MCPs, subagents, rules, commands, and hooks into one panel, managed at the user / team / workspace level; one-click installs from the Cursor Marketplace, plus a leaderboard of what your team uses most. As of 2026-07-10.比 skill 轻,够用就别升级。A markdown file invoked with /, holding one reusable prompt.3注 3Note 3Cursor Docs · Customize Cursor —— Customize 页(3.9,2026-06-22 起)把 plugins、skills、MCPs、subagents、rules、commands、hooks 收进一个面板,按 user / team / workspace 三层管理;可从 Cursor Marketplace 一键安装,并有团队最常用插件的排行榜。截至 2026-07-10。Cursor Docs · Customize Cursor — the Customize page (3.9, since 2026-06-22) gathers plugins, skills, MCPs, subagents, rules, commands, and hooks into one panel, managed at the user / team / workspace level; one-click installs from the Cursor Marketplace, plus a leaderboard of what your team uses most. As of 2026-07-10. Lighter than a skill — if it's enough, don't upgrade.
升级路径还是老的:先一份 AGENTS.md;同一句话说了十遍,写成 rule;同一套带脚本的流程重复到第三遍,升成 skill;同一类活需要固定角色、要并行跑,配 subagent;只有「每次都必须、违反就出事」的硬约束,才值得上 hook。Customize 和 Marketplace 解决的是「放哪儿、怎么装」,不替你回答「该不该钉」—— 上一节那条纪律原样适用:钉得越多,读得越少。The upgrade path hasn't changed: start with one AGENTS.md; a sentence said ten times becomes a rule; a scripted workflow repeated a third time graduates into a skill; work that needs a fixed role run in parallel gets a subagent; only the hard constraints — 'every time, or something breaks' — deserve a hook. Customize and the Marketplace answer 'where it lives and how it installs,' not 'whether to pin it' — the discipline from the previous section applies unchanged: the more you pin, the less gets read.
这条规则是否可执行、可检查,而不是愿望?Is this rule executable and checkable, not a wish?
它是否只说一件事?如果有三件,拆三条。Does it say one thing? If it says three, split it.
它是否有正确触发方式,而不是无脑 alwaysApply?Does it have the right trigger, not reflexive alwaysApply?
它是否引用现有文件,而不是复制一大段会过期的内容?Does it reference canonical files instead of copying stale-prone text?
它是否含密钥、个人偏好、临时任务限制?这些不该提交。Does it contain secrets, personal preferences, or temporary task constraints? Those should not be committed.
把你最常重复的那句话钉下来:Pin down the one thing you most often repeat:
01
找出你跟 Cursor 重复最多的一条要求Find the instruction you repeat to Cursor most
可能是某个库、某种风格、某个别碰的目录,或某种写作口吻。It might be a library, a style, a directory to avoid, or a writing tone.
02
写成一条 rule 或一行 AGENTS.md,选对触发Write it as one rule or one AGENTS.md line, with the right trigger
全局就 always / User Rule,按文件就 globs,偶尔才用就 description 或手动。Global → always / User Rule; file-specific → globs; occasional → description or manual.
03
跑一个任务验证它被遵守,再删一条过期的Run a task to confirm it's honored, then delete one stale rule
确认你没再重复那句话;顺手清掉一条已经不成立的旧 rule。Confirm you didn't repeat the instruction; while you're there, clear one old rule that no longer holds.
说十遍不如钉一遍,
钉多了又没人读.
Pinning it once beats saying it ten times;
pin too much and nothing gets read.
Aklman Library
— 讨论Discussion
讨论Discussion.
评论区初始化中…Initializing comments…
01 / 01
没有匹配结果No matches.
换个关键词,或按 Esc 回到页面Try another keyword, or press Esc to return