
Inside Claude Code
The Architecture
How Claude Code works under the hood, from its runtime state to its agent orchestration engine.
You can read the contents and the first 2,000 characters.
Pro includes the whole book.
- By Sahar Carmel
- 25 chapters
- Updated Nov 1, 2026
- 322 readers
What’s inside
- Bootstrap & State — The Singleton Nervous System
- The Query Engine — The Core Loop
- Context Management — The Five Layers
- System Prompt Construction
- The Permission System
- Auto Mode and the YOLO Classifier
From the first page
Version: 2.0 Based on: Source analysis of Claude Code Note: All content is original analysis and description. No verbatim code or prompts are reproduced.
1. Bootstrap & State — The Singleton Nervous System 2. The Query Engine — The Core Loop 3. Context Management — The Five Layers 4. System Prompt Construction
5. The Permission System 6. Auto Mode & the YOLO Classifier 7. The Hooks System
8. Tool Architecture Patterns 9. The Agent Definition Schema 10. The Agent Sourcing Hierarchy 11. The Five Built-in Agents 12. How the Parent Model Chooses — The Agent Tool Prompt 13. Coordinator Mode — The Full Orchestration System 14. Fork Subagent — The Experimental Parallelism Feature 15. The Memory System 16. The Skill System 17. The Command System 18. The Plugin System 19. MCP Integration
20. The Transport Layer 21. The Bridge & Remote Control System
Claude Code's entire runtime revolves around a single mutable state object initialized at module load time. Every subsystem reads from and writes to this object, making it the central nervous system of the application. The design is shaped by one hard constraint: the state module must sit at the leaf of the import dependency graph.
Preview · 2,000 of 125,446 characters
Contents
- 01Table of Contentsp.1
- Part I: The Core Runtimep.1
- Part II: The Security & Control Planep.1
- Part III: The Extension Surfacep.1
- Part IV: Infrastructure & Connectivityp.1
- Appendicesp.1
- 02Bootstrap & State — The Singleton Nervous Systemp.1
- The State Objectp.1
- The Leaf Constraintp.1
- The Sticky-On Latch Patternp.1
- Atomic Session Switchingp.1
- Path Normalization at Startupp.1
- Why This Mattersp.1
- 03The Query Engine — The Core Loopp.1
- Persistence Before Transmissionp.1
- The Async Generator Patternp.1
- The Infinite Loopp.1
- Output Token Cappingp.1
- The Rules of Thinkingp.1
- Token Budget Tracking Across Compactionp.1
- 04Context Management — The Five Layersp.1
- Layer 1: Context Window Detectionp.1
- Layer 2: Microcompactionp.1
- Layer 3: Auto-Compaction Triggerp.1
- Layer 4: Full Compactionp.1
- Layer 5: Session Memory Compactionp.1
- The Manual Triggerp.1
- 05System Prompt Constructionp.1
- The Cache Boundaryp.1
- The Section Frameworkp.1
- The Static Halfp.1
- The Dynamic Halfp.1
- Identity Prefix Variantsp.1
- The Attestation Headerp.1
- 06The Permission Systemp.1
- The Seven Modesp.1
- The Three-Step Pipelinep.1
- Rule Sources and Persistencep.1
- Sandbox Integrationp.1
- Server-Side Killswitchesp.1
- 07Auto Mode and the YOLO Classifierp.1
- The Design Problemp.1
- The Fast Pathp.1
- Two-Stage Classificationp.1
- Dangerous Pattern Pre-Screeningp.1
- The Circuit Breakerp.1
- The Namep.1
- Implications for Usersp.1
- 08The Hooks Systemp.1
- The Fourteen Hook Eventsp.1
- Sync vs. Async Hooksp.1
- What Hooks Can Returnp.1
See all 25 parts
- 09Tool Architecture Patternsp.1
- The Deferred Tool Patternp.1
- The Synthetic Output Toolp.1
- The Brief Toolp.1
- The LSP Toolp.1
- The REPL Toolp.1
- Tool Filtering and Cache Optimizationp.1
- The Permission System Interactionp.1
- 10The Agent Definition Schemap.1
- The Complete Field Setp.1
- The Key Insightp.1
- 11The Agent Sourcing Hierarchyp.1
- What This Means in Practicep.1
- 12The Five Built-in Agentsp.1
- The General-Purpose Agentp.1
- The Explore Agentp.1
- The Plan Agentp.1
- The Verification Agentp.1
- The Claude Code Guide Agentp.1
- 13How the Parent Model Chooses -- The Agent Tool Promptp.1
- The Static/Dynamic Splitp.1
- The Agent Line Formatp.1
- The "When Not to Use" Sectionp.1
- Writing the Prompt Guidancep.1
- 14Coordinator Mode -- The Full Orchestration Systemp.1
- The Coordinator's Rolep.1
- The Four-Phase Workflowp.1
- Worker Results Formatp.1
- Continue vs. Spawn -- The Decision Matrixp.1
- The "Never Fabricate Results" Rulep.1
- 15Fork Subagent -- The Experimental Parallelism Featurep.1
- What a Fork Isp.1
- How Prompt Cache Sharing Worksp.1
- The Fork Boilerplatep.1
- The "Don't Peek" Rulep.1
- Coordinator Mode Exclusionp.1
- 16The Memory Systemp.1
- Agent Memory Scopesp.1
- The Memory Entrypointp.1
- Remote Memory for Container Deploymentsp.1
- Memory Scope Guidancep.1
- 17The Skill Systemp.1
- Five Sources, One Ordered Listp.1
- The Skill File Formatp.1
- Conditional Activationp.1
- Dynamic Discoveryp.1
- The Security Boundary for External Skillsp.1
- Bundled Skill File Extractionp.1
- Design Philosophyp.1
- 18The Command Systemp.1
- Three Command Typesp.1
- No Auto-Discoveryp.1
- Lazy Loadingp.1
- Feature-Flag Gatingp.1
- Two-Layer Visibilityp.1
- The Migration Patternp.1
- 19The Plugin Systemp.1
- Five Component Typesp.1
- The Manifestp.1
- The Marketplacep.1
- Anti-Impersonationp.1
- The Loading Pipelinep.1
- Variable Substitutionp.1
- Dependency Resolutionp.1
- MCP Server Deduplicationp.1
- +1 more section
- 20MCP Integrationp.1
- Seven Configuration Scopesp.1
- Six Transport Typesp.1
- Plugin-Provided MCP Serversp.1
- The Channel Systemp.1
- OAuth and Cross-App Authenticationp.1
- Enterprise Allowlistingp.1
- The Bigger Picturep.1
- 21The Transport Layerp.1
- The Transport Hierarchyp.1
- Why Split Reads and Writes?p.1
- Buffering and Coalescingp.1
- Sleep, Wake, and Reconnectionp.1
- Rate Limits and Backpressurep.1
- Design Philosophyp.1
- 22The Bridge and Remote Control Systemp.1
- Two Generations, One Interfacep.1
- Three Spawn Modesp.1
- Cross-Process Token Failure Backoffp.1
- Crash Recovery Through Bridge Pointersp.1
- The FlushGate State Machinep.1
- Session Identity Compatibilityp.1
- 23Appendix A: The Buddy Systemp.1
- Bones and Soulp.1
- Rarity, Stats, and Personalityp.1
- The Forbidden String Problemp.1
- Virality by Time Zonep.1
- The Theatrical Separationp.1
- 24Appendix B: Glossary of Architectural Patternsp.1
- Module-as-Singletonp.1
- DAG Leaf Constraintp.1
- Sticky-On Latchp.1
- Circuit Breakerp.1
- Passthroughp.1
- Bubble Permission Propagationp.1
- Content-Based Deduplicationp.1
- Reconciler Patternp.1
- +2 more sections
- 25Appendix C: Agent Definition Quick Referencep.1



