这不是官方开发仓库,而是一套围绕
claude-code当前源码快照整理出来的中文研究文档。目标是让读者即使不先扎进src/,也能先理解 Claude Code 这套 agent runtime 在做什么。
这个仓库把 Claude Code 拆成一套可连续阅读的研究文档,重点覆盖:
- Claude Code 的启动、执行、权限、工具与状态持久化
- Anthropic 在 prompt、上下文管理、记忆、工具调用、多 agent 协作上的设计取向
- 运行协议、远程接入、灰度控制、hooks、输入系统等容易被忽略但很关键的外围机制
- 记忆、上下文与 agent 运行时里更细的算法、状态机与不变量
边界也很明确:
- 研究对象是当前仓库里可见的
src/实现 - 远程服务、OAuth、真实账号与外部系统联动仍以“需真实环境验证”为准
- 文档中的设计归纳基于源码,不等于 Anthropic 官方表述
Claude Code 可以粗略理解成一套面向软件工程工作流的 agentic CLI:
- src/main.tsx 负责启动与总装配
- src/commands.ts 和 src/tools.ts 分离“用户命令”和“模型可执行动作”
- src/QueryEngine.ts 把 prompt、上下文、工具调用、状态与恢复串成长期工作会话
- src/utils/permissions/permissionSetup.ts 和 plan mode 把安全直接嵌进 agent 工作流
- src/tools/AgentTool/AgentTool.tsx、
tasks、swarm、coordinator把单 agent 扩展为多角色协作系统
flowchart TD
A["入口\nmain.tsx"] --> B["交互层\nApp / REPL / AppState"]
A --> C["命令层\ncommands.ts"]
A --> D["工具层\ntools.ts"]
B --> E["执行层\nQueryEngine"]
C --> E
D --> E
E --> F["上下文与记忆\ncontext / compact / session memory / memory"]
E --> G["权限与策略\npermissions / plan mode / settings / policy"]
D --> H["Agent 运行时\nAgentTool / tasks / lifecycle"]
H --> I["协作层\nswarm / coordinator / teammate"]
A --> J["扩展层\nplugins / skills / MCP / LSP"]
A --> K["远程层\nbridge / remote / server / proxy"]
这套文档现在按 6 个分卷组织,而不是把所有专题平铺在同一层:
- 卷一:认识 Claude Code
- 卷二:Claude Code 如何运行
- 卷三:扩展、远程与协作
- 卷四:记忆与上下文
- 卷五:Anthropic Agent 设计研究
- 卷六:操作、研究与索引
更完整的分卷目录见 docs/README.md。
如果你关心 Claude Code 对不同接入面的限制,以及它具体会上报什么,这两个专题可以直接进入:
- prompt:17. 系统提示词与模型决策
- 上下文:07. QueryEngine 与上下文
- 记忆:21. 记忆系统:CLAUDE.md、Session Memory 与 Agent Memory
- 工具调用:05. 工具系统
- 多 agent:15. Agent 设计理念研究 和 20. Coordinator、Swarm 与 Teammate 协作
- 19. 上下文压缩与历史治理
- 33. Session Memory 调度与并发控制
- 35. CLAUDE.md 加载算法与指令装配
- 39. Forking、子代理与上下文经济学
- 43. Agent 组织学与 Anthropic 的工作模型
| 研究问题 | 主入口 | 延伸入口 |
|---|---|---|
| Anthropic 如何设计 prompt | 17 | 15 |
| Anthropic 如何管理上下文 | 07 | 19 |
| Anthropic 如何做记忆 | 21 | 36 |
| Anthropic 如何做工具调用 | 05 | 08 |
| Anthropic 如何设计 agent 角色 | 15 | 42 |
| fork 和 fresh subagent 有什么区别 | 39 | 43 |
| agent 为什么能 background / resume | 40 | 11 |
| agent 隔离到底隔离了什么 | 41 | 28 |
| Claude Code 如何被外部宿主接管 | 22 | 32 |
| 为什么源码里的功能不一定可见 | 24 | 18 |
| Claude Code 对不同 provider 有哪些明确限制 | 44 | 23 |
| Claude Code 具体会上报什么 | 45 | 24 |
如果你已经有明确问题,最值得先点开的源码入口通常是:
- 启动与装配:src/main.tsx
- 命令系统:src/commands.ts
- 工具系统:src/tools.ts
- 会话核心:src/QueryEngine.ts
- 上下文装配:src/context.ts
- 权限系统:src/utils/permissions/permissionSetup.ts
- agent 运行时:src/tools/AgentTool/AgentTool.tsx
- agent 定义加载:src/tools/AgentTool/loadAgentsDir.ts
- coordinator 模式:src/coordinator/coordinatorMode.ts
首页只负责建立整体方向。完整的分卷结构、全部章节入口和按主题组织的阅读地图在这里:
- 03. 启动与主循环
- 04. 命令系统
- 05. 工具系统
- 06. UI、状态与 REPL
- 07. QueryEngine 与上下文
- 08. 权限与安全控制
- 16. 会话持久化与恢复机制
- 17. 系统提示词与模型决策
- 18. Settings、Policy 与托管配置
- 19. 上下文压缩与历史治理
- 09. 扩展体系:Plugins、Skills、MCP、LSP
- 10. Bridge、Remote 与 IDE 集成
- 11. 子代理与任务系统
- 20. Coordinator、Swarm 与 Teammate 协作
- 22. CLI Structured IO、Control Protocol 与 Transports
- 23. API Client、鉴权与 Provider 路由
- 24. GrowthBook、Analytics 与 Feature Control
- 25. Hooks 与 Runtime Extensibility
- 26. Keybindings 与 Vim 输入状态机
- 27. Output Styles 与 Response Shaping
- 28. Direct Connect、Server 与 Upstream Proxy
- 30. Assistant、Voice 与 Runtime Modes
- 31. Buddy、Git 状态与 Workflow Observability
- 32. Harness 与 Eval Runtime
- 44. Provider 能力限制审计
- 45. Telemetry、Analytics 与上报规则审计
- 21. 记忆系统:CLAUDE.md、Session Memory 与 Agent Memory
- 29. Team Memory Sync 与 Shared Repo Memory
- 33. Session Memory 调度与并发控制
- 34. History Snip、Replay 与 Projected View
- 35. CLAUDE.md 加载算法与指令装配
- 36. Memory Taxonomy 与 Drift 防护
- 37. Agent Memory Snapshot 与 Sync Protocol
- 38. ReadFileState、Context Cache 与 Partial View 机制