claude-code 源码解读-整体架构、目录 袁旭佳(Aaron) 2026-04-01 AI, claude code claude-code 源码解读-整体架构、目录 文件结构123456789101112131415161718┌─────────────────────────────────────────────────────────────────────────┐│ main.tsx 入口流程 │└─────────────────────────────────────────────────────────────────────────┘ │ ┌───────────────────────────┼───────────────────────────┐ ▼ ▼ ▼┌───────────────┐ ┌───────────────┐ ┌───────────────┐│ 启动预检 │ │ 命令行解析 │ │ 初始化系统 ││ (行 1-20) │ │ (行 900+) │ │ (行 2500+) │└───────────────┘ └───────────────┘ └───────────────┘ │ │ │ ▼ ▼ ▼┌───────────────┐ ┌───────────────┐ ┌───────────────┐│ profileCheck │ │ Commander.js │ │ AppState ││ startMdmRaw │ │ .hook() │ │ launchRepl() ││ startKeychain │ │ .option() │ │ ││ Prefetch │ │ .command() │ │ │└───────────────┘ └───────────────┘ └───────────────┘ 主流程123456789101112131415161718192021222324252627CLI 输入 (args) │ ▼program.parse() ─────────────────────┐ │ │ ▼ ▼preAction hook ┌─────────────────────┐ │ │ 继续对话 (--continue)│ ▼ │ 直接连接 (connect) │┌──────────────┐ │ SSH 远程 (ssh) ││ 解析选项 │ │ Resume ││ - model │ └──────────┬──────────┘│ - effort │ ││ - task-budget│ ▼│ - debug │ ┌─────────────────────┐└──────────────┘ │ launchRepl() │ │ └──────────┬──────────┘ ▼ │┌──────────────┐ ▼│ 构建 State │ ┌─────────────────────┐│ - context │ │ REPL 循环 ││ - tools │ │ (交互式对话) ││ - commands │ └─────────────────────┘└──────────────┘ │ ▼launchRepl() 项目目录数123456789101112131415161718192021222324252627282930313233343536.├── assistant├── bootstrap├── bridge├── buddy├── cli├── commands├── components├── constants├── context├── coordinator├── entrypoints├── hooks├── ink├── keybindings├── memdir├── migrations├── moreright├── native-ts├── outputStyles├── plugins├── query├── remote├── schemas├── screens├── server├── services├── skills├── state├── tasks├── tools├── types├── upstreamproxy├── utils├── vim└── voice