内存系统
Claude Code 使用 ~/.claude/ 中基于文件的内存系统在会话之间持久化信息。它使用 4 种类型的内存类别和一个始终加载到上下文中的索引文件(MEMORY.md)。
内存类型
User
· 角色、偏好、知识水平Example: "Is a data scientist, new to React. Explain frontend concepts via backend analogues."
When to save: 当你了解用户的背景、目标或工作风格时。
Feedback
· 纠正和验证的方法Example: "Don't mock the database in tests. A previous incident showed mock/prod divergence breaks migrations."
When to save: 当用户纠正方法或确认非显而易见的选择有效时。
Project
· 正在进行的工作、截止日期、事件Example: "Merge freeze begins 2026-03-05 for mobile release cut. Flag non-critical PRs after that date."
When to save: 当你了解谁在做什么、为什么或何时做时。相对日期转换为绝对日期。
Reference
· 指向外部系统的指针Example: "Pipeline bugs are tracked in Linear project INGEST."
When to save: 当你了解外部工具中的资源(Linear、Grafana、Slack 频道等)时。
文件结构
每个内存存储为带有 YAML 前言的单独 markdown 文件。MEMORY.md 是索引。
~/.claude/projects/<slug>/memory/
├── MEMORY.md # index, max 200 lines / 25KB
├── user_role.md
├── feedback_testing.md
└── reference_tools.md