Claude Code Source Analysis — Development skill for Claude Code
Claude Code 泄露源码深度分析 — 基于 2026-03-31 泄露的 Anthropic Claude Code CLI 完整 TypeScript 源码(~1,884 文件,512K+ 行)的逐模块架构解读.
How to install Claude Code Source Analysis
This entry records only its repository, not the path inside it, so there is no
exact command to give. Open catyans/claude-code-source-analysis and copy the folder into
~/.claude/skills/, or the file into ~/.claude/agents/.
What Claude Code Source Analysis does
Claude Code 泄露源码深度分析 — 基于 2026-03-31 泄露的 Anthropic Claude Code CLI 完整 TypeScript 源码(~1,884 文件,512K+ 行)的逐模块架构解读.
Alternatives in Development
- Mcporter — Call MCPs via TypeScript, masquerading as simple TypeScript API 4.1k ★
- Open Agent SDK TypeScript — Agent-SDK without CLI dependencies, as an alternative to claude-agent-sdk, completely open source 2.6k ★
- Dao Code — Open-source TypeScript terminal coding agent for DeepSeek-V4 — builds on DeepSeek's strong price-performance a 1.3k ★
README
Claude Code 源码深度分析
基于 2026-03-31 泄露的 Anthropic Claude Code CLI 完整 TypeScript 源码的逐模块架构解读
**作者**: [Wang Yanshu](https://catyans.github.io)
背景
2026 年 3 月 31 日,Anthropic 的 Claude Code CLI 源码通过 npm 包中未清理的 `.map` 文件泄露,由 [@Fried_rice](https://x.com/Fried_rice) 首先公开。Source Map 文件包含了从编译后代码到原始 TypeScript 源码的完整映射,使得完整源码得以还原。
本项目对还原后的源码进行深度分析,覆盖全部核心子系统。
项目规模
| 指标 | 数值 |
|---|---|
| 文件数 | ~1,884 个 .ts/.tsx |
| 代码行数 | 512,664 行 |
| 运行时 | Bun |
| 语言 | TypeScript (strict) |
| UI 框架 | React + 自定义 Ink 渲染器 |
| CLI 解析 | Commander.js |
| Schema 验证 | Zod v4 |
目录
| # | 章节 | 说明 |
|---|---|---|
| 00 | 总览 | 项目背景、技术栈、目录结构、章节索引 |
| 01 | 启动流程 | 多阶段启动流水线、91 个 CLI 选项、6 种执行模式 |
| 02 | 查询引擎 | Generator 状态机、7 级错误恢复、流式处理、Token 预算 |
| 03 | 工具系统 | Tool 接口 30+ 方法、buildTool 工厂、并发分区策略 |
| 04 | BashTool 详解 | 三层安全防护、23 项安全检查、权限规则匹配 |
| 05 | AgentTool 与多 Agent | Agent 生成、Coordinator 编排、团队管理、消息路由 |
| 06 | 文件与搜索工具 | FileRead/Write/Edit、Glob、Grep、WebFetch 等 9 个工具 |
| 07 | 权限系统 | ResolveOnce 竞态防护、6 路并发竞争、7 种权限模式 |
| 08 | 状态管理 | 150+ 字段 AppState、35 行纯函数 Store、6 个同步点 |
| 09 | 服务层 | 多 Provider API、MCP 协议、5 种上下文压缩策略 |
| 10 | IDE 集成 (Bridge) | V1/V2 双传输路径、JWT 刷新调度、多会话工作窃取 |
| 11 | 记忆系统 | 文件记忆、4 种类型、Sonnet 语义召回、团队记忆 |
| 12 | Skill 与插件系统 | 懒提取、O_EXCL 安全写入、插件热加载 |
| 13 | UI 渲染层 | 自定义 React 终端渲染器、双缓冲、硬件滚动、虚拟滚动 |
| 14 | 命令系统 | 103 个命令、3 种类型、并行加载、可用性过滤 |
| 15 | Feature Flags 与编译优化 | 编译时死代码消除、运行时 GrowthBook、12 次配置迁移 |
| 16 | 数据流与架构模式 | 12 个跨切面设计模式 |
| 17 | 其他子系统 | Vim 状态机、Buddy 彩蛋、语音、远程会话、Server 模式 |
| 18 | 架构设计总结 | 7 大设计原则、性能优化、安全架构分层 |
核心架构一览
┌─────────────┐
│ main.
Related Skills
Learn Real Claude Code
Deep dive into Claude Code source — 512K lines of industrial-grade TypeScript agent architecture
Clio — Claude Code CLI
功能丰富的 Claude Code 开源替代品,在终端中运行。连接 Anthropic API(或任何兼容端点),提供交互式智能编程助手,支持本地工具执行。 46 个源文件,约 9200 行 TypeScript。运行时
Clio — Claude Code CLI Clone
Agentic coding CLI that connects to Anthropic API (or compatible endpoints) to provide a terminal-based Claude
Claude Code Agent SDK TypeScript Tracker
Tracking the update of source code of claude code agent sdk
Claudecode
Open Source ClaudeCode Leaked. Same functionalities as Claude Code by Anthropic. Written in Rust, Ready to use
Claude Code Source Code Leak
Claude Code Snapshot for Research. All original source code is the property of Anthropic.
Related Agents
CLI Explore Agent
Read-only code exploration via Bash + CLI semantic dual-source analysis, with schema-validated structured outp
Claude Code Research Agent
Senior Anthropic researcher specializing in Claude Code CLI - researches latest context window and model avail
Codex Orchestrator
CLI tool for delegating tasks to GPT Codex agents via tmux sessions. Designed for Claude Code orchestration wi