# Inside Claude Code's AI agent architecture

> A deep dive into how Anthropic built the most widely used AI coding agent, extracted from source maps and distilled into 18 chapters of transferable patterns.
- Title: Inside Claude Code's AI agent architecture | Shortify
- Summary: A deep dive into how Anthropic built the most widely used AI coding agent, extracted from source maps and distilled into 18 chapters of transferable…
- Keywords: claude code, anthropic, ai agents, architecture, async generators, tool execution, multi-agent orchestration, prompt cache, memory systems, performance engineering, technology, startups
- Source: Claude Code From Source — https://claude-code-from-source.com
- Read time: 2 min
- Topics: claude code, anthropic, ai agents, architecture, async generators, tool execution, multi-agent orchestration, prompt cache, memory systems, performance engineering, technology, startups
## How Anthropic reverse-engineered its own code
Claude Code shipped with source maps containing full TypeScript. Anthropic extracted nearly 2,000 files and used 36 AI agents across four phases to analyze, document, and rewrite the architecture as a book in about 6 hours.

> The source was extracted from npm source maps, the .js.map files that shipped with Claude Code contained a sourcesContent field with the full original TypeScript.
## The agent loop drives everything
An async generator powers the entire system, streaming model output, executing tools, recovering from errors, and compressing context across four layers. This natural backpressure and cancellation mechanism is the heartbeat of the agent.
## Tool execution at scale
A 14-step pipeline handles every request from model to result. Permission resolution, speculative execution (starting read-only tools before the response completes), and concurrent batching by safety classification keep latency low.
## Sub-agents share cached prompts
Multiple agents can fork and share byte-identical prompt prefixes, cutting input token costs by 95%. Coordinator mode and swarm messaging with mailboxes let teams work together efficiently.
## Memory without a database
File-based memory with an LLM-powered recall system beats embedding search. Four memory types, staleness warnings, and a Sonnet side-query select relevant memories instead of keyword matching.
## Performance engineered to 240ms startup
Parallel I/O gets Claude Code running in 240 milliseconds. Slot reservation saves context in 99% of requests, bitmap pre-filters speed fuzzy search, and prompt cache optimization accounts for every millisecond.
## Security through frozen config snapshots
Two-phase skill loading defers content until invocation, while 27 lifecycle hooks with config snapshots frozen at startup prevent runtime injection attacks. Sticky latches keep cache headers stable mid-session.
## Ten architectural bets that define Claude Code
Async generators, speculative execution, concurrent-safe batching, fork agents for cache sharing, four-layer context compression, file-based memory with LLM recall, two-phase skill loading, sticky latches, slot reservation, and frozen config snapshots form the foundation.
## Learn patterns you can steal
The book covers 18 chapters with transferable patterns and concrete adaptation advice. Engineers can steal the architecture, technical leaders can understand the decisions, and anyone can learn how production AI tools actually work.

> Engineers building agentic systems. Every chapter ends with "Apply This", 5 transferable patterns with concrete adaptation advice.
## Key takeaway

Claude Code uses six core abstractions, an async generator loop, speculative tool execution, multi-agent orchestration with cache sharing, file-based memory with LLM recall, and frozen config snapshots, that can be adapted to build production AI agents.