All Articles

Deep Dive Articles

Guided walkthroughs of Claude Code's architecture and internals.

The Big Picture: How a 512,000-Line AI CLI Is Built

Starting from the leak, we take our first look inside Claude Code's massive codebase and build a complete mental model from the CLI entry point to the LLM engine

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

The Streaming Tool Executor: How to Safely Let AI Operate Multiple Tools Simultaneously

Deep dive into StreamingToolExecutor's concurrency model — isConcurrencySafe declarations, queue scheduling, Sibling Abort cascading cancellation, progress buffering and ordered emission

The Permission System: Walking the Tightrope Between Autonomy and Safety

A deep dive into Claude Code's multi-layered permission evaluation — from Hook pre-screening to automated classifiers to rule matching, understanding the engineering behind AI tool safety

Context Management: When Even a Million Tokens Aren't Enough

A deep dive into Claude Code's context compression strategies — from token estimation to reactive compaction to tool summaries, understanding the engineering of context management in long conversations

Startup Performance: How a Heavy CLI Achieves Fast Cold Starts

A deep dive into Claude Code's startup optimization — parallel prefetching, compile-time dead code elimination, dynamic lazy loading, performance profiling, and understanding cold start engineering for large CLIs

Multi-Agent Orchestration: How the Coordinator Pattern Enables AI Collaboration

A deep dive into Claude Code's multi-agent architecture — Coordinator/Worker role separation, AgentTool spawning mechanics, task notifications, Scratchpad sharing, and Team swarm mode

Persistent Memory: How AI Remembers You Across Sessions

A deep dive into Claude Code's memory system — MEMORY.md indexing, four memory types, automatic extraction, memory injection and deduplication, and team memory sync

Bridge System: Bidirectional Communication Architecture Between CLI and IDE

A deep dive into Claude Code's Bridge system — bidirectional communication between CLI and IDE extensions, JWT authentication, session management, and capacity wake mechanisms

MCP Protocol Integration: How AI Tools Connect to Everything

A deep dive into Claude Code's MCP integration — Server lifecycle management, dynamic tool generation, Resource/Prompt support, and inter-Agent Server inheritance

Plugins and Skills: A Three-Layer Extensibility Architecture

A deep dive into Claude Code's extensibility design — Skill Markdown frontmatter configuration, Plugin two-tier registration, MCP Server dynamic loading, and how all three layers are unified

OAuth and Authentication: The Full Pipeline from Keychain to Token Refresh

A deep dive into Claude Code's authentication architecture — API Keys, OAuth 2.0, JWT, macOS Keychain integration, and token refresh scheduling

Terminal UI Framework: Building a CLI with React

A deep dive into Claude Code's React/Ink terminal UI — the rendering pipeline, 140+ component architecture, Markdown terminal rendering, live progress, and permission dialogs

Keybindings and Vim Mode: Editor-Level Interaction in a CLI

A deep dive into Claude Code's keybinding system and Vim mode — custom shortcuts, chord combinations, exhaustive type-driven state machine, and modal editing in TypeScript

Screen System: Designing Fullscreen Interaction Modes

A deep dive into Claude Code's fullscreen system — Doctor diagnostics, Resume session recovery, the REPL screen, and the switching mechanism between conversation and fullscreen modes

State Management: React State Architecture Without Redux

A deep dive into Claude Code's minimalist state management -- a custom Store in under 35 lines, Object.is change detection, and fine-grained subscriptions

Telemetry and Observability: OpenTelemetry in a CLI Application

A deep dive into Claude Code's telemetry architecture -- OpenTelemetry lazy loading, performance profiling, GrowthBook feature flags, and privacy considerations

Configuration System: Schema Validation, Migrations, and Multi-Source Merging

A deep dive into Claude Code's configuration architecture -- Zod schemas, multi-source priority merging, versioned migrations, and remote managed settings

Feature Flags and Conditional Compilation: The Art of Compile-Time Code Elimination

A deep dive into Bun's compile-time feature flags -- the feature() API, dead code elimination, and criteria for choosing runtime vs compile-time flags

The File Operations Trio: Design Philosophy of Read, Write, and Edit

A deep dive into Claude Code's file operation tools — the three-tool separation design decision, multi-format reading, precise replacement model, and permission differences

BashTool: Letting AI Safely Execute Shell Commands

A deep dive into BashTool's secure execution architecture — sandbox mechanisms, command classification, timeout management, AbortSignal integration, and background execution

The Search System: The Glob + Grep + Full-Text Search Combination

A deep dive into Claude Code's search tool combination — GlobTool pattern matching, GrepTool ripgrep integration, and ToolSearchTool deferred discovery

Web Tools: How AI Accesses the Internet

A deep dive into Claude Code's network access tools — WebFetchTool content retrieval, WebSearchTool search, proxy configuration, and security considerations

LSP Integration: How Language Server Protocol Enhances AI Coding

A deep dive into Claude Code's LSP integration — providing type information and diagnostics to AI, not IDE features for humans

The Buddy System: A Virtual Pet Game Inside Your Codebase

A deep dive into Claude Code's Buddy easter egg — deterministic RNG, Mulberry32 PRNG, rarity-weighted distributions, Bones vs Soul

The Output Style System: Bringing Brand Identity to Terminal Output

A deep dive into Claude Code's output styles — theme system, Markdown terminal rendering, syntax highlighting, and brand consistency

Remote Execution and Scheduled Triggers: The Headless AI Agent

A deep dive into Claude Code's remote capabilities — remote sessions, Server mode, Cron scheduled tasks, RemoteTrigger, and SDK headless mode

Session Management: Interruption, Resumption, and Sharing

Deep dive into Claude Code's session persistence — disk storage, /resume recovery, Teleport cross-device migration, /share sharing

API Client: Deep Integration with the Anthropic API

Deep dive into Claude Code's API client — streaming response handling, model selection and fallback, Beta APIs, token counting and cost tracking, retry logic

Error Handling and Self-Healing: How AI Recovers from Failures

Deep dive into Claude Code's error recovery mechanisms — query.ts recovery state machine, tool failure handling, network retries, user interruption, /doctor self-diagnostics