Inside Claude Code
  • Series Home
  • Code Explorer
  1. Inside Claude Code
  • Inside Claude Code
  • Code Explorer
  • I. Overview
    • I.1 — Bird’s Eye Architecture
    • I.2 — End-to-End Workflow
  • II. Agent Harness
    • II.1 — Agent Loop & Query Engine
    • II.2 — Agent SDK & Structured I/O
    • II.3 — Multi-Agent Orchestration
    • II.4 — Plan Mode
  • III. Context Engineering
    • III.1 — Prompt Assembly
    • III.2 — Context Compaction
    • III.3 — Memory Hierarchy
    • III.4 — Hooks & Lifecycle
  • IV. Tools
    • IV.1 — Tool System & Registry
    • IV.2 — Safety & Sandbox
  • V. Invocation
    • V.1 — CLI, Commands & UI
    • V.2 — Auth, Providers & Flags
  • VI. Extensions
    • VI.1 — Model Context Protocol
    • VI.2 — Skills System
    • VI.3 — Plugin Architecture
  • VII. Remote Runtime
    • VII.1 — Remote Runtime & Bridge
  • VIII. Native Runtime
    • VIII.1 — Native Runtime, Voice & Portability
  • IX. Transparency & Trust
    • IX.1 — Transparency & Trust

On this page

  • The Series
    • I. Overview
    • II. Agent Harness
    • III. Context Engineering
    • IV. Tools
    • V. Invocation
    • VI. Extensions
    • VII. Remote Runtime
    • VIII. Native Runtime
    • IX. Transparency & Trust

Inside Claude Code

A deep-dive into the architecture of Anthropic’s AI coding agent

Author: Zhuoran Yang

Post-impressionist illustration of Claude Code's layered architecture

Claude Code is Anthropic’s agentic coding assistant — 512K lines of TypeScript, a React-based terminal UI, approximately 40 tools governed by a three-tier permission system, and ML classifiers that gate every shell command. This series provides a systematic, source-level walkthrough of how it all fits together.

The analysis is based on the v2.1.88 source tree, recovered from a source map that was inadvertently included in the npm package. The full extracted source is available at github.com/Exhen/claude-code-2.1.88.

TipInteractive Code Explorer

Browse all 1,888 source files with enriched descriptions, export maps, and architecture-layer tagging. Open the Code Explorer →

The Series

I. Overview

Part Title Core Insight
I.1 Bird’s Eye Architecture Shared engine, six layers, context engineering as the key differentiator
I.2 End-to-End Workflow Tracing a single query through the entire pipeline, from CLI input to streaming output

II. Agent Harness

Part Title Core Insight
II.1 Agent Loop & Query Engine The agent loop is an async generator — a coroutine that yields streaming events
II.2 Agent SDK & Structured I/O Three entry modes (CLI, SDK, MCP) sharing one agent engine through a data/control plane split
II.3 Multi-Agent Orchestration Sub-agents are fork() for AI — five agent types, subagent prompts, worktree isolation
II.4 Plan Mode Read-only planning with explicit approval gates — separating reasoning from action

III. Context Engineering

Part Title Core Insight
III.1 Prompt Assembly 65+ fragments assembled through a middleware pipeline before the model sees anything
III.2 Context Compaction Context management is cache eviction applied to conversation history
III.3 Memory Hierarchy Five memory tiers from session to team — a cache hierarchy; plus MagicDocs appendix
III.4 Hooks & Lifecycle Over 25 lifecycle events and system reminders that inject real-time state into context

IV. Tools

Part Title Core Insight
IV.1 Tool System & Registry Approximately 40 interchangeable tools behind a uniform interface; plus computer-use appendix
IV.2 Safety & Sandbox Defense in depth — mandatory access control reimagined for AI agents

V. Invocation

Part Title Core Insight
V.1 CLI, Commands & UI A full React app in a TTY; plus prompt suggestion, speculation, tips, buddy, and installer appendices
V.2 Auth, Providers & Flags OAuth for terminal apps and feature flags enabling continuous delivery

VI. Extensions

Part Title Core Insight
VI.1 Model Context Protocol The LSP of AI agents — a universal tool protocol that turns \(N \times M\) into \(N + M\)
VI.2 Skills System Expertise injection, not capability extension
VI.3 Plugin Architecture Six extension points composed into a customizable platform

VII. Remote Runtime

Part Title Core Insight
VII.1 Remote Runtime & Bridge The terminal is just one frontend — bridge, remote sessions, and transport abstractions

VIII. Native Runtime

Part Title Core Insight
VIII.1 Native Runtime, Voice, and Portability Native N-API modules, vendor bindings, voice pipeline, and platform-specific fallback engineering

IX. Transparency & Trust

Part Title Core Insight
IX.1 Transparency & Trust Invisible tokens, remote feature flags, opt-out telemetry, enterprise control plane, and silent history rewriting

Analysis based on Claude Code v2.1.88 (March 2026). All code snippets are reconstructed from the source map for educational purposes. The full extracted source is available at github.com/Exhen/claude-code-2.1.88.

Code Explorer