Anatomy of Claude Code: The ReAct Loop Under the Hood
I spent time pulling apart how Claude Code actually works under the hood, based on Anthropic's docs and community reverse-engineering.
Underneath, it's a ReAct loop, and the loop skeleton is only about 50 lines. The model decides everything.
Reason → the model reasons. Roughly 30-40% of calls run on Haiku, for metadata, exploration, and summaries. Tool Call → it picks one of ~18 tools (5 core: Read, Write, Bash, Grep, Web). Bash is the universal adapter; MCP tools load on demand via ToolSearch, saving >85% of context. Observe → it reads the result. If context passes ~85% (on Sonnet), it compacts.
Around the loop: CLAUDE.md as persistent memory, sub-agents get a fresh isolated context, and skills are injected instructions.
Safety is 18 lifecycle hooks plus an allowlist that filters every tool call: permission (auto / ask / deny), a PreToolUse hook, a Haiku check on Bash commands, execution, then a PostToolUse hook.
And search is just ripgrep + the LLM. Zero RAG, zero embeddings, zero vector DB.
The simpler the loop, the more room the model has to reason.