Content
<div align="center">
# Tool List
**1884 TypeScript files · 512K+ lines of code · 18 core modules · Systematic architecture analysis**
[](https://jiahp0920.github.io/claude-origin-study/)
[]()
[]()
</div>
---
> **[Click here to read the full document online →](https://jiahp0920.github.io/claude-origin-study/)**
>
> Dark theme · Sidebar navigation · Architecture diagrams · Data flow · Flowcharts · Search
## What is this?
A systematic architecture analysis of the Claude Code CLI open-source code. A module-by-module breakdown of how Anthropic's AI programming assistant is designed and implemented - from when you input `claude` to when it helps you write code, what engineering decisions and architectural trade-offs are made.
## Analysis Module Overview
| # | Module | Problem solved | Core design |
|---|------|------------|---------|
| 1 | [Startup Link](https://jiahp0920.github.io/claude-origin-study/00-startup.html) | Authentication, environment detection, configuration loading | Progressive initialization pipeline |
| 2 | [Query Loop](https://jiahp0920.github.io/claude-origin-study/01-query-loop.html) | Multi-round dialogue engine between model and tools | AsyncGenerator + read-write separation concurrency |
| 3 | [Tool Dispatch](https://jiahp0920.github.io/claude-origin-study/02-tool-dispatch.html) | Translating model intent into actual operations | Tool abstraction + MCP extension + concurrency control |
| 4 | [Permission System](https://jiahp0920.github.io/claude-origin-study/03-permissions.html) | Controlling tool execution security | 13-step decision chain + allow/deny/ask |
| 5 | [Risk Control and Security Hardening](https://jiahp0920.github.io/claude-origin-study/03b-security-hardening.html) | Depth defense against Prompt injection | 15-layer security defense |
| 6 | [Agent Architecture](https://jiahp0920.github.io/claude-origin-study/04-agent-arch.html) | Multi-Agent collaboration to execute complex tasks | 5 operation modes + message passing |
| 7 | [MCP System](https://jiahp0920.github.io/claude-origin-study/05-mcp.html) | Third-party tool extension protocol | App Store-style plugin ecosystem |
| 8 | [Context Management](https://jiahp0920.github.io/claude-origin-study/06-context-mgmt.html) | Token window management | 4-layer compression strategy |
| 9 | [Plugin System](https://jiahp0920.github.io/claude-origin-study/07-plugins.html) | User-state extension framework | Market + skills + hot loading |
| 10 | [Command System](https://jiahp0920.github.io/claude-origin-study/08-commands.html) | Slash command interaction | 70+ commands + multiple sources |
| 11 | [UI Interaction Layer](https://jiahp0920.github.io/claude-origin-study/09-ui.html) | Terminal interface rendering | React + Ink + Yoga layout |
| 12 | [Service Layer](https://jiahp0920.github.io/claude-origin-study/10-services.html) | Background asynchronous service | fail-open + GrowthBook |
| 13 | [Hook Mechanism](https://jiahp0920.github.io/claude-origin-study/11-hooks.html) | Lifecycle interception | Pre/Post hooks + React Hooks |
| 14 | [External Integration](https://jiahp0920.github.io/claude-origin-study/12-external.html) | Shell/Git/browser/voice | Zero-subprocess Git cache |
| 15 | [Configuration and Migration](https://jiahp0920.github.io/claude-origin-study/13-config.html) | User preference management | 5-layer configuration hierarchy + Zod validation |
| 16 | [Native Capabilities](https://jiahp0920.github.io/claude-origin-study/14-native.html) | High-performance rendering/search/layout | Rust→TS full rewrite |
| 17 | [Cost and Limiting](https://jiahp0920.github.io/claude-origin-study/15-cost-limits.html) | Token budget and cost control | Real-time statistics + graceful degradation |
| 18 | [Anti-Distillation and Output Protection](https://jiahp0920.github.io/claude-origin-study/16-anti-distillation.html) | Preventing output from being used for training competing products | 7-layer depth defense |
| 19 | [Buddy Pet System](https://jiahp0920.github.io/claude-origin-study/17-buddy.html) | Terminal virtual pet | Deterministic generation + ASCII animation |
| 20 | [Telemetry and User Profiling](https://jiahp0920.github.io/claude-origin-study/18-telemetry.html) | Multi-pipeline data collection and analysis | Datadog + BigQuery + GrowthBook |
## Flowcharts
| Flowchart | Description |
|--------|------|
| [Query Lifecycle](https://jiahp0920.github.io/claude-origin-study/flows/query-lifecycle.html) | Complete process from user input to task completion |
| [Tool Execution Process](https://jiahp0920.github.io/claude-origin-study/flows/tool-execution.html) | Permission check and concurrent execution of tool calls |
| [Agent Collaboration Process](https://jiahp0920.github.io/claude-origin-study/flows/agent-collab.html) | Multi-Agent task splitting and result aggregation |
## Why read this?
### Visualization - At a glance
The first systematic analysis project to visualize the Claude Code from a **visualization perspective**. Not just posting source code with comments, but using layered architecture diagrams, data flow diagrams, and topology diagrams to illustrate the internal structure of each module - **you can understand the design intent by looking at the diagrams, without needing to read 512K lines of source code**.
### Depth - Not just surface-level
Each module is analyzed in-depth to **function-level implementation details**: key algorithm source code snippets, complete decision-making chains, concurrency control mechanisms, and security defense layer-by-layer breakdowns. Not just a general introduction of "what this module does", but an analysis of "why it's designed this way, and what problems would arise if it were designed differently".
### Practical value - Directly applicable
Each module comes with **vertical Agent practice reference**: mapping CC's design patterns to specific business scenarios (like customer service Agent), providing actionable code examples and a "must-copy vs don't need to copy" checklist. Not just admiring the design, but knowing how to apply it.
## Who should read this?
| Role | What you'll gain |
|------|-----------|
| **Architect / Tech Lead** | AI Agent system architecture paradigm: multi-Agent collaboration, tool dispatch, context management, and security defense engineering implementation |
| **AI Application Developer** | MCP plugin development, Prompt orchestration, streaming output, and concurrency control implementation reference |
| **Agent Product Manager** | Understanding what Agent can and can't do, technical boundary awareness for better product decisions |
| **Security Engineer** | 15-layer depth defense system, 7-layer protection against distillation, and Prompt injection defense practices |
| **Front-end Engineer** | Terminal UI (React + Ink), virtual list, Yoga layout, and ANSI rendering implementation |
| **Anyone interested in AI Agent** | Quickly understanding a production-level AI Agent through visualization |
## Search Keywords
`Claude Code` `source code analysis` `architecture analysis` `Anthropic` `AI Agent` `CLI` `MCP` `Model Context Protocol` `tool dispatch` `permission system` `context management` `anti-distillation` `Prompt injection defense` `multi-Agent collaboration` `Agent architecture` `vertical Agent` `TypeScript` `LLM application` `AI programming assistant` `terminal UI` `Zod configuration validation` `GrowthBook A/B testing` `Datadog monitoring` `OpenTelemetry` `concurrency control` `read-write separation` `streaming output` `sandbox isolation` `OAuth authentication`
## Disclaimer
This document is for technical learning and architecture analysis purposes only. The source code analysis is based on publicly leaked code, and all trademarks and copyrights belong to Anthropic. No commercial use is allowed without authorization.
Connection Info
You Might Also Like
everything-claude-code
Complete Claude Code configuration collection - agents, skills, hooks,...
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
cc-switch
All-in-One Assistant for Claude Code, Codex & Gemini CLI across platforms.
servers
Model Context Protocol Servers
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.