Anthropic's Claude Code Leak Gets Rebuilt in 4,300 Lines Anyone Can Read

A 13-chapter, ~4,300-line open-source tutorial rebuilds Claude Code's core agent architecture from scratch in TypeScript and Python, making production-grade coding agent design accessible to everyone.

·
·
·
Anthropic's Claude Code Leak Gets Rebuilt in 4,300 Lines Anyone Can ReadPRO
  • A 13-chapter open-source tutorial rebuilds Claude Code's core architecture in ~4,300 lines of TypeScript and Python.
  • The project was born after Anthropic accidentally exposed 512,000 lines of Claude Code source via a missing .npmignore entry in an npm package.
  • Covers the full agent stack: agent loop, 13 tools, 4-layer context compression, semantic memory, multi-agent spawning, MCP integration, and a permission system.
  • Runs against both Anthropic and OpenAI-compatible APIs; installable as a CLI tool (mini-claude or mini-claude-py) usable in any project directory.
  • Key insight from the source analysis: only 1.6% of Claude Code is AI logic -- the other 98.4% is deterministic infrastructure (permissions, context, tool routing).
  • MIT-licensed and available in English and Chinese; companion repo how-claude-code-works provides deeper source-level analysis.

When Anthropic accidentally shipped the full source code of Claude Code inside an npm package, the community got a rare look inside one of the most sophisticated AI coding agents ever built. The problem? The codebase clocked in at 513,216 lines of TypeScript across 1,884 files, with 42 tools and 90 feature flags. Most developers had no realistic path to understanding it. Claude Code From Scratch is the answer to that problem: a step-by-step tutorial that rebuilds the core architecture in roughly 4,300 lines of code.

The backstory: a missing line that changed everything

On March 31, 2026, someone at Anthropic forgot to add *.map to .npmignore. That single oversight shipped a 59.8 MB source map inside the @anthropic-ai/claude-code v2.1.88 npm package, exposing 512,000 lines of unobfuscated TypeScript across 1,906 files -- the entire internal architecture of their flagship AI coding agent. Anthropic filed DMCA takedowns and GitHub repos started disappearing. But the architecture was already out, and the community moved fast to understand it.

What they found was surprising. 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 agent loop itself is just a while loop. The engineering is everything around it.

What the tutorial actually covers

Rather than asking you to read half a million lines of proprietary code, the tutorial rebuilds the core in 13 chapters across two phases. Phase 1 gets you to a working coding agent. Phase 2 adds the advanced systems that make it production-grade. Each chapter maps directly to the real Claude Code source files, showing you what the original does and how the simplified version differs.

Pro article

This story is for Pro members

You've reached the end of the free preview. Upgrade to AlphaSignal Pro to read the full article - and everything else behind the paywall.

Trending
  • No trending articles

Comments

avatar

Next Reads