Anthropic's Accidental Claude Code Leak Reveals Only 1.6% is AI Logic
Researchers reverse-engineered Claude Code's 512K-line TypeScript codebase and found that only 1.6% is AI logic — the rest is a fortress of deterministic infrastructure built to manage the model
ProTakeaways
- Researchers analyzed Claude Code's accidentally leaked 512K-line TypeScript codebase and found only 1.6% is AI decision logic — 98.4% is deterministic infrastructure.
- The core agent loop is a simple
while-loop; the real complexity lives in the permission system, context pipeline, and recovery logic surrounding it. - A 7-mode permission system with an ML-based classifier and deny-first defaults manages every tool invocation — motivated by a finding that users approve 93% of prompts without careful review.
- A 5-layer context compaction pipeline (budget reduction → snip → microcompact → context collapse → auto-compact) manages the context window before every model call.
- Four extensibility mechanisms (MCP, plugins, skills, hooks) are ordered by context cost, from zero-footprint hooks to schema-heavy MCP servers.
- The paper identifies 6 open design directions including silent failure observability, cross-session memory, and long-term human capability preservation. Full analysis at GitHub and arXiv.
When Anthropic accidentally shipped a 59.8 MB source map inside Claude Code's npm package, they inadvertently handed researchers the keys to one of the most closely studied AI systems of the year. The artifact mapped the minified production code straight back to the full, readable TypeScript source tree , approximately 1,900 files and over 512,000 lines. A research team from VILA Lab at Mohamed bin Zayed University of AI and University College London seized the moment, publishing a comprehensive architectural analysis of what they found.
The headline finding is almost counterintuitive: only 1.6% of Claude Code's codebase is AI decision logic. The other 98.4% is deterministic infrastructure , permission gates, context management, tool routing, and recovery logic. The model itself is almost a footnote. The real engineering is everything built around it.
The Leak That Started It All
Security researcher Chaofan Shou found that Claude Code v2.1.88 on npm contained something it shouldn't have: a complete source map file. Source maps are debugging tools that reverse minified code back to its original form. Normally you strip them before publishing. Anthropic didn't. The code was quickly taken down, but not before the community had already cloned and archived it.
What the researchers analyzed was a production system, not a demo. What the npm source map revealed was the entire kitchen , over 4,600 source files across 55+ directories, written in TypeScript/React. Claude Code is a sophisticated, real-world application that combines LLM orchestration, terminal UI rendering, plugin systems, multi-agent coordination, and more , all in a single TypeScript codebase.
A While-Loop at the Center of Everything
Strip away all the complexity and the core of Claude Code is embarrassingly simple. The agent loop is a while-true cycle: assemble context, call the model, get a response, execute any tool calls, feed results back, repeat. The core of the system is a simple while-loop that calls the model, runs tools, and repeats. Most of the code, however, lives in the systems around this loop.
This is a deliberate architectural philosophy. The architecture invests in deterministic infrastructure (context management, tool routing, recovery) rather than decision scaffolding (explicit planners or state graphs), on the premise that increasingly capable models benefit more from a rich operational environment than from frameworks that constrain their choices. Frameworks like LangGraph encode decision logic as explicit state graphs with typed edges. Claude Code does the opposite: give the model maximum latitude, and let the harness handle everything else.

The paper maps this into a five-layer architecture:
- Surface layer , the CLI, headless mode, Agent SDK, and IDE integrations. All of them feed the same underlying loop.
- Core layer , the
queryLoop()async generator inquery.ts, plus the five-stage context compaction pipeline that runs before every model call. - Safety/action layer , the permission system, hook pipeline, extensibility mechanisms, built-in tools, shell sandbox, and subagent spawning.
- State layer , context assembly, runtime state, session persistence, the CLAUDE.md memory hierarchy, and sidechain transcripts for subagents.
- Backend layer , shell execution, MCP server connections, remote execution, and the 42 tool subdirectories.