2026-04-12 sathwick reverse-engineering-claude-code 摘要
What it is
一篇面向 Claude Code 整体架构的外部二手综述,覆盖启动、query 主循环、工具系统、权限、UI、扩展、上下文管理与多 agent。
Key claims / findings
- 文章把 Claude Code 拆成几层明确分工的模块:入口层、
QueryEngine/query.ts主循环、工具系统、权限系统、终端 UI、会话状态与扩展机制。 - 对主运行时的判断与现有源码笔记基本一致,即
QueryEngine.ts负责会话级编排,query.ts负责 turn loop、流式输出与工具调度。 - 文章强调工具系统是统一接口,涵盖 schema 校验、权限检查、执行逻辑、渲染 hook 与并发分类,这与 AgentTool 解析、query.ts 工具分发链、toolExecution.ts 解析 的主线相吻合。
- 权限系统被描述为多层治理,而不是单点开关,这与 权限系统如何影响 AgentTool 的结论一致。
- 这份材料的额外价值主要在于提供一个“源码阅读地图”,把 Claude Code 放回完整产品面,而不只盯着 subagent 路径。
- 原始抓取被刻意缩短,因此对后半段的 terminal UI、slash commands、skills/plugins/MCP、memory、hooks、voice 等部分,只能当作目录级线索,不能视为已核实结论。
Relevant concepts
- Claude Code 架构总览
- Claude Code 源码阅读路线
- AgentTool 解析
- query.ts 工具分发链
- toolExecution.ts 解析
- 权限系统如何影响 AgentTool
- Task 系统总览
- Remote agent 机制
Verbatim quotes
“Claude Code follows a layered architecture where each layer has clear responsibilities.”
Source:
2026-04-12 sathwick reverse-engineering-claude-code.md
“The article splits the core into:
QueryEngine.tsfor session-level orchestration,query.tsfor the turn loop state machine.”Source:
2026-04-12 sathwick reverse-engineering-claude-code.md
Open questions
- 文章列出的 terminal UI / Yoga / ANSI diff 渲染链,在当前 vault 里还没有对应 walkthrough,是否值得单独补一条源码线。
- skills、plugins、MCP 被称为 extensibility trifecta,但这份截断版原文没有给出足够机制细节,后续应回到源码或重抓全文验证。
- 文中提到 100+ slash commands、memory、hooks、voice、coordinator 等扩展面,哪些属于公开主线,哪些属于实验性或内部 feature,仍不清楚。