记忆 · CLAUDE.md 是项目的长期记忆Memory · CLAUDE.md Is the Project's Long-Term Memory.
同一件事你跟它说了十遍:用这个包管理器、按这个风格、别碰那个目录、跑测试用这条命令。模型不跨会话记事 —— 但 CLAUDE.md 会。它是每次开工自动加载的项目长期记忆,分项目级、用户级、企业级三层,还能用 @import 把别的文件拼进来。这一章讲什么该钉进去、什么不该(它不是文档垃圾场),三层怎么分工,以及为什么一份写得好的 CLAUDE.md,比你换一个更强的模型更能改善它干活的质量。You've told it the same thing ten times: use this package manager, follow this style, don't touch that directory, run tests with this command. Models don't remember across sessions — CLAUDE.md does. It's the project's long-term memory, loaded automatically each session, in three tiers (project, user, enterprise), and it can pull in other files with @import. What belongs in it and what doesn't (it's not a dumping ground), how the tiers divide, and why a well-written CLAUDE.md improves the quality of its work more than switching to a stronger model.
8 分钟 · 初稿 2026.078 Min · Drafted 2026.07
用这个包管理器,不是那个。测试要跑 npm test 不是 npx jest。migrations 目录别碰。—— 这些话你跟它说过十遍,因为模型不跨会话记事,每个新会话都是一张白纸。CLAUDE.md 就是治这个的:一份每次开工自动进入它脑子的文件。这一章讲什么该钉进去、钉在哪一层,以及一条容易被高估的边界:记忆是请求,不是规矩。Use this package manager, not that one. Tests run with npm test, not npx jest. Don't touch the migrations directory. — You've said these ten times, because models don't remember across sessions; every new session is a blank page. CLAUDE.md is the cure: a file that enters its head automatically at every start. This chapter covers what to pin, at which layer — and one boundary that's easy to overrate: memory is a request, not a rule.
— I
放哪:四层记忆,各管一摊Where It Lives: Four Layers, Each with Its Beat.
CLAUDE.md 是普通的 markdown,特殊在于加载时机:每个会话开始,Claude 自动读它 —— 不用你贴、不用你提。1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17.起点不用手写:跑一次 /init,它会分析你的代码库,把探出来的构建命令、测试方式、项目惯例生成一份初稿;已经有 CLAUDE.md 的话,它提改进而不是覆盖。1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17.之后的问题只剩一个:哪句话放哪一层。CLAUDE.md is ordinary markdown; what's special is when it loads: at the start of every session, Claude reads it — nothing to paste, nothing to mention.1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17. Don't write the first draft by hand: run /init once and it analyzes your codebase into a starter — build commands, test setup, conventions it discovered; if a CLAUDE.md exists, it proposes improvements instead of overwriting.1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17. After that, one question remains: which line goes on which layer.
层级Layer
位置Location
放什么What goes here
组织Organization
managed policy(IT 下发)Managed policy (IT-deployed)
全公司的编码与合规规范Company-wide coding and compliance rules
用户User
~/.claude/CLAUDE.md
你个人的偏好,跟你走所有项目Personal preferences that follow you everywhere
项目Project
./CLAUDE.md
团队共享:命令、架构、惯例,进版本库Team-shared: commands, architecture, conventions — in version control
项目 · 个人Project · personal
CLAUDE.local.md
你的沙盒地址、测试数据,进 .gitignoreYour sandbox URLs and test data — gitignored
四层叠加生效,不互相覆盖。1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17.文件长了还有两个泄压阀:@path 语法把别的文件拼进来(比如 @docs/git-instructions.md,最多递归 4 层);.claude/rules/ 目录把规则拆成多个主题文件,还能用 paths 限定 —— 只在 Claude 碰到匹配文件时才加载,不白占上下文。1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17.The layers stack; none overrides another.1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17. When a file grows, two relief valves: the @path syntax splices other files in (say @docs/git-instructions.md, up to 4 hops), and the .claude/rules/ directory splits rules into topic files that can be scoped with paths — loading only when Claude touches matching files, costing no idle context.1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17.
— II
写什么:一行一个否决问题What to Write: One Veto Question per Line.
CLAUDE.md 的敌人不是太短,是太长:它整份进入每次会话的上下文,臃肿的文件会让真正要紧的规则被淹没 —— 官方直说,写得太满,Claude 反而开始忽略你的指令。2注 2Note 2Claude Code Docs · Best practices —— 写 CLAUDE.md 的取舍表:收录它猜不到的构建命令、和默认不同的风格规则、测试跑法、仓库礼仪、项目特有的架构决定与坑;排除读代码就能推断的、语言通识、频繁变动的信息、逐文件的代码库描述。每一行问一句「删掉它会不会导致出错」,不会就删;臃肿的 CLAUDE.md 会让真正的规则被忽略。截至 2026-07-17。Claude Code Docs · Best practices — the CLAUDE.md include/exclude table: include build commands it can't guess, style rules that differ from defaults, how to run tests, repository etiquette, project-specific architecture decisions and gotchas; exclude what reading the code reveals, standard language conventions, fast-changing information, file-by-file codebase descriptions. Ask of every line 'would removing this cause mistakes' — if not, cut it; a bloated CLAUDE.md gets your real rules ignored. As of 2026-07-17.纪律是对每一行问同一个问题:删掉这行,它会不会因此犯错?不会,就删。2注 2Note 2Claude Code Docs · Best practices —— 写 CLAUDE.md 的取舍表:收录它猜不到的构建命令、和默认不同的风格规则、测试跑法、仓库礼仪、项目特有的架构决定与坑;排除读代码就能推断的、语言通识、频繁变动的信息、逐文件的代码库描述。每一行问一句「删掉它会不会导致出错」,不会就删;臃肿的 CLAUDE.md 会让真正的规则被忽略。截至 2026-07-17。Claude Code Docs · Best practices — the CLAUDE.md include/exclude table: include build commands it can't guess, style rules that differ from defaults, how to run tests, repository etiquette, project-specific architecture decisions and gotchas; exclude what reading the code reveals, standard language conventions, fast-changing information, file-by-file codebase descriptions. Ask of every line 'would removing this cause mistakes' — if not, cut it; a bloated CLAUDE.md gets your real rules ignored. As of 2026-07-17.CLAUDE.md's enemy isn't brevity, it's length: the whole file enters every session's context, and a bloated one drowns the rules that matter — the docs say it plainly: overstuffed files get your instructions ignored.2注 2Note 2Claude Code Docs · Best practices —— 写 CLAUDE.md 的取舍表:收录它猜不到的构建命令、和默认不同的风格规则、测试跑法、仓库礼仪、项目特有的架构决定与坑;排除读代码就能推断的、语言通识、频繁变动的信息、逐文件的代码库描述。每一行问一句「删掉它会不会导致出错」,不会就删;臃肿的 CLAUDE.md 会让真正的规则被忽略。截至 2026-07-17。Claude Code Docs · Best practices — the CLAUDE.md include/exclude table: include build commands it can't guess, style rules that differ from defaults, how to run tests, repository etiquette, project-specific architecture decisions and gotchas; exclude what reading the code reveals, standard language conventions, fast-changing information, file-by-file codebase descriptions. Ask of every line 'would removing this cause mistakes' — if not, cut it; a bloated CLAUDE.md gets your real rules ignored. As of 2026-07-17. The discipline is one question per line: would removing this cause a mistake? If not, cut it.2注 2Note 2Claude Code Docs · Best practices —— 写 CLAUDE.md 的取舍表:收录它猜不到的构建命令、和默认不同的风格规则、测试跑法、仓库礼仪、项目特有的架构决定与坑;排除读代码就能推断的、语言通识、频繁变动的信息、逐文件的代码库描述。每一行问一句「删掉它会不会导致出错」,不会就删;臃肿的 CLAUDE.md 会让真正的规则被忽略。截至 2026-07-17。Claude Code Docs · Best practices — the CLAUDE.md include/exclude table: include build commands it can't guess, style rules that differ from defaults, how to run tests, repository etiquette, project-specific architecture decisions and gotchas; exclude what reading the code reveals, standard language conventions, fast-changing information, file-by-file codebase descriptions. Ask of every line 'would removing this cause mistakes' — if not, cut it; a bloated CLAUDE.md gets your real rules ignored. As of 2026-07-17.
值得一行Worth a line
不值得Not worth one
它猜不到的构建 / 测试命令Build / test commands it can't guess
什么时候写?用第 1 章那张触发表里的第一条:同一个错误出现第二次,就是写一行的时候。3注 3Note 3Claude Code Docs · Extend Claude Code —— 各扩展机制的触发时机:同一个约定或命令错第二次,写进 CLAUDE.md;反复粘贴的多步流程,做成 skill;必须每次发生的,写 hook。截至 2026-07-17。Claude Code Docs · Extend Claude Code — when each mechanism earns its place: a convention or command gotten wrong twice goes into CLAUDE.md; a multi-step procedure you keep pasting becomes a skill; what must happen every time becomes a hook. As of 2026-07-17.什么时候搬走?一段记忆长成了多步流程,它就不该住在这里 —— 那是 skill 的形状(第 4 章);只对某个目录有效的规则,搬进带 paths 的 rules 文件。1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17.200 行是个好的警戒线。1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17.When to write? The first trigger from chapter 1's table: the second time the same mistake appears, it's time for a line.3注 3Note 3Claude Code Docs · Extend Claude Code —— 各扩展机制的触发时机:同一个约定或命令错第二次,写进 CLAUDE.md;反复粘贴的多步流程,做成 skill;必须每次发生的,写 hook。截至 2026-07-17。Claude Code Docs · Extend Claude Code — when each mechanism earns its place: a convention or command gotten wrong twice goes into CLAUDE.md; a multi-step procedure you keep pasting becomes a skill; what must happen every time becomes a hook. As of 2026-07-17. When to move out? A memory that has grown into a multi-step procedure no longer belongs here — that's the shape of a skill (chapter 4); a rule that only applies to one directory moves into a paths-scoped rules file.1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17. Two hundred lines is a good tripwire.1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17.
— III
记忆是请求,不是规矩Memory Is a Request, Not a Rule.
把预期校准准确:文档对 CLAUDE.md 的定性是「上下文,不是强制配置」—— 它读了、大概率照做,但没有任何机制保证。1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17.所以「提交前必须跑 lint」写在这里是叮嘱,写成 hook 才是闸门(第 7 章);「绝不许碰 .env」想要硬拦,用 PreToolUse hook,不是加粗字体。分层记忆负责让它懂你的项目,hooks 负责让它越不过线 —— 两件事,别用一个工具硬扛。Calibrate expectations precisely: the docs classify CLAUDE.md as 'context, not enforced configuration' — it reads it, very likely follows it, and nothing guarantees it.1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17. So 'run lint before committing' written here is a reminder; written as a hook it's a gate (chapter 7). To truly stop it touching .env, use a PreToolUse hook, not bold text. Memory's job is making it understand your project; hooks' job is making the line uncrossable — two jobs, one tool won't carry both.还有两个容易踩的时间差。其一:CLAUDE.md 在会话开始读入内存,中途改了不生效 —— 新内容要等下次 /clear、/compact 或重启才加载。4注 4Note 4Claude Code Docs · How Claude Code uses prompt caching —— 项目根与用户级 CLAUDE.md 在会话开始读入内存,中途编辑不废缓存、但也不生效,下次 /clear、/compact 或重启才加载新内容。截至 2026-07-17。Claude Code Docs · How Claude Code uses prompt caching — project-root and user-level CLAUDE.md are read once at session start and held in memory; a mid-session edit doesn't invalidate the cache, but doesn't apply either — the new content loads on the next /clear, /compact, or restart. As of 2026-07-17.改完发现它还按旧规矩走,不是它叛逆,是你还没翻页。其二:除了你写的记忆,它也在自己记 —— auto memory 默认开启,构建命令、调试心得这类「下次会用上」的东西被它写进 ~/.claude/projects/ 下的项目记忆目录,每次会话带上索引。1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17.用 /memory 能看到两套记忆的全部文件:定期翻一翻,删掉过时的 —— 记忆也会腐烂,烂记忆比没记忆更误事。Two timing traps as well. First: CLAUDE.md is read into memory at session start, and a mid-session edit does not apply — new content waits for the next /clear, /compact, or restart.4注 4Note 4Claude Code Docs · How Claude Code uses prompt caching —— 项目根与用户级 CLAUDE.md 在会话开始读入内存,中途编辑不废缓存、但也不生效,下次 /clear、/compact 或重启才加载新内容。截至 2026-07-17。Claude Code Docs · How Claude Code uses prompt caching — project-root and user-level CLAUDE.md are read once at session start and held in memory; a mid-session edit doesn't invalidate the cache, but doesn't apply either — the new content loads on the next /clear, /compact, or restart. As of 2026-07-17. If it keeps following the old rule after your edit, it isn't rebelling; you haven't turned the page. Second: beyond what you write, it takes notes of its own — auto memory is on by default, filing build commands and debugging insights it expects to reuse into the project's memory directory under ~/.claude/projects/, with an index loaded each session.1注 1Note 1Claude Code Docs · Memory —— CLAUDE.md 每次会话开始加载;位置分四级:组织(managed policy,IT 统一下发)、用户(~/.claude/CLAUDE.md,你的全部项目)、项目(./CLAUDE.md 或 ./.claude/CLAUDE.md,随版本库共享)、项目个人(CLAUDE.local.md,加进 .gitignore);@path 导入其他文件,最多递归 4 层;.claude/rules/ 可按路径限定加载;建议单文件 200 行以内,过长反而降低遵循度;/init 自动生成起点;明确一句「context, not enforced configuration」—— 要硬拦用 PreToolUse hook。auto memory:Claude 自己跨会话记笔记,存于 ~/.claude/projects/<项目>/memory/,MEMORY.md 索引每次加载前 200 行或 25KB,/memory 可查看、编辑、关闭。截至 2026-07-17。Claude Code Docs · Memory — CLAUDE.md loads at the start of every session; four locations: organization (managed policy, deployed by IT), user (~/.claude/CLAUDE.md, all your projects), project (./CLAUDE.md or ./.claude/CLAUDE.md, shared via version control), and project-personal (CLAUDE.local.md, gitignored); @path imports other files up to 4 hops; .claude/rules/ can scope rules to file paths; keep a file under ~200 lines — longer reduces adherence; /init generates a starting point; and the explicit line 'context, not enforced configuration' — to hard-block, use a PreToolUse hook. Auto memory: Claude takes its own cross-session notes under ~/.claude/projects/<project>/memory/, with MEMORY.md's first 200 lines or 25KB loaded as an index; /memory views, edits, or turns it off. As of 2026-07-17./memory shows every file of both memories: browse it periodically and delete what's stale — memory rots too, and rotten memory misleads worse than none.动手 · 给你的项目铺第一层记忆:Hands-on · lay your project's first layer of memory:
跑一次 /init;已有 CLAUDE.md 就让它提改进,逐条批。Run /init once; with an existing CLAUDE.md, have it propose improvements and approve line by line.
回想最近两周你重复交代过两次以上的话,各压成一行写进去。Recall what you've explained more than twice in two weeks, and compress each into one line.
用「删掉会不会出错」的尺子删掉三行 —— 减法和加法一样重要。Apply the would-removing-this-cause-mistakes test and cut three lines — subtraction matters as much as addition.
同一句话说第三遍之前,
把它变成一行记忆.
Before you say it a third time,
make it one line of memory.
Aklman Library
— 讨论Discussion
讨论Discussion.
评论区初始化中…Initializing comments…
01 / 01
没有匹配结果No matches.
换个关键词,或按 Esc 回到页面Try another keyword, or press Esc to return