Deep dive into the architecture of Claude Code v2.1.88 — Anthropic's official CLI for Claude.
This repo documents the internal architecture, design patterns, and engineering decisions behind Claude Code CLI. The goal is to learn from a well-engineered, production-grade CLI tool built with TypeScript, React (Ink), and Bun.
| # | Document | Description |
|---|---|---|
| 1 | 整体架构概览 | High-level system architecture and module map |
| 2 | 入口与启动流程 | Boot sequence, fast paths, and startup optimizations |
| 3 | 查询引擎与对话循环 | Core conversation loop, message management, context handling |
| 4 | 工具系统 | Tool abstraction, 40+ built-in tools, permission model |
| 5 | UI 层 | Custom Ink fork, 200+ React components, terminal rendering |
| 6 | 服务层 | MCP, OAuth, compact, analytics, plugin system |
| 7 | 性能与构建 | Startup optimization, feature flags, dead code elimination |
| 8 | 设计模式 | Patterns worth adopting in your own projects |
| # | Document | Description |
|---|---|---|
| 1 | Architecture Overview | High-level system architecture and module map |
| 2 | Entry & Startup | Boot sequence, fast paths, and startup optimizations |
| 3 | Query Engine & Conversation Loop | Core conversation loop, message management, context handling |
| 4 | Tool System | Tool abstraction, 40+ built-in tools, permission model |
| 5 | UI Layer (Ink) | Custom Ink fork, 200+ React components, terminal rendering |
| 6 | Services Layer | MCP, OAuth, compact, analytics, plugin system |
| 7 | Performance & Build | Startup optimization, feature flags, dead code elimination |
| 8 | Key Design Patterns | Patterns worth adopting in your own projects |
- Language: TypeScript
- Runtime: Node.js >= 18, built with Bun
- UI: Ink (React for terminal) — heavily customized fork
- CLI Framework: Commander.js
- Layout: Yoga (Flexbox for terminal)
- Protocol: MCP (Model Context Protocol) for tool extensibility
- ~1900 source files across 50+ modules
- 40+ built-in tools (Bash, FileEdit, Agent, WebFetch, etc.)
- 200+ React components for terminal UI
- Full Vim mode with motions, operators, and text objects
- Voice input support
- Multi-agent coordination (coordinator mode, agent swarms)
Claude Code is one of the most sophisticated terminal applications ever built. It combines:
- A production AI agent loop with tool use and permission control
- A rich terminal UI rivaling desktop apps
- Enterprise-grade auth, policy, and remote management
- Extreme startup performance optimization
There's a lot to learn here regardless of whether you're building AI tools, CLI apps, or complex TypeScript projects.
This analysis is for educational purposes. Claude Code is a product of Anthropic.