Claude Code Internals

AI coding agents represent a new paradigm: an LLM in a loop that can read files, run commands, edit code, and spawn sub-agents — all autonomously. This section dissects the architecture behind these systems, using Claude Code as a case study to explore the design patterns that make agentic coding work.

Based on publicly available information, official documentation, and architectural analysis. No proprietary source code is reproduced.

High-Level Architecture

What Makes Coding Agents Different from Chatbots

Traditional Chatbot
  • Single request → single response
  • No file system access
  • No persistent state between turns
  • User must copy-paste code manually
  • Context limited to conversation
Agentic Coding Assistant
  • Multi-step loop: think → act → observe → repeat
  • Direct file read/write/edit access
  • Terminal command execution (sandboxed)
  • Tool results feed back into reasoning
  • Sees full codebase via retrieval + grep
✦ Live

The Agent Loop

How agentic coding assistants use a read-think-act-observe cycle to solve multi-step tasks — with animated execution traces

✦ Live

Tool Use & Sandboxing

File edits, terminal commands, web fetches — how the tool system works, permission boundaries, and why sandboxing matters

✦ Live

Context Window Engineering

Fitting a whole codebase into 200K tokens — summarization, compression, retrieval strategies, and what gets evicted first

✦ Live

Multi-Agent Architecture

Sub-agent spawning, parallel execution, worktree isolation, and how orchestrators coordinate specialized workers

Key Architectural Concepts

System Prompt
A large instruction set that defines the agent's behavior, available tools, safety boundaries, coding style preferences, and environment context. Often 10K+ tokens before the user says anything.
Tool Definitions
JSON schemas describing each capability (Read, Edit, Bash, Grep, Glob, Write, WebFetch, Agent). The model generates structured tool calls; the harness executes them and returns results.
Permission Model
Layered safety: user-configured permission modes control which tools auto-execute vs require approval. Destructive operations (force-push, rm -rf) always need confirmation.
Context Compression
As conversations grow beyond the context window, older tool results are summarized or evicted. The system preserves recent edits and user messages while compressing intermediate search results.
Hooks
User-defined shell commands that trigger on events like pre-tool-execution or post-response. Enables custom CI checks, linting, or notification workflows without modifying the agent itself.
MCP (Model Context Protocol)
A standardized protocol that lets external services expose tools, resources, and prompts to the agent. Think of it as USB for AI — plug in any capability without changing the core system.