v0.2.29 source analysis updated

Deconstructing Claude Code Source

Deep dive into the internals of Anthropic's official CLI tool. From architecture design and Agent loops to terminal rendering — a comprehensive analysis of 1,902+ files and 514k+ lines of TypeScript.

1,902+Source Files
514k+Lines of Code
35Core Modules
agent-loop.ts
1async function runAgentLoop(ctx: Context) {
2 while (true) {
3 // 1. Gather context and tools
4 const tools = await getAvailableTools(ctx);
5
6 // 2. Call Claude API
7 const response = await callClaude(ctx, tools);
8
9 // 3. Handle tool calls or return result
10 if (response.type === 'tool_calls') {
11 await executeTools(ctx, response.calls);
12 } else {
13 return response.text;
14 }
15 }
16}
Architecture

Core Module Breakdown

View full architecture
Deep Dives

Deep Dive Articles

Browse all articles

The Query Engine: The Complete Lifecycle of a Conversation

Deep dive into QueryEngine.ts and query.ts, tracing the full journey of a conversation from user input to final response, and understanding the async-generator-driven streaming query loop

The Tool System: How AI Safely Interacts with the Outside World

Deep dive into Claude Code's 40+ tool system — from type definitions to concurrent execution to the six-layer permission evaluation pipeline, understanding how AI safely operates on the external world

Roadmap

Analysis Roadmap

01
Foundation & Startup
CLI entry, config loading, auth flow
02
Agent Core Loop
Prompt building, API interaction, tool scheduling
03
Tool Library
File operations, Bash execution, AST analysis
04
Terminal UI Rendering
Ink component tree, streaming output, interaction handling