content-forge-vault/02-drafts/2026-03-03-claude-code-auto-memory-deep-dive-formatted.html
2026-03-05 17:09:06 +08:00

184 lines
74 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html style=" ">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>我翻遍了Claude Code的system prompt发现它的\"记忆\"就是一个200行的markdown文件</title>
</head>
<body style="padding: 24px; background: #ffffff; max-width: 860px; margin: 0 auto; font-family: -apple-system-font,BlinkMacSystemFont, Helvetica Neue, PingFang SC, Hiragino Sans GB , Microsoft YaHei UI , Microsoft YaHei ,Arial,sans-serif; font-size: 16px; line-height: 1.75; text-align: left;">
<div id="output">
<section class="container" style="font-family: -apple-system-font,BlinkMacSystemFont, Helvetica Neue, PingFang SC, Hiragino Sans GB , Microsoft YaHei UI , Microsoft YaHei ,Arial,sans-serif; font-size: 16px; line-height: 1.75; text-align: left;"><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0; margin-top: 0 !important;"><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">id: 2026-03-03-claude-code-auto-memory-deep-dive<br>title: 我翻遍了Claude Code的system prompt发现它的&quot;记忆&quot;就是一个200行的markdown文件<br>slug: claude-code-auto-memory-deep-dive<br>status: draft<br>content_type: article<br>channels:<br>language: zh-CN<br>source_urls:</p><ul class="ul" style="list-style: circle; padding-left: 1em; margin-left: 0; color: #3f3f3f;"><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">&quot;https: //blakecrosley.com/en/blog/context-window-management&quot;<br>assets:<br>cover_image: 05-assets/claude-code-auto-memory-deep-dive/01-infographic-memory-system-overview.png<br>template: article<br>owner: content-forge<br>created_at: 2026-03-03T00:00:00+08:00<br>updated_at: 2026-03-04T00:00:00+08:00<br>style: lizi_kk<br>audience: Claude Code 用户、AI 编程从业者、开发者<br>tags:<br>source_notes:</li></ul><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">说实话,用 Claude Code 的人都有一个抓狂时刻——每次新开会话,它对你的项目一无所知。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">你得重新说一遍:“我们用 FastAPI + Next.js后端端口 9801状态管理用 Zustand上次那个 bug 根因是连接池耗尽……”</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">烦不烦?</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">2026 年 2 月 5 日Anthropic 发布了 Opus 4.6。大多数人只看到了“更强的模型”。但真正改变日常开发体验的,是三个不起眼的底层能力:</p><ul class="ul" style="list-style: circle; padding-left: 1em; margin-left: 0; color: #3f3f3f;"><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">Auto Memory</strong>——跨会话持久记忆</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">Agent Teams</strong>——多智能体并行协作</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">Context Compaction</strong>——上下文智能压缩</li></ul><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">内部测试数据:智能体性能提升 39%100 轮对话 token 消耗降低 84%,支持 30 小时无人值守。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">这篇文章,我把 Auto Memory 的底层机制逐层拆开——system prompt 注入原文、200 行硬截断的真实含义、5 个我全踩过的坑,以及它和 Agent Teams、Context Compaction 之间怎么配合。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">如果你每天都在用 Claude Code这篇值得收藏。</p><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><img src="MDTOHTMLIMGPH_1" data-local-path="/home/kang/apps/content-forge/content-forge/02-drafts/05-assets/claude-code-auto-memory-deep-dive/01-infographic-memory-system-overview.png" style="display: block; width: 100%; margin: 1.5em auto;"></p><h2 class="h2" data-heading="true" style="display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: #0F4C81; font-size: calc(16px * 1.2); font-weight: bold; text-align: center;">01 Claude Code 的记忆到底有几层</h2><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">先看全貌。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">Claude Code 的记忆不是一坨东西,是分层的:</p><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-" data-language-pending data-raw-code="┌──────────────────────────────────────────────────────┐
│ Layer 0: Enterprise Rules最高优先级
│ └─ 组织管理员的全局规则,所有用户强制生效 │
│ │
│ Layer 1: CLAUDE.md 文件族(静态指令 · 人工维护) │
│ ├─ ~/.claude/CLAUDE.md ← 用户级,所有项目 │
│ ├─ <project>/CLAUDE.md ← 项目级,入库共享 │
│ ├─ <project>/CLAUDE.local.md ← 项目级,本地私有 │
│ └─ <subdir>/CLAUDE.md ← 子目录级,按需加载 │
│ │
│ Layer 2: Auto Memory动态知识 · Claude 自主维护) │
│ ├─ MEMORY.md ← 主索引自动加载200行上限
│ └─ *.md ← 主题文件,按需读取(无行数限制) │
│ │
│ Layer 3: Subagent Memory子代理记忆 · 独立隔离) │
│ │
│ Layer 4: Session Context会话上下文 · 临时) │
└──────────────────────────────────────────────────────┘" data-show-line-number="undefined" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;">┌──────────────────────────────────────────────────────┐<br>&nbsp;&nbsp;Layer&nbsp;0:&nbsp;Enterprise&nbsp;Rules最高优先级&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;└─&nbsp;组织管理员的全局规则,所有用户强制生效&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;Layer&nbsp;1:&nbsp;CLAUDE.md&nbsp;文件族(静态指令&nbsp;·&nbsp;人工维护)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;├─&nbsp;~/.claude/CLAUDE.md&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用户级,所有项目&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;├─&nbsp;&lt;project&gt;/CLAUDE.md&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;项目级,入库共享&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;├─&nbsp;&lt;project&gt;/CLAUDE.local.md&nbsp;&nbsp;&nbsp;项目级,本地私有&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;└─&nbsp;&lt;subdir&gt;/CLAUDE.md&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;子目录级,按需加载&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;Layer&nbsp;2:&nbsp;Auto&nbsp;Memory动态知识&nbsp;·&nbsp;Claude&nbsp;自主维护)&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;├─&nbsp;MEMORY.md&nbsp;&nbsp;&nbsp;主索引自动加载200行上限&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;└─&nbsp;*.md&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;主题文件,按需读取(无行数限制)&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;Layer&nbsp;3:&nbsp;Subagent&nbsp;Memory子代理记忆&nbsp;·&nbsp;独立隔离)&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;Layer&nbsp;4:&nbsp;Session&nbsp;Context会话上下文&nbsp;·&nbsp;临时)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>└──────────────────────────────────────────────────────┘</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><img src="MDTOHTMLIMGPH_2" data-local-path="/home/kang/apps/content-forge/content-forge/02-drafts/05-assets/claude-code-auto-memory-deep-dive/02-framework-three-layer-architecture.png" style="display: block; width: 100%; margin: 1.5em auto;"></p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">一句话说清楚 Layer 1 和 Layer 2 的关系:</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">Layer 1 是项目手册</strong>——你写的规则、命令、规范,入 Git团队共享。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">Layer 2 是个人笔记</strong>——Claude 自己记的调试心得、踩坑经验,不入 Git纯本地。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">一个是宪法,一个是草稿纸。互补,不是替代。</p>
<section style="font-family: -apple-system-font,BlinkMacSystemFont, Helvetica Neue, PingFang SC, Hiragino Sans GB , Microsoft YaHei UI , Microsoft YaHei ,Arial,sans-serif; font-size: 16px; line-height: 1.75; text-align: left; max-width: 100%; overflow: auto;">
<table class="preview-table" style="color: #3f3f3f; margin-top: 0 !important;">
<thead style="font-weight: bold; color: #3f3f3f;"><th class="th" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all; background: rgba(0, 0, 0, 0.05);"></th><th class="th" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all; background: rgba(0, 0, 0, 0.05);">CLAUDE.md手册</th><th class="th" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all; background: rgba(0, 0, 0, 0.05);">Auto Memory笔记</th></thead>
<tbody><tr class="tr"><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">谁写</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">人工维护</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">Claude 主动写入</td></tr><tr class="tr"><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">内容</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">编码规范、构建命令、禁止事项</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">陷阱、失败模式、调试经验</td></tr><tr class="tr"><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">入 Git</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">是(团队共享)</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">否(个人本地)</td></tr><tr class="tr"><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">上限</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">无硬限制</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">200 行(主索引)</td></tr><tr class="tr"><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">更新频率</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">低(架构变更才改)</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">高(每次会话可能更新)</td></tr><tr class="tr"><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">典型内容</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">“始终使用 pytest 运行测试”</td><td class="td" style="border: 1px solid #dfdfdf; padding: 0.25em 0.5em; color: #3f3f3f; word-break: keep-all;">“检查 A 必须在 B 之前,否则测试 X 挂”</td></tr></tbody>
</table>
</section>
<p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">搞清楚这两层的区别,后面的东西才看得懂。</p><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><h2 class="h2" data-heading="true" style="display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: #0F4C81; font-size: calc(16px * 1.2); font-weight: bold; text-align: center;">02 从 # 前缀到 Auto Memory三个阶段</h2><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">Auto Memory 不是凭空冒出来的。</p><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-" data-language-pending data-raw-code="阶段 1: # 前缀时代(已弃用)
└─ 用户在对话中用 # 标记重要信息
└─ Claude 被动记录,能力有限
└─ 问题完全依赖用户主动标记Claude 不会判断
阶段 2: Research Preview
└─ 需要手动开启settings.json 加 autoMemoryEnabled: true
└─ Claude 开始有&quot;自主写入&quot;能力
└─ 问题:默认关闭,大多数人根本不知道
阶段 3: 正式发布v2.1.32+,当前)
└─ 默认开启,无需配置
└─ 可用环境变量关闭CLAUDE_CODE_DISABLE_AUTO_MEMORY=1
└─ 与 Opus 4.6 的 Agent Teams / Context Compaction 协同" data-show-line-number="undefined" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;">阶段&nbsp;1:&nbsp;#&nbsp;前缀时代(已弃用)<br>&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;用户在对话中用&nbsp;#&nbsp;标记重要信息<br>&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;Claude&nbsp;被动记录,能力有限<br>&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;问题完全依赖用户主动标记Claude&nbsp;不会判断<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>阶段&nbsp;2:&nbsp;Research&nbsp;Preview<br>&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;需要手动开启settings.json&nbsp;&nbsp;autoMemoryEnabled:&nbsp;true<br>&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;Claude&nbsp;开始有&quot;自主写入&quot;能力<br>&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;问题:默认关闭,大多数人根本不知道<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>阶段&nbsp;3:&nbsp;正式发布v2.1.32+,当前)<br>&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;默认开启,无需配置<br>&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;可用环境变量关闭CLAUDE_CODE_DISABLE_AUTO_MEMORY=1<br>&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;&nbsp;Opus&nbsp;4.6&nbsp;&nbsp;Agent&nbsp;Teams&nbsp;/&nbsp;Context&nbsp;Compaction&nbsp;协同</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">还在用 # 前缀标记的,该换了。</strong></p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">说实话,大部分人连阶段 2 都没用过。这功能藏得太深,如果不是我挨个翻 settings.json 的字段,根本发现不了。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">但真正有意思的不是这个演进历史——是 Auto Memory 的底层实现,朴素得超乎想象。</p><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><h2 class="h2" data-heading="true" style="display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: #0F4C81; font-size: calc(16px * 1.2); font-weight: bold; text-align: center;">03 底层真相:没有向量数据库,没有 RAG就是读写文件</h2><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">先说结论:<strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">就是 Claude 被允许在你电脑上的一个文件夹里读写 markdown 文件。</strong></p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">没有向量数据库。没有语义检索。没有 RAG。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">每次开新会话,主文件塞进 system prompt。完事。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">零依赖,纯文件 I/O。</p><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-" data-language-pending data-raw-code="~/.claude/projects/<project-path-hash>/memory/
├── MEMORY.md ← 主索引每次自动加载上限200行
├── debugging.md ← 主题文件(按需创建,不自动加载)
├── patterns.md
├── architecture.md
└── ..." data-show-line-number="undefined" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;">~/.claude/projects/&lt;project-path-hash&gt;/memory/<br>├──&nbsp;MEMORY.md&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;主索引每次自动加载上限200行<br>├──&nbsp;debugging.md&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;主题文件(按需创建,不自动加载)<br>├──&nbsp;patterns.md<br>├──&nbsp;architecture.md<br>└──&nbsp;...</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">你可能觉得“就这?”</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">对,就这。这就是 Anthropic 的风格——<strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">用最简单的机制解决 80% 的问题</strong>。不过度工程化,不引入额外依赖。</p><h3 class="h3" data-heading="true" style="padding-left: 8px; border-left: 3px solid #0F4C81; margin: 2em 8px 0.75em 0; color: #3f3f3f; font-size: calc(16px * 1.1); font-weight: bold; line-height: 1.2;">拆开 system promptClaude 到底看到了什么</h3><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">大多数文章不会讲这部分。以下是我从实际运行环境中提取的完整 system prompt 注入内容:</p><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-" data-language-pending data-raw-code="You have a persistent auto memory directory at
`~/.claude/projects/<project>/memory/`.
Its contents persist across conversations.
## How to save memories:
- Organize memory semantically by topic, not chronologically
- Use the Write and Edit tools to update your memory files
- MEMORY.md is always loaded into your conversation context
— lines after 200 will be truncated, so keep it concise
- Create separate topic files (e.g., debugging.md, patterns.md)
for detailed notes and link to them from MEMORY.md
- Update or remove memories that turn out to be wrong or outdated
- Do not write duplicate memories.
## What to save:
- Stable patterns confirmed across multiple interactions
- Key architectural decisions, important file paths
- User preferences for workflow and tools
- Solutions to recurring problems
## What NOT to save:
- Session-specific context
- Information that might be incomplete
- Anything that duplicates CLAUDE.md instructions
- Speculative conclusions from reading a single file" data-show-line-number="undefined" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;">You&nbsp;have&nbsp;a&nbsp;persistent&nbsp;auto&nbsp;memory&nbsp;directory&nbsp;at<br>`~/.claude/projects/&lt;project&gt;/memory/`.<br>Its&nbsp;contents&nbsp;persist&nbsp;across&nbsp;conversations.<br><br>##&nbsp;How&nbsp;to&nbsp;save&nbsp;memories:<br>-&nbsp;Organize&nbsp;memory&nbsp;semantically&nbsp;by&nbsp;topic,&nbsp;not&nbsp;chronologically<br>-&nbsp;Use&nbsp;the&nbsp;Write&nbsp;and&nbsp;Edit&nbsp;tools&nbsp;to&nbsp;update&nbsp;your&nbsp;memory&nbsp;files<br>-&nbsp;MEMORY.md&nbsp;is&nbsp;always&nbsp;loaded&nbsp;into&nbsp;your&nbsp;conversation&nbsp;context<br>&nbsp;&nbsp;&nbsp;lines&nbsp;after&nbsp;200&nbsp;will&nbsp;be&nbsp;truncated,&nbsp;so&nbsp;keep&nbsp;it&nbsp;concise<br>-&nbsp;Create&nbsp;separate&nbsp;topic&nbsp;files&nbsp;(e.g.,&nbsp;debugging.md,&nbsp;patterns.md)<br>&nbsp;&nbsp;for&nbsp;detailed&nbsp;notes&nbsp;and&nbsp;link&nbsp;to&nbsp;them&nbsp;from&nbsp;MEMORY.md<br>-&nbsp;Update&nbsp;or&nbsp;remove&nbsp;memories&nbsp;that&nbsp;turn&nbsp;out&nbsp;to&nbsp;be&nbsp;wrong&nbsp;or&nbsp;outdated<br>-&nbsp;Do&nbsp;not&nbsp;write&nbsp;duplicate&nbsp;memories.<br><br>##&nbsp;What&nbsp;to&nbsp;save:<br>-&nbsp;Stable&nbsp;patterns&nbsp;confirmed&nbsp;across&nbsp;multiple&nbsp;interactions<br>-&nbsp;Key&nbsp;architectural&nbsp;decisions,&nbsp;important&nbsp;file&nbsp;paths<br>-&nbsp;User&nbsp;preferences&nbsp;for&nbsp;workflow&nbsp;and&nbsp;tools<br>-&nbsp;Solutions&nbsp;to&nbsp;recurring&nbsp;problems<br><br>##&nbsp;What&nbsp;NOT&nbsp;to&nbsp;save:<br>-&nbsp;Session-specific&nbsp;context<br>-&nbsp;Information&nbsp;that&nbsp;might&nbsp;be&nbsp;incomplete<br>-&nbsp;Anything&nbsp;that&nbsp;duplicates&nbsp;CLAUDE.md&nbsp;instructions<br>-&nbsp;Speculative&nbsp;conclusions&nbsp;from&nbsp;reading&nbsp;a&nbsp;single&nbsp;file</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><img src="MDTOHTMLIMGPH_3" data-local-path="/home/kang/apps/content-forge/content-forge/02-drafts/05-assets/claude-code-auto-memory-deep-dive/03-flowchart-auto-memory-trigger.png" style="display: block; width: 100%; margin: 1.5em auto;"></p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">Auto Memory 的全部“智能”就来自这段指令。</strong></p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">Claude 没有特殊的记忆模块,没有额外的神经网络组件。它只是被告知“你有个文件夹可以读写,按规则来”——跟你在 CLAUDE.md 里写“遇到 bug 先跑测试”是完全同一个机制。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">这也解释了一个很多人困惑的问题:为什么 Claude 的记忆写入行为这么不稳定?</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">答案很简单。忙着干活的时候,这段指令的优先级自然被压低。不是不想记,是顾不上。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">但我觉得这恰恰是好的工程品味。你见过很多方案搞 embedding + vector store + semantic search链路一长出 bug 的概率翻倍。Anthropic 选了最朴素的路,反而最稳。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">不过“朴素”不代表“没限制”。接下来这部分,才是整篇文章最关键的。</p><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><h2 class="h2" data-heading="true" style="display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: #0F4C81; font-size: calc(16px * 1.2); font-weight: bold; text-align: center;">04 200 行限制:比你想的更硬</h2><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">MEMORY.md 有 200 行的硬截断。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">注意,是<strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">硬截断</strong>——第 201 行开始直接消失。不是“存在但优先级低”,是 Claude 完全看不到:</p><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-" data-language-pending data-raw-code="MEMORY.md 总共 250 行
├─ 前 200 行 → 注入 system prompt ✓
└─ 第 201-250 行 → 硬截断Claude 完全看不到 ✗
└─ Claude 收到截断警告,建议你精简内容" data-show-line-number="undefined" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;">MEMORY.md&nbsp;总共&nbsp;250&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;├─&nbsp;&nbsp;200&nbsp;&nbsp;&nbsp;注入&nbsp;system&nbsp;prompt&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;&nbsp;201-250&nbsp;&nbsp;&nbsp;硬截断Claude&nbsp;完全看不到&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└─&nbsp;Claude&nbsp;收到截断警告,建议你精简内容</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><img src="MDTOHTMLIMGPH_4" data-local-path="/home/kang/apps/content-forge/content-forge/02-drafts/05-assets/claude-code-auto-memory-deep-dive/04-infographic-memory-file-structure.png" style="display: block; width: 100%; margin: 1.5em auto;"></p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">主题文件debugging.md 等没有行数限制。但它们不自动加载——Claude 得自己用 Read 工具去读。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">这里有个容易忽略的连锁反应:<strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">MEMORY.md 的索引质量决定了整个记忆系统的有效性。</strong></p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">如果里面没提某个主题文件Claude 压根不知道它存在。你精心写的 debugging.md 可能永远不会被读到。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">所以 MEMORY.md 只能当目录用:</p><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-markdown" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;"><span class="hljs-section">#&nbsp;Memory&nbsp;Index</span><span class="hljs-section"><br><br>##&nbsp;调试经验</span><span class="hljs-bullet"><br>-</span>&nbsp;[<span class="hljs-string">后端连接池问题</span>](<span class="hljs-link">./debugging.md</span>)&nbsp;-&nbsp;根因和修复方案<span class="hljs-section"><br><br>##&nbsp;架构决策</span><span class="hljs-bullet"><br>-</span>&nbsp;[<span class="hljs-string">消息工厂设计</span>](<span class="hljs-link">./architecture.md</span>)&nbsp;-&nbsp;分层逻辑<span class="hljs-section"><br><br>##&nbsp;用户偏好</span><span class="hljs-bullet"><br>-</span>&nbsp;[<span class="hljs-string">工作流</span>](<span class="hljs-link">./user-preferences.md</span>)&nbsp;-&nbsp;测试、部署、风格</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">简洁,只做索引,别超 200 行。这 200 行是你的“记忆预算”,花在刀刃上。</p><h3 class="h3" data-heading="true" style="padding-left: 8px; border-left: 3px solid #0F4C81; margin: 2em 8px 0.75em 0; color: #3f3f3f; font-size: calc(16px * 1.1); font-weight: bold; line-height: 1.2;">数据流:三个阶段看完</h3><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-" data-language-pending data-raw-code="┌──────────────────────────────────────────────────────┐
│ 阶段一:会话启动 │
│ Claude Code 读 MEMORY.md 前 200 行 → 塞进 prompt │
│ 其他 memory/*.md 不自动加载 │
└────────────────────────┬─────────────────────────────┘
┌──────────────────────────────────────────────────────┐
│ 阶段二:会话进行中 │
│ Claude 可能记录: │
│ ├─ gotchas——&quot;检查 A 必须在 B 之前,否则测试 X 挂&quot; │
│ ├─ 失败模式——&quot;该 API 并发 > 100 时返回 429&quot; │
│ ├─ 项目模式——&quot;所有 router 必须用 API_PREFIX 注册&quot; │
│ └─ 用户偏好——&quot;用户偏好 pnpm 而非 npm&quot; │
│ │
│ 写入时机: │
│ ├─ 你说&quot;记住这个&quot; → 立即写入(最靠谱) │
│ └─ Claude 自己觉得有用 → 看心情(不靠谱) │
└────────────────────────┬─────────────────────────────┘
┌──────────────────────────────────────────────────────┐
│ 阶段三:会话结束 │
│ 文件留在磁盘,下次自动可用 │
│ ⚠️ 没有&quot;会话结束时自动总结&quot;——社区方案存在的根因 │
└──────────────────────────────────────────────────────┘" data-show-line-number="undefined" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;">┌──────────────────────────────────────────────────────┐<br>&nbsp;&nbsp;阶段一:会话启动&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;Claude&nbsp;Code&nbsp;&nbsp;MEMORY.md&nbsp;&nbsp;200&nbsp;&nbsp;&nbsp;塞进&nbsp;prompt&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;其他&nbsp;memory/*.md&nbsp;不自动加载&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>└────────────────────────┬─────────────────────────────┘<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>┌──────────────────────────────────────────────────────┐<br>&nbsp;&nbsp;阶段二:会话进行中&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;Claude&nbsp;可能记录:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;├─&nbsp;gotchas——&quot;检查&nbsp;A&nbsp;必须在&nbsp;B&nbsp;之前,否则测试&nbsp;X&nbsp;&quot;&nbsp;&nbsp;<br>&nbsp;&nbsp;├─&nbsp;失败模式——&quot;&nbsp;API&nbsp;并发&nbsp;&gt;&nbsp;100&nbsp;时返回&nbsp;429&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;├─&nbsp;项目模式——&quot;所有&nbsp;router&nbsp;必须用&nbsp;API_PREFIX&nbsp;注册&quot;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;└─&nbsp;用户偏好——&quot;用户偏好&nbsp;pnpm&nbsp;而非&nbsp;npm&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;写入时机:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;├─&nbsp;你说&quot;记住这个&quot;&nbsp;&nbsp;立即写入(最靠谱)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;└─&nbsp;Claude&nbsp;自己觉得有用&nbsp;&nbsp;看心情(不靠谱)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>└────────────────────────┬─────────────────────────────┘<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>┌──────────────────────────────────────────────────────┐<br>&nbsp;&nbsp;阶段三:会话结束&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;文件留在磁盘,下次自动可用&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;⚠️&nbsp;没有&quot;会话结束时自动总结&quot;——社区方案存在的根因&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>└──────────────────────────────────────────────────────┘</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">第三阶段是关键设计取舍。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">官方方案完全依赖 Claude 在会话过程中的“自觉性”。</strong> 你聊了两小时发现三个重要结论,但 Claude 没记——那就真没了。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">这也是社区方案claude-mem、AutoMem存在的根本原因。后面会讲到怎么选。</p><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><h2 class="h2" data-heading="true" style="display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: #0F4C81; font-size: calc(16px * 1.2); font-weight: bold; text-align: center;">05 三板斧协同:一套组合拳</h2><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">Opus 4.6 同时上线的三个能力,不是各干各的,是一套组合拳:</p><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-" data-language-pending data-raw-code="┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Auto Memory │ │ Agent Teams │ │ Context │
│ 跨会话记忆 │ │ 多智能体协作 │ │ Compaction │
├──────────────┤ ├──────────────┤ ├──────────────┤
│ 解决: │ │ 解决: │ │ 解决: │
│ &quot;每次重新 │ │ &quot;一个人干 │ │ &quot;聊久了就 │
│ 介绍项目&quot; │ │ 不过来&quot; │ │ 忘事&quot; │
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
│ │ │
└──────────────────┼──────────────────┘
┌───────▼───────┐
│ 30小时无人 │
│ 值守自主运行 │
└───────────────┘" data-show-line-number="undefined" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;">┌──────────────┐&nbsp;&nbsp;&nbsp;┌──────────────┐&nbsp;&nbsp;&nbsp;┌──────────────┐<br>&nbsp;Auto&nbsp;Memory&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Agent&nbsp;Teams&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Context&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;跨会话记忆&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;多智能体协作&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Compaction&nbsp;&nbsp;<br>├──────────────┤&nbsp;&nbsp;&nbsp;├──────────────┤&nbsp;&nbsp;&nbsp;├──────────────┤<br>&nbsp;解决:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解决:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;解决:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&quot;每次重新&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;一个人干&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;聊久了就&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;介绍项目&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;不过来&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;忘事&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>└──────┬───────┘&nbsp;&nbsp;&nbsp;└──────┬───────┘&nbsp;&nbsp;&nbsp;└──────┬───────┘<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└──────────────────┼──────────────────┘<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;┌───────▼───────┐<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;30小时无人&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;值守自主运行&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;└───────────────┘</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">token 降 84%、性能升 39%——就是这三者组合的效果。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">但有几个细节,踩过坑才知道:</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">子代理记忆是隔离的。</strong> Agent Teams 的子代理有独立记忆空间,读不到主会话的 Auto Memory也不会污染主记忆。好处是干净坏处是子代理对你的项目上下文一无所知。你得在 prompt 里手动交代背景。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">Context Compaction 会吃掉记忆。</strong> 最新版在上下文使用率 64-75% 时就触发压缩——比以前的 90%+ 激进得多。MEMORY.md 的细节可能在压缩中被摘要化。你以为 Claude 记着呢,其实早忘了。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">Adaptive Thinking 省 token。</strong> Claude 根据问题复杂度自动调整思考深度,简单问题不浪费 token把预算留给真正需要深度推理的场景。这个倒是好消息。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">说到踩坑,接下来这部分我全经历过。</p><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><h2 class="h2" data-heading="true" style="display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: #0F4C81; font-size: calc(16px * 1.2); font-weight: bold; text-align: center;">06 5 个必踩的坑</h2><h3 class="h3" data-heading="true" style="padding-left: 8px; border-left: 3px solid #0F4C81; margin: 2em 8px 0.75em 0; color: #3f3f3f; font-size: calc(16px * 1.1); font-weight: bold; line-height: 1.2;">坑 1聊久了记忆被压缩掉</h3><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-" data-language-pending data-raw-code="会话开始: MEMORY.md 内容完整 ✓
▼ (对话越来越长)
上下文压缩触发64-75% 容量时)
MEMORY.md 的细节被摘要化 ✗" data-show-line-number="undefined" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;">会话开始:&nbsp;MEMORY.md&nbsp;内容完整&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(对话越来越长)<br>上下文压缩触发64-75%&nbsp;容量时)<br>&nbsp;&nbsp;&nbsp;&nbsp;<br>MEMORY.md&nbsp;的细节被摘要化&nbsp;</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">发现 Claude 开始“忘事”了?用 <code class="codespan" style="font-size: 90%; color: #d14; background: rgba(27, 31, 35, 0.05); padding: 3px 5px; border-radius: 4px;">/clear</code> 开新会话。记忆会重新完整加载。</p><h3 class="h3" data-heading="true" style="padding-left: 8px; border-left: 3px solid #0F4C81; margin: 2em 8px 0.75em 0; color: #3f3f3f; font-size: calc(16px * 1.1); font-weight: bold; line-height: 1.2;">坑 2Claude 经常忘记写笔记</h3><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">写入完全靠 Claude“自觉”。实际用下来</p><ul class="ul" style="list-style: circle; padding-left: 1em; margin-left: 0; color: #3f3f3f;"><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">• 忙着干活时根本想不起来记</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">• 写入质量参差不齐,有时太笼统,有时写了不该写的</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">• 不同模型版本的写入倾向还不一样</li></ul><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">最靠谱的办法就一个字:你自己说“把这个记下来”。</strong> 别指望它自觉。我现在养成了习惯,每次调试出重要结论,直接说“写到 memory 里”。</p><h3 class="h3" data-heading="true" style="padding-left: 8px; border-left: 3px solid #0F4C81; margin: 2em 8px 0.75em 0; color: #3f3f3f; font-size: calc(16px * 1.1); font-weight: bold; line-height: 1.2;">坑 3换路径打开项目记忆就断了</h3><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">记忆目录按项目路径哈希生成。同一个项目换个路径打开,就是两套独立记忆:</p><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-" data-language-pending data-raw-code="/home/user/apps/my-project → memory-A
/mnt/disk/my-project → memory-B" data-show-line-number="undefined" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;">/home/user/apps/my-project&nbsp;&nbsp;&nbsp;memory-A<br>/mnt/disk/my-project&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memory-B</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">多台机器或多个挂载点工作的,注意了。这个坑很隐蔽,你可能很久才会发现“怎么之前记的东西全没了”。</p><h3 class="h3" data-heading="true" style="padding-left: 8px; border-left: 3px solid #0F4C81; margin: 2em 8px 0.75em 0; color: #3f3f3f; font-size: calc(16px * 1.1); font-weight: bold; line-height: 1.2;">坑 4.claude.json 越来越胖</h3><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">GitHub issue #5024<code class="codespan" style="font-size: 90%; color: #d14; background: rgba(27, 31, 35, 0.05); padding: 3px 5px; border-radius: 4px;">.claude.json</code> 持续累积会话历史,文件越来越大。不是 Auto Memory 的锅,但会拖慢整体体验。定期清理一下。</p><h3 class="h3" data-heading="true" style="padding-left: 8px; border-left: 3px solid #0F4C81; margin: 2em 8px 0.75em 0; color: #3f3f3f; font-size: calc(16px * 1.1); font-weight: bold; line-height: 1.2;">坑 5旧记忆比没记忆更危险</h3><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">这个是最致命的。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">Claude 不会主动清理过时记忆。项目架构改了记忆还是旧的Claude 就会基于错误信息做决策。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">过时的记忆不是“没用”,是“有害”。</strong> 就像你手机导航用的三年前的地图——不是找不到路,是找到一条已经拆了的路。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">得你自己定期去看看,删掉过时的。我每周花 2 分钟扫一眼 memory 目录,这个习惯帮我躲过好几次大坑。</p><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><h2 class="h2" data-heading="true" style="display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: #0F4C81; font-size: calc(16px * 1.2); font-weight: bold; text-align: center;">07 官方够用吗?看项目规模</h2><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">官方 Auto Memory 不够用时,社区有两个主流替代。先看对比:</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><img src="MDTOHTMLIMGPH_5" data-local-path="/home/kang/apps/content-forge/content-forge/02-drafts/05-assets/claude-code-auto-memory-deep-dive/05-comparison-best-practices.png" style="display: block; width: 100%; margin: 1.5em auto;"></p><pre class="hljs code__pre" style="font-size: 90%; overflow-x: auto; border-radius: 8px; line-height: 1.5; margin: 10px 8px; padding: 0 !important;"><span class="mac-sign" style="display: none; padding: 10px 14px 0;"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="45px" height="13px" viewBox="0 0 450 130">
<ellipse cx="50" cy="65" rx="50" ry="52" stroke="rgb(220,60,54)" stroke-width="2" fill="rgb(237,108,96)"/>
<ellipse cx="225" cy="65" rx="50" ry="52" stroke="rgb(218,151,33)" stroke-width="2" fill="rgb(247,193,81)"/>
<ellipse cx="400" cy="65" rx="50" ry="52" stroke="rgb(27,161,37)" stroke-width="2" fill="rgb(100,200,86)"/>
</svg></span><code class="language-" data-language-pending data-raw-code=" 官方 Auto Memory claude-mem AutoMem
────────────── ────────── ───────
存储 纯 markdown 文件 压缩后的文本 图DB + 向量DB
写入触发 Claude 自主判断 Hook 自动捕获 Hook 自动捕获
会话结束 啥也不干 自动捕获+压缩 自动捕获+向量化
压缩 无 ~200:1 压缩率 向量化
依赖 零 Bun + uv Docker 全家桶
可靠性 看 Claude 心情 自动化,稳定 自动化,稳定" data-show-line-number="undefined" style="font-size: 90%; border-radius: 4px; display: -webkit-box; padding: 0.5em 1em 1em; overflow-x: auto; text-indent: 0; color: inherit; background: none; white-space: nowrap; margin: 0;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;官方&nbsp;Auto&nbsp;Memory&nbsp;&nbsp;&nbsp;&nbsp;claude-mem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AutoMem<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;──────────────&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;──────────&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;───────<br>存储&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;markdown&nbsp;文件&nbsp;&nbsp;&nbsp;&nbsp;压缩后的文本&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;图DB&nbsp;+&nbsp;向量DB<br>写入触发&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Claude&nbsp;自主判断&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hook&nbsp;自动捕获&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hook&nbsp;自动捕获<br>会话结束&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;啥也不干&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;自动捕获+压缩&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;自动捕获+向量化<br>压缩&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;~200:1&nbsp;压缩率&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;向量化<br>依赖&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bun&nbsp;+&nbsp;uv&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Docker&nbsp;全家桶<br>可靠性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Claude&nbsp;心情&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;自动化,稳定&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;自动化,稳定</code></pre><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">怎么选?别纠结,看项目大小:</p><ul class="ul" style="list-style: circle; padding-left: 1em; margin-left: 0; color: #3f3f3f;"><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">个人项目、小团队</strong>——官方够了。零配置零依赖,能跑就行。</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">中等复杂度</strong>——上 claude-mem。自动捕获 + AI 压缩1 万 token 的会话内容压到约 50 token200:1 的压缩率。靠谱。</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">大型长期项目</strong>——考虑 AutoMem。图数据库做关系推理但得跑 Docker部署成本不低。</li></ul><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><h2 class="h2" data-heading="true" style="display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: #0F4C81; font-size: calc(16px * 1.2); font-weight: bold; text-align: center;">6 条你现在就能用的建议</h2><ol class="ol" style="padding-left: 1em; margin-left: 0; color: #3f3f3f;"><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">1. <strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">MEMORY.md 只当目录用。</strong> 只放链接和一句话摘要。200 行限制逼你这么做,别跟它较劲。</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">2. <strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">按主题建文件,别按时间排。</strong> debugging.md、architecture.md、user-preferences.md。语义组织不是流水账。</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">3. <strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">重要的事主动说“记住”。</strong> “把这个调试结论写到 memory 里”——这句话比什么技巧都靠谱。别等 Claude 自觉,它不会的。</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">4. <strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">每周扫一眼 memory 文件夹。</strong> 打开 <code class="codespan" style="font-size: 90%; color: #d14; background: rgba(27, 31, 35, 0.05); padding: 3px 5px; border-radius: 4px;">~/.claude/projects/</code> 下的 memory 目录过时的删掉。2 分钟的事。旧记忆比没记忆更危险,前面说过了。</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">5. <strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">聊天太长就 /clear。</strong> Context Compaction 会吃记忆,/clear 让记忆重新完整加载。代价是丢失当前会话上下文,但总比 Claude 基于残缺记忆做决策强。</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">6. <strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">不想用可以关。</strong> 环境变量 <code class="codespan" style="font-size: 90%; color: #d14; background: rgba(27, 31, 35, 0.05); padding: 3px 5px; border-radius: 4px;">CLAUDE_CODE_DISABLE_AUTO_MEMORY=1</code>,完事。</li></ol><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><h2 class="h2" data-heading="true" style="display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: #0F4C81; font-size: calc(16px * 1.2); font-weight: bold; text-align: center;">安全:别让记忆变成攻击面</h2><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">2026 年 2 月 26 日The Register 报道了 Claude Code 的安全漏洞CVE攻击者可以在仓库中注入恶意配置文件实现远程代码执行和 API Key 窃取。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">这和记忆系统直接相关。如果有人能操纵你的 MEMORY.md 或 CLAUDE.md就能影响 Claude 的行为——它每次启动都无条件信任这些文件的内容。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">三个基本防护:</p><ul class="ul" style="list-style: circle; padding-left: 1em; margin-left: 0; color: #3f3f3f;"><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">• 定期看看 memory 目录,确认没被注入奇怪指令</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">• 别在 memory 文件里存 API Key、密码</li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;">• clone 陌生仓库后,先看看有没有 CLAUDE.md 或 .claude/ 目录</li></ul><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">这不是吓你。攻击面就在那里。</p><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;"><img src="MDTOHTMLIMGPH_6" data-local-path="/home/kang/apps/content-forge/content-forge/02-drafts/05-assets/claude-code-auto-memory-deep-dive/06-flowchart-memory-lifecycle.png" style="display: block; width: 100%; margin: 1.5em auto;"></p><h2 class="h2" data-heading="true" style="display: table; padding: 0 0.2em; margin: 4em auto 2em; color: #fff; background: #0F4C81; font-size: calc(16px * 1.2); font-weight: bold; text-align: center;">写在最后</h2><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">Auto Memory 的技术实现朴素到令人意外。没有向量数据库,没有 RAG 管线——system prompt + 文件读写,完事。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">但这恰恰是好的工程品味。<strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">用最少的复杂度解决最核心的问题。</strong></p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">不过说到底,<strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">真正的记忆管理责任在你身上。</strong> Auto Memory 给了工具效果取决于你怎么用——MEMORY.md 的索引质量、主题文件的组织方式、定期审查的纪律性。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">记忆系统的本质不是让 AI 变聪明。是让 AI 在正确的上下文中工作。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">这才是 Context Engineering 真正在做的事。</p><p class="p" style="margin: 1.5em 8px; letter-spacing: 0.1em; color: #3f3f3f;">下一篇我打算拆 Agent Teams 的多智能体协作机制——怎么让多个 Claude 同时干活还不打架。点关注不迷路。</p><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><blockquote class="blockquote" style="margin-top: 0; margin-right: 0; margin-left: 0; font-style: normal; padding: 1em; border-left: 4px solid #0F4C81; border-radius: 6px; color: #3f3f3f; background: #f7f7f7; margin-bottom: 1em;"><p class="p" style="display: block; font-size: 1em; letter-spacing: 0.1em; color: #3f3f3f; margin: 0;"><strong style="color: #0F4C81; font-weight: bold; font-size: inherit;">栗子KK</strong>,一个在 AI 浪潮中游泳的 AI 产品 Founder</p><p class="p" style="display: block; font-size: 1em; letter-spacing: 0.1em; color: #3f3f3f; margin: 0;">欢迎点赞、在看、关注,一起聊科技、聊产品、聊未来 🚀</p></blockquote><hr class="hr" style="border-style: solid; border-width: 2px 0 0; border-color: rgba(0, 0, 0, 0.1); -webkit-transform-origin: 0 0; -webkit-transform: scale(1, 0.5); transform-origin: 0 0; transform: scale(1, 0.5); height: 0.4em; margin: 1.5em 0;"><blockquote class="blockquote" style="margin-top: 0; margin-right: 0; margin-left: 0; font-style: normal; padding: 1em; border-left: 4px solid #0F4C81; border-radius: 6px; color: #3f3f3f; background: #f7f7f7; margin-bottom: 1em;"><p class="p" style="display: block; font-size: 1em; letter-spacing: 0.1em; color: #3f3f3f; margin: 0;">参考来源:</p><ul class="ul" style="list-style: circle; padding-left: 1em; margin-left: 0; color: #3f3f3f;"><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://www.anthropic.com/news/claude-opus-4-6" title="Anthropic 官方 Opus 4.6 发布" style="color: #576b95; text-decoration: none;">Anthropic 官方 Opus 4.6 发布</a></li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://claudelog.com/claude-code-changelog/" title="Claude Code Changelog" style="color: #576b95; text-decoration: none;">Claude Code Changelog</a></li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://paddo.dev/blog/quiet-features-opus-4-6/" title="The Quiet Features That Shipped With Opus 4.6" style="color: #576b95; text-decoration: none;">The Quiet Features That Shipped With Opus 4.6</a></li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://www.implicator.ai/claude-codes-quiet-power-play-tooling-not-trophies/" title="Claude Code's quiet power play" style="color: #576b95; text-decoration: none;">Claude Code&#39;s quiet power play</a></li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://hyperdev.matsuoka.com/p/how-claude-code-got-better-by-protecting" title="How Claude Code Got Better by Protecting More Context" style="color: #576b95; text-decoration: none;">How Claude Code Got Better by Protecting More Context</a></li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://www.theregister.com/2026/02/26/clade_code_cves/" title="Claude Code 安全漏洞 - The Register" style="color: #576b95; text-decoration: none;">Claude Code 安全漏洞 - The Register</a></li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://github.com/thedotmack/claude-mem" title="claude-mem GitHub" style="color: #576b95; text-decoration: none;">claude-mem GitHub</a></li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://therealjasoncoleman.com/2026/02/05/giving-claude-code-a-memory-and-a-soul-with-automem/" title="AutoMem" style="color: #576b95; text-decoration: none;">AutoMem</a></li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://www.thenextgentechinsider.com/pulse/anthropic-introduces-auto-memory-system-for-claude-code" title="Anthropic Introduces Auto Memory System" style="color: #576b95; text-decoration: none;">Anthropic Introduces Auto Memory System</a></li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://github.com/anthropics/claude-code/issues/5024" title=".claude.json 膨胀 Issue #5024" style="color: #576b95; text-decoration: none;">.claude.json 膨胀 Issue #5024</a></li><li class="listitem" style="display: block; margin: 0.2em 8px; color: #3f3f3f;"><a href="https://blakecrosley.com/en/blog/context-window-management" title="Context Window Management 实测" style="color: #576b95; text-decoration: none;">Context Window Management 实测</a></li></ul></blockquote>
</section>
</div>
</body>
</html>