# Reverse Engineering Claude Code > A bottom-up, source-verified guide to how a production coding agent is built: tools, the query loop, compaction, permissions, hooks, MCP, subagents, the terminal renderer and the remote bridge. Every page is also available as markdown by adding `.md` to its URL. The whole book as one file: https://reverseengineeringclaudecode.com/book.md ## Start here - [Dissecting an Agentic Coding Tool](https://reverseengineeringclaudecode.com/introduction.md) - [Architecture Map: The Bottom-Up Layer Cake](https://reverseengineeringclaudecode.com/architecture-map.md) - [Master Outline & Chapter Blueprints](https://reverseengineeringclaudecode.com/outline.md) ## Prologue - [Chapter 00 — How to Read a 1,900-File Agent](https://reverseengineeringclaudecode.com/chapters/00-how-to-read-a-1900-file-agent.md): Orient the reader without drowning in `main.tsx`. Map file distribution across top-level directories (`utils/`, `components/`, `commands/`, `tools/`, `services/`, `hooks/`, `ink/`), explain the five idioms seen everywhere (`feature()` DCE, `lazySchema()`, `bootstrap/state.ts` leaf isolation, React Compiler `_c(...)` output in `.tsx`, and snapshot gaps), and establish the bottom-up reading path. ## Part I — Foundations: Atoms, State, and Contracts - [Chapter 01 — The Atoms: Identity, Reactive Stores, Lazy Schemas, and Async Generators](https://reverseengineeringclaudecode.com/chapters/01-atoms-types-stores-and-primitives.md) - [Chapter 02 — The Tool Contract: Defining What an Agent Can Do](https://reverseengineeringclaudecode.com/chapters/02-the-tool-contract.md) - [Chapter 03 — The Command & Message Contracts: User Input Meets the Model](https://reverseengineeringclaudecode.com/chapters/03-command-and-message-contracts.md) ## Part II — The Prompt, the Model, and the Engine - [Chapter 04 — Prompt Engineering as Systems Engineering: Context & Cache Boundaries](https://reverseengineeringclaudecode.com/chapters/04-prompt-engineering-and-cache-boundaries.md) - [Chapter 05 — Talking to the Model: API Client, Streaming, Retries, and Accounting](https://reverseengineeringclaudecode.com/chapters/05-talking-to-the-model.md) - [Chapter 06 — Executing Tools: Validation, Hooks, Concurrency, and Streaming Execution](https://reverseengineeringclaudecode.com/chapters/06-executing-tools.md) - [Chapter 07 — The Heartbeat: query.ts and the Agentic Turn State Machine](https://reverseengineeringclaudecode.com/chapters/07-the-heartbeat-query-loop.md) - [Chapter 08 — The Session Envelope: QueryEngine.ts and Transcript Persistence](https://reverseengineeringclaudecode.com/chapters/08-session-envelope-query-engine-and-transcripts.md) ## Part III — Surviving Long Horizon: Context Management & Memory - [Chapter 09 — The Five-Layer Compaction Pipeline](https://reverseengineeringclaudecode.com/chapters/09-five-layer-compaction-pipeline.md) - [Chapter 10 — Memory Systems: CLAUDE.md, Auto-Memory, Session Memory, and Auto-Dream](https://reverseengineeringclaudecode.com/chapters/10-memory-systems-claudemd-auto-memory-and-dream.md) ## Part IV — Safety, Policy, and Extensibility - [Chapter 11 — The Permission Engine: Modes, Rules, Classifiers, and Persistence](https://reverseengineeringclaudecode.com/chapters/11-the-permission-engine.md) - [Chapter 12 — Shell Execution, Sandboxing, and Core Workspace Tools](https://reverseengineeringclaudecode.com/chapters/12-shell-execution-sandboxing-and-workspace-tools.md) - [Chapter 13 — The Hook System: Intercepting Every Lifecycle Event](https://reverseengineeringclaudecode.com/chapters/13-the-hook-system.md) - [Chapter 14 — Configuration, Settings Precedence, and Enterprise Policy](https://reverseengineeringclaudecode.com/chapters/14-configuration-settings-and-enterprise-policy.md) ## Part V — Dynamic Capabilities: MCP, Skills, Plugins, and LSP - [Chapter 15 — Model Context Protocol (MCP): Clients, Transports, Auth, and Tool Search](https://reverseengineeringclaudecode.com/chapters/15-model-context-protocol-mcp.md) - [Chapter 16 — Skills, Plugins, Output Styles, and LSP Intelligence](https://reverseengineeringclaudecode.com/chapters/16-skills-plugins-output-styles-and-lsp.md) ## Part VI — Concurrency, Tasks, Subagents, and Swarms - [Chapter 17 — The Background Task Runtime: Unified State, Disk-Backed Output, Notifications, and Proactive Scheduling](https://reverseengineeringclaudecode.com/chapters/17-background-task-runtime.md) - [Chapter 18 — Subagents, Context Forking, and Git Worktrees](https://reverseengineeringclaudecode.com/chapters/18-subagents-context-forking-and-worktrees.md) - [Chapter 19 — Agent Teams, Swarms, and Coordinator Mode: Multi-Agent IPC, Permission Bubbling, and Pure Orchestration](https://reverseengineeringclaudecode.com/chapters/19-agent-teams-swarms-and-coordinator-mode.md) ## Part VII — The Terminal UI Engine - [Chapter 20 — Inside ink/: A Custom React Renderer for the Terminal](https://reverseengineeringclaudecode.com/chapters/20-inside-ink-terminal-react-renderer.md) - [Chapter 21 — The Interactive REPL: Screens, Input, Keybindings, and Vim Mode](https://reverseengineeringclaudecode.com/chapters/21-the-interactive-repl-screens-keybindings-and-vim.md) ## Part VIII — Entrypoints, Startup, SDK, and Remote Control - [Chapter 22 — Cold Start Mastery: From entrypoints/cli.tsx Through init.ts to main.tsx](https://reverseengineeringclaudecode.com/chapters/22-cold-start-mastery-cli-init-main.md) - [Chapter 23 — Machine-Readable Modes: Headless CLI, Agent SDK, and Control Protocols](https://reverseengineeringclaudecode.com/chapters/23-machine-readable-modes-headless-sdk-and-control-protocols.md) - [Chapter 24 — Across the Wire: Remote Sessions, Always-On Bridge, and Direct Connect](https://reverseengineeringclaudecode.com/chapters/24-across-the-wire-remote-sessions-bridge-and-direct-connect.md) ## Part IX — Epilogue: The Snapshot Meets the Shipped Product - [Chapter 25 — Bringing It to the Present: From 2.1.88 to 2.1.331](https://reverseengineeringclaudecode.com/chapters/25-bringing-it-to-the-present.md): Map eight months and roughly 240 releases of drift onto Layers 0–8, tagging each claim as Changelog, Binary (2.1.331 or 2.1.296 extraction), or Speculation, and show which 2.1.88 contracts held. ## Appendices - [Appendix A — Complete Inventory of Build-Time feature() Flags & Environment Knobs](https://reverseengineeringclaudecode.com/appendices/A-feature-flags-and-env-knobs.md) - [Appendix B — Reconstructing the Missing Snapshot Boundaries from Call Sites](https://reverseengineeringclaudecode.com/appendices/B-missing-snapshot-boundaries.md) - [Appendix C — Mini-Harness Blueprint: Building a 500-Line Working Toy Clone Using the Patterns in This Book](https://reverseengineeringclaudecode.com/appendices/C-mini-harness-blueprint.md) ## Reference - [Codebase Glossary](https://reverseengineeringclaudecode.com/glossary.md) - [Editorial & Authoring Guide](https://reverseengineeringclaudecode.com/editorial-guide.md)