做产品 PMaker
空格的键盘
约束 CLAUDE.md ·整个项目一直生效 写一次,管几个月 规格 docs/specs/*.md ·一个模块内一直生效 写一次,管几周 提示 你打的那段字 ·只管这一次 说完就过去了 同一句话反复说三次,就该往上挪一层

三层的区别只有一个:生效范围有多大、存活多久。放错层,就要么反复重讲,要么到处失灵。

Spec, Prompt, Constraints: Who Does What

Where a sentence belongs depends on how long it needs to stay in force. Temporary things go in the prompt, things that apply across a module go in the spec, things that apply across the whole project go in the constraints file.

What you'll run into
  • 每次对话都要重复交代同样的规矩
  • 约束文件越写越长,最后它开始不遵守了
  • 改到第三轮,它推翻了第一轮定好的数据结构

What goes in each layer

层放在哪写什么典型内容
约束 CLAUDE.md 整个项目一直成立的规矩 组件必须实现四态、间距只用这六个值、权限一律后端校验
规格 docs/specs/模块名.md 某个模块的数据、状态、边界 评论支持两层楼中楼、删除是软删除、超 500 字折叠
提示 你打的那段字 这一次要做的具体事 把这个按钮挪到右上角、这里的间距改成 24
"Would removing it cause an error?" is a useful sieve. Half of most people's constraint files describe the project rather than constrain behavior—that half can go.

There's an ordering among the three layers: constraints are the backdrop, the spec is the module's setup, and the prompt is the current action. All three take effect at once when code is generated; on conflict, the lower layer wins—but to override cleanly, say so explicitly rather than hoping it judges for itself.

同一句话该写在哪,取决于它要管多久 有效期 约束 CLAUDE.md 整个项目一直成立的规矩 组件必须实现四态 · 间距只用这六个值 规格 docs/specs/模块.md 某个模块的数据、状态、边界 评论支持两层楼中楼 · 删除是软删除 提示 你打的那段字 这一次要做的具体事 把这个按钮挪到右上角 同一句话说了三次,挪进规格;在两个以上模块里都要重申,挪进约束。三次是个比「感觉说得有点多」可靠的阈值。 三层同时生效,冲突时以下层为准——但下层要覆盖上层,最好明确说出来,别指望它自己判断。
"Would removing it cause an error?" is a useful sieve. Half of most people's constraint files describe the project rather than constrain behavior—that half can go.

When to move something up

Constraints aren't commands

One thing to be clear about: the constraints file is not a hard switch. It enters the context as ordinary content; the model follows it probabilistically, not as a guarantee. That implies two things.

所以要精简
每一行都问一遍:删掉它会不会导致出错。不会就删。
控制在两百行以内。写得越长,每一条被遵守的概率越低。
所以要复查
关键约束不能只写在文件里,还要在当下这条指令里重申一次。
做完之后让它对照约束自检一遍,成本很低。
"Would removing it cause an error?" is a useful sieve. Half of most people's constraint files describe the project rather than constrain behavior—that half can go.