Claude Code Source Code Deep Analysis (in pdf)
The articles attached are contributed by NetMind.AI's Algorithm Lead Bin Liang.
After reading through a lot of the existing coverage, he found that most posts stopped at the architecture-summary layer: "40+ tools," "QueryEngine.ts is huge," "there is even a virtual pet." Interesting, sure, but not the kind of material that gives advanced technical readers a real understanding of how Claude Code is actually built.
That is why he took a different approach, not here to repeat the headline facts people already know. These writeups are for readers who want to understand the system at the implementation level: how the architecture is organized, how the security boundaries are enforced, how prompt and context construction really work, and how performance and terminal UX are engineered in practice. he only focused on the parts that become visible when you read the source closely, especially the parts that still have not been clearly explained elsewhere.
The Full Series:
- Architecture — entry points, startup flow, agent loop, tool system, MCP integration, state management
- Security — sandbox, permissions, dangerous patterns, filesystem protection, prompt injection defense
- Prompt System — system prompt construction, CLAUDE.md loading, context injection, token management, cache strategy
- Performance & UX — lazy loading, streaming renderer, cost tracking, Vim mode, keybinding system, voice input
Overall
The core is a streaming agentic loop (query.ts) that starts executing tools while the model is still generating output. There are 40+ built-in tools, a 3-tier multi-agent orchestration system (sub-agents, coordinators, and teams), and workers can run in isolated Git worktrees so they don't step on each other.
- They built a full Vim implementation. Not "Vim-like keybindings." An actual 11-state finite state machine with operators, motions, text objects, dot-repeat, and a persistent register. In a CLI tool. We did not see that coming.
- The terminal UI is a custom React 19 renderer. It's built on Ink but heavily modified with double-buffered rendering, a patch optimizer, and per-frame performance telemetry that tracks yoga layout time, cache hits, and flicker detection. Over 200 components total. They also have a startup profiler that samples 100% of internal users and 0.5% of external users.
- Prompt caching is a first-class engineering problem here. Built-in tools are deliberately sorted as a contiguous prefix before MCP tools, so adding or removing MCP tools doesn't blow up the prompt cache. The system prompt is split at a static/dynamic boundary marker for the same reason. And there are three separate context compression strategies: auto-compact, reactive compact, and history snipping.
- "Undercover Mode" accidentally leaks the next model versions. Anthropic employees use Claude Code to contribute to public open-source repos, and there's a system called Undercover Mode that injects a prompt telling the model to hide its identity. The exact words: "Do not blow your cover." The prompt itself lists exactly what to hide, including unreleased model version numbers opus-4-7 and sonnet-4-8. It also reveals the internal codename system: Tengu (Claude Code itself), Fennec (Opus 4.6), and Numbat (still in testing). The feature designed to prevent leaks ended up being the leak.
A bunch of unreleased features are hidden in feature flags:
- KAIROS — an always-on daemon mode. Claude watches, logs, and proactively acts without waiting for input. 15-second blocking budget so it doesn't get in your way.
- autoDream — a background "dreaming" process that consolidates memory while you're idle. Merges observations, removes contradictions, turns vague notes into verified facts. Yes, it's literally Claude dreaming.
- ULTRAPLAN — offloads complex planning to a remote cloud container running Opus 4.6, gives it up to 30 minutes to think, then "teleports" the result back to your local terminal.
- Buddy — a full Tamagotchi pet system. 18 species, rarity tiers up to 1% legendary, shiny variants, hats, and five stats including CHAOS and SNARK. Claude writes its personality on first hatch. Planned rollout was April 1-7 as a teaser, going live in May.
User-Agent: