Skip to main content

Claude Code Source Tutorial -- Project Overview & Quick Navigation

Background

Claude Code is Anthropic's CLI tool that lets users interact with Claude from the terminal to perform software engineering tasks: editing files, running commands, searching codebases, and coordinating workflows.

This repository is a source snapshot that became publicly accessible on March 31, 2026, through a source map exposure in the npm distribution. It is maintained for educational and security research purposes only.

Tech Stack

CategoryTechnology
RuntimeBun
LanguageTypeScript (strict)
Terminal UIReact + Ink (custom fork)
CLI ParsingCommander.js (extra-typings)
Schema ValidationZod v4
Code Searchripgrep
ProtocolsMCP SDK, LSP
APIAnthropic SDK
TelemetryOpenTelemetry + gRPC
Feature FlagsGrowthBook + bun:bundle compile-time elimination
AuthOAuth 2.0, JWT, macOS Keychain

Scale

  • ~1,900 source files, 512,000+ lines of code
  • Single src/ package structure, no package.json (this snapshot contains source only)
  • 301 directories

Quick Navigation

I want to learn about...ChapterKey Files
Overall architecture01-architecturesrc/ directory structure
How it starts up02-startup-flowentrypoints/cli.tsx, main.tsx
How the agent loop works03-core-loopquery.ts, QueryEngine.ts
How tools are defined and run04-tool-systemTool.ts, tools.ts, services/tools/
How permissions work05-permission-securityutils/permissions/, types/permissions.ts
How system prompt is assembled06-context-promptconstants/prompts.ts, context.ts
How memory works07-memory-systemmemdir/, services/SessionMemory/
How the terminal UI renders08-terminal-uiink/, screens/REPL.tsx, components/
MCP integration09-mcp-integrationservices/mcp/, tools/MCPTool/
Multi-agent coordination10-multi-agenttools/AgentTool/, utils/swarm/
Plugin and skill system11-plugin-skillplugins/, skills/, tools/SkillTool/
API calls and streaming12-api-streamingservices/api/claude.ts, services/api/client.ts
Configuration system13-config-settingsutils/settings/
Context compaction14-compact-context-mgmtservices/compact/
Slash command system15-command-systemcommands.ts, commands/
Design patterns summary16-design-patternsCross-file

Fast Track (~2 hours)

For readers who want to quickly grasp the core mechanisms:

00-overview -> 01-architecture -> 03-core-loop -> 04-tool-system -> 06-context-prompt

This covers the agent's "brain" -- how the loop runs, how tools execute, and how prompts are assembled.

Full Track (~1-2 days)

For systematic, in-depth study, read all 17 documents in order:

00 -> 01 -> 02 -> 03 -> 04 -> 05 -> 06 -> 07 -> 08 -> 09 -> 10 -> 11 -> 12 -> 13 -> 14 -> 15 -> 16

By Interest

  • Agent core: 03 -> 04 -> 05 -> 06
  • Extensibility: 09 -> 10 -> 11 -> 15
  • Engineering practices: 02 -> 12 -> 13 -> 14 -> 16
  • UI implementation: 08

Source Directory Overview

src/
├── main.tsx # Main entry (Commander CLI + Ink rendering)
├── query.ts # Core agent loop
├── QueryEngine.ts # SDK/headless query engine wrapper
├── Tool.ts # Tool type definitions and context
├── tools.ts # Tool registry
├── commands.ts # Command registry
├── context.ts # Context collection (CLAUDE.md, git, etc.)
├── cost-tracker.ts # Token cost tracking

├── entrypoints/ # Entry points (cli.tsx, init.ts, mcp.ts)
├── bootstrap/ # Global bootstrap state
├── screens/ # Full-screen UIs (REPL, Doctor)
├── query/ # Query pipeline helpers (deps, config, stopHooks)

├── tools/ # ~40 tool implementations
├── commands/ # ~50 slash commands
├── components/ # ~140 Ink UI components
├── hooks/ # React hooks
├── ink/ # Ink rendering engine (custom fork)
├── services/ # External service integrations (API, MCP, OAuth, etc.)
├── utils/ # Utilities (permissions, settings, model, etc.)

├── plugins/ # Plugin system
├── skills/ # Skill system
├── bridge/ # IDE bridge
├── memdir/ # Persistent memory directory
├── tasks/ # Task management (sub-agents, teammates)
├── state/ # State management
├── keybindings/ # Keybinding configuration
├── vim/ # Vim mode
├── voice/ # Voice input
├── remote/ # Remote sessions
└── ...

Hands-on Experiments

In addition to reading, we provide 15 Python experiments that let you replicate Claude Code's core design patterns through code.

Experiments support three modes: --mock (offline), --provider anthropic, --provider openai.

Experiment Directory

ExperimentChapterTrack
exp_03 Core Agent Loop03 - Core LoopCore
exp_04 Tool System04 - Tool SystemCore
exp_05 Permission Engine05 - PermissionsCore
exp_06 Prompt Assembly06 - Context/PromptCore
exp_07 Memory System07 - MemoryCore
exp_09 MCP Client09 - MCPCore
exp_10 Multi-Agent10 - Multi-AgentCore
exp_12 Streaming API12 - API/StreamingCore
exp_14 Context Compaction14 - CompactionCore
exp_02 Startup Flow02 - Startup FlowComprehensive
exp_08 Terminal UI08 - Terminal UIComprehensive
exp_11 Plugin/Skill11 - Plugin/SkillComprehensive
exp_13 Config System13 - ConfigComprehensive
exp_15 Command System15 - CommandsComprehensive
exp_16 Design Patterns16 - PatternsComprehensive

See the Experiment Guide for full setup instructions.

Next

Go to 01-architecture.md to understand the overall architecture.