Claude Code Internals
API reference and code examples for the Claude Code Internals module.
The Big Picture
markdownNine-crate map of the Claude Code agent harness, the request loop in eleven lines of pseudocode, and the eight architectural moves worth borrowing.
The Tool Surface
markdownAll 50 tools cataloged by category, the four-field ToolSpec struct, and the deferred-loading mechanism that keeps the system prompt small.
Sub-agents & Context Cleanliness
markdownHow the Agent tool spawns isolated runtimes, why the parent's context stays clean, and the per-subagent-type tool allowlists that prevent whole classes of mistakes.
The Request Loop, Traced
markdownEnd-to-end walk of one bash invocation: REPL → conversation runtime → API stream → permission gate → sandbox → tool result, with file:line refs at every step.
Context, Caching, Compaction
markdownThe static-vs-dynamic system prompt boundary, where claw-code's prompt cache stops short of upstream Claude Code, and the compaction algorithm that trades cache invalidation for headroom.
Plan vs Execution
markdownHow plan mode, TaskRegistry, and recovery recipes keep long agent runs from drifting off course.
Permissions & Sandboxing
markdownFive-tier permission mode, the deny-context-ask-allow-mode-default decision tree, capability-probed Linux sandboxing, and the bash validation gaps.
Extensibility (Hooks, Plugins, Skills, MCP)
markdownFive extensibility surfaces with different blast radii: hooks can block tool calls, plugins ship bundled tools, skills inject guidance, slash commands are user-invokable, and MCP brings external servers into the registry.
Multi-Agent Coordination
markdownLanes as event streams, branch locks before merge, teams and crons — the claw-code-specific layer that enables Discord-driven autonomous coordination.
The Mock Parity Harness
markdownA faithful mock of /v1/messages plus 12 scripted scenarios — a deterministic, sub-second integration test pattern worth lifting wholesale.
Patterns to Borrow
markdownTwelve patterns ranked by impact-per-line-of-code, plus a file:line cheat sheet and the parity gaps to know about.