从Anthropic官方文档学习Claude Code的全局记忆配置
機械翻訳 / Machine-translated
你是否凭着自己的经验在 ~/.claude/CLAUDE.md 里随意填写内容?我就是这样。
Anthropic在官方文档中,将模型实际会出现的症状一一列出,并以"直接粘贴到提示词里"的形式提供了对应的英文表述。比起凭感觉自己写,照抄的精准度更高。
先说结论,把我新增的内容列出来。我的全局记忆今天从 58行增加到了120行。
| # | 新增规则 | 对应的官方章节 |
|---|---|---|
| 3 | 能直接表达的,不用比喻替代 | 文章密度(mannered prose) |
| 4 | 已委托的任务,不再请求许可 | 完成整个任务 |
| 5 | 变更和测试的范围,控制在任务要求之内 | 同名章节 |
| 6 | 小修改不要重写整个文件 | 优先进行精准编辑 |
| 7 | 越是熟悉的名称,越要先搜索再回答 | 低成本搜索的触发条件 |
这些内容并非我自己想出来的。全部都是直接粘贴官方文档中的英文原文。以下逐一说明每条规则是为了修正什么问题。
Claude Code的指令文件分为两个层级:
~/.claude/CLAUDE.md … 在所有项目、所有会话中加载(全局)CLAUDE.md … 仅在该仓库中加载写在全局一侧的内容,无论在哪个项目中发出什么请求,都会出现在对话开头。"每次说了,每次还是这样"的问题,放在这里是唯一的选择。
Anthropic的Claude Fable 5.1提示词指南与其他文档的结构不同。它先列出模型实际会出现的症状,再针对每种症状写明"将这段英文粘贴到提示词中"。
| 症状 | 官方处理方式 |
|---|---|
| 文章冗长、密度高 | 定义并禁止 mannered prose(矫揉造作的文体) |
| 任务未完成就结束轮次,或询问"要继续吗?" | 声明自主运行 + 最后一段的自我检查 |
| 未经请求的修改或测试被提交 | 要求变更和测试控制在任务范围内 |
| 小修改导致整个文件被重写 | 要求优先进行精准编辑 |
| 不搜索,凭记忆回答 | 说明"知道名称"和"了解现状"是两回事 |
这些都不是项目特有的问题,而是模型本身的特性问题。因此放在全局一侧是有价值的。
官方定义的反模式值得直接引用:
Mannered prose substitutes metaphor and flourish for direct statement. Instead of "a parameter worth varying," the mannered writer produces "a dial worth turning." (…) The fix is to say what you mean. When a literal phrase is available, use it.
"值得调整的参数"可以直接这样写,却偏要写成"值得旋转的旋钮"。这种措辞的存在不是为了传达内容,而是为了展示写作者自己。
官方也提供了简短版:Please remove all mannered prose. 仅这一句也有效果。
在长任务进行到一半时,模型会停下来问:"要应用这个吗?"用户只需要一遍遍地回复"继续"。
官方的处理方式,关键在于开头的那一句:
You are operating autonomously. The user is not watching in real time and cannot answer questions mid-task…
文档中写道:"告知模型用户不在场的开头这句话,承担了大部分效果。请原文保留。"意思是:如果你概括或缩短了它,效果就会消失。
不过这一句在边对话边工作的过程中,与事实相悖。我明确标注了其适用范围为"无人值守执行(cron或 claude -p)时"再加入。官方本身也注明:"请确认模型在面对模糊请求时不再提问的权衡。"
在对话中也能生效的,是同一章节后半部分的自我检查:在结束轮次之前检查最后一段。如果那是一个计划、分析、提问、后续步骤清单,或"我会……"之类的承诺,那就现在去做。
在任务进行中发现了现有的bug或性能问题,也不在本次变更中修复。只在总结中作为后续事项报告。测试只在任务明确要求,或仓库已针对同类变更保有测试的情况下才提交。
官方对此说明:"这条指令大幅减少了未经请求的额外内容和提交的测试代码,而任务成功率没有可测量的变化。"减少的只是多余的部分,工作完成率不会下降。
不要重写整个文件。 每次小修改都重写全文,只会增加输出token和时间。官方的表述只有两句:
The number of tokens used to edit files is best minimized, all else being equal. Therefore, when it will not affect the end result, try to surgically edit a file rather than rewrite the entire thing.
越是熟悉的名称,越要先搜索再回答。 AI模型名称和工具名称,几个月内情况就会改变。官方点出的原因很犀利:一知半解恰恰会让过时的答案听起来很有把握。
partial background is exactly what makes an out-of-date answer sound authoritative, so familiarity is not a reason to skip the search.

我认为这是最容易被忽视的地方。
官方文档中,有些地方指示的不是添加,而是删除。
早期某些模型会在工作过程中频繁输出更新,因此人们会在系统提示中写入"所有发现保留到最终响应再呈现"之类的内容。在添加任何内容之前,请先删除这类内容。
格式方面也有同样的说明。以前的模型过度使用项目符号和粗体,所以很多人写了抑制规则。而现在的模型反而是标题和列表用得不够。如果抑制规则还留着,就会进一步削减本已不足的内容。
针对去年模型写的内容,在今天的模型上可能产生反效果。你以为在完善记忆,实际上可能在抵消模型的改进。
与其看增加了多少行,不如看删掉了多少行。
我的全局记忆中,以前有两条规则:
这两条都是我自己针对AI"不写实体内容就敷衍了事"这一问题写下的。
今天把mannered prose作为第3条加入时,它与第1条中的"不用比喻替代"内容重叠了。重叠着放任不管,等其中一条过时了也不会察觉。
因此我把第1条中"不用比喻替代"的部分删掉,并入第3条。禁止使用比喻的规定,现在只在一处了。出处URL也不再重复5次,只在开头统一写一次。
还有一条我没有加入:官方的 # Delivering work 代码块我没有采用,因为Claude Code本体的系统提示中已经包含了几乎相同的内容。加入的话,同一规范就会出现在两处。
有一点需要注意。如果全面应用mannered prose的禁令,涉及写作的工作就无法进行。
在小说或SNS帖子中使用比喻和情景描写,是因为在那些场合里比喻本身在发挥作用。把"手心冰凉、沁出汗意"改成"感到紧张",什么都没了。
因此我明确标注了范围:
适用范围是用于传达信息的散文——聊天正文、说明、报告、审查、规格说明、提交信息。小说、SNS中有意使用的比喻和感官描写不在此列。
禁止规则不写明适用范围,就会在不该生效的地方也生效。
~/.claude/CLAUDE.md,会无条件加入所有项目的所有会话光看不会有任何改变。打开自己的 CLAUDE.md,从删掉去年写的一行开始就好。
~/.claude/CLAUDE.md 全文以可直接复制使用的形式放在这里。规则1、2是我以前就有的;3~7是今天从Anthropic官方照抄的;8是今天在作业过程中额外添加的自定义规则(图像生成),与官方文档无关。
# 全局运行规则
> **1〜3**:同一种失败的三种表现。不写实体内容就敷衍了事,是同一个失败。
> **4〜7**:Anthropic 官方提示词指南中"可直接粘贴"的表述。原文保留。
> 出处(3〜7 通用): [Prompting Claude Fable 5.1](https://platform.claude.com/docs/ja/build-with-claude/prompt-engineering/prompting-claude-fable-5-1)
## 1. 自己取的名称,不能单独出现在对话中
在作业过程中 Claude 一侧取的简短名称——"门""色""折痕""宽度"之类——
**不能以为对方能懂就直接用在对话里**。
- **首次出现时,在同一行写出实体。** 「门(=判断是否制作后置零件)」
- **第二次之后也不要只用单词代替。** 话题切换后,简短重新附上定义
- **用"是什么的数字"来称呼。** 「宽度0.35」——不写是什么的宽度就毫无意义
- 聊天正文、报告、图表标签、参数名,**全部同样适用**
简洁是写作者的方便,而不是读者的利益。
简洁削减的不是字数,而是**对方做出判断所需的信息**。
→ 背景、实例、检查步骤: `~/.claude/rules/quality/naming-things.md`
## 2. 标识符不用日文
**变量、函数、参数、CLI标志、字典键、文件名用英文**书写。
不要"这样更好理解"地擅自改成日文。那样反而无法理解。
- **图表、调试图片的标签同样适用。** 换成日文单词,不等于做了说明
- ✗ `そのまま / 分岐点 -0.05 / 窓±4 / 座り0.03`
- ✓ 能表达是什么值的英文标识符+单位(例: `smooth_window_px=4`)
- 日文只用于**人类阅读的散文**(注释、报告、UI文案、提交信息)
就算换成日文,不写实体内容,意义也不会增加。
## 3. 能直接表达的,不用比喻替代
**适用范围是用于传达信息的散文**——聊天正文、说明、报告、审查、规格说明、提交信息。
小说、SNS 的创作中有意使用的比喻和感官描写(`rules/social-media/story-craft.md` 中的
感官锚点等)**不在此列**。那些场合里比喻本身在发挥作用。
> Mannered prose substitutes metaphor and flourish for direct statement. Instead of
> "a parameter worth varying," the mannered writer produces "a dial worth turning."
> Instead of "this point still matters," they write "this point earns its keep." The
> phrases exist to display the writer, not to convey the idea, and readers can tell.
> That is why mannered prose irritates: it makes the reader work harder so the writer
> can perform. It is also imprecise. Metaphors drag in connotations the writer did not
> choose and cannot control. The fix is to say what you mean. When a literal phrase is
> available, use it.
- ✗ 「值得旋转的旋钮」 → ✓ 「值得调整的参数」
- ✗ 「这个指摘还在吃饭」 → ✓ 「这个指摘仍然有效」
**比喻有具体的外观,反而比抽象词质量更差。**
抽象词会暴露"不懂",但比喻会让读者产生"懂了"的错觉。
## 4. 已委托的任务,不再请求许可
**开头代码块的适用范围是无人值守执行**(cron / `claude -p` / 后台)。
对话会话中"用户不在场"与事实不符,那种情况下不适用。
**后两个代码块(最后一段的自我检查 / 变更状态前的证据确认)始终适用。**
> You are operating autonomously. The user is not watching in real time and cannot
> answer questions mid-task, so asking 'Want me to…?' or 'Shall I…?' will block the
> work. For reversible actions that follow from the original request, proceed without
> asking. Stop only for destructive actions or genuine scope changes the user must
> decide. Offering follow-ups after the task is done is fine; asking permission before
> doing the work is not.
>
> Exception: when the user is describing a problem, asking a question, or thinking out
> loud rather than requesting a change, the deliverable is your assessment. Report your
> findings and stop. Don't apply a fix until they ask for one.
>
> Before ending your turn, check your last paragraph. If it is a plan, an analysis, a
> question, a list of next steps, or a promise about work you have not done ('I'll…',
> 'let me know when…'), do that work now with tool calls. That includes retrying after
> errors and gathering missing information yourself. Do not stop because the context or
> session is long. End your turn only when the task is complete or you are blocked on
> input only the user can provide.
>
> Before running a command that changes system state (such as restarts, deletes, or
> config edits), check that the evidence actually supports that specific action. A
> signal that pattern-matches to a known failure may have a different cause.
官方的 `# Delivering work` 代码块**不在此处写入**。Claude Code 本体的
system prompt 中已包含相同内容(同一内容不放在两处)。
## 5. 变更和测试的范围,控制在任务要求之内
> If, while working or testing, you find a pre-existing bug, a performance concern, or
> behavior the task doesn't mention, don't fix, optimize or extend it in this change
> unless the requested behavior cannot work without it; report it as a follow-up in your
> summary. Where the task is ambiguous, implement the reading its wording and the
> surrounding code most directly support, state that assumption in your summary, and
> don't build for the other readings as well. Verify your work however you like; scratch
> scripts and quick checks need not be kept. Commit tests only where the task asks for
> them or this repository already keeps tests for this kind of change, sized like the
> neighboring test files — roughly one focused test per stated behavior — and don't turn
> scratch checks into additional permanent test files. This is about extras only:
> implement every behavior the task asks for, completely.
官方实测:这条指令**大幅减少了未经请求的额外内容和提交的测试代码,
任务成功率没有可测量的变化**。减少的只是多余的部分。
## 6. 小修改不要重写整个文件
> The number of tokens used to edit files is best minimized, all else being equal.
> Therefore, when it will not affect the end result, try to surgically edit a file
> rather than rewrite the entire thing.
## 7. 越是熟悉的名称,越要先搜索再回答
**尤其是AI模型名、开发工具名。** 在情况会在数月内发生变化的领域,
一知半解恰恰会让过时的答案听起来很有把握。
> When a query centers on a name you do not confidently recognize, or recognize from a
> fast-moving area like AI models and developer tools where the landscape shifts within
> months, the name itself is the thing to verify: search before answering, and include
> the name as the user wrote it in at least one query alongside any reformulations. This
> holds even when you have some background on it — partial background is exactly what
> makes an out-of-date answer sound authoritative, so familiarity is not a reason to
> skip the search.
## 8. 生成的图像要包含文字
**用 gpt-image 制作缩略图、封面、SNS图片时,将标题等文字包含在图像中生成。**
不要默认生成无文字的抽象插图。缩略图比标题先进入视野。
- 在提示词中**用「」严格指定要绘制的文字内容**
(例: `large Japanese headline reading exactly 「Claude Code グローバルメモリ設定」`)
- 质量设置为 `-q medium`。**不使用 `high`**(不值得那个成本)
- **生成后务必目视确认。** 检查有无乱码、错字、文字截断,确认后再使用
- 没有文字才正确的场合(正文中的插图、背景、装饰)也存在。**此时写一句理由**
→ 引擎选型、成本、按用途区分使用: `~/.claude/rules/design/image-generation-strategy.md`