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 goes in each layer
| 层 | 放在哪 | 写什么 | 典型内容 |
|---|---|---|---|
| 约束 | CLAUDE.md | 整个项目一直成立的规矩 | 组件必须实现四态、间距只用这六个值、权限一律后端校验 |
| 规格 | docs/specs/模块名.md | 某个模块的数据、状态、边界 | 评论支持两层楼中楼、删除是软删除、超 500 字折叠 |
| 提示 | 你打的那段字 | 这一次要做的具体事 | 把这个按钮挪到右上角、这里的间距改成 24 |
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.
When to move something up
- If you've said the same thing three times, move it into the spec. Three is a decent threshold — more reliable than "feels like I'm saying this a lot."
- If it has to be restated across two or more modules, move it into constraints. What holds in only one module stays in that module's spec.
- If the spec changes, the code changes too. And vice versa — change the code without updating the spec and the spec is dead. Have the AI update the spec file first before every change.
- Delete the constraints file on a regular schedule. Once the project has moved on, stale constraints are worse than none — they make the AI produce things you no longer want.
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.
