Claude Code's 4 Architecture Patterns — From Yesterday's Headline to This Sprint's Implementation
Yesterday we established that harness engineering matters more than model selection. Today, 8 independent sources have dissected the 600K lines in enough detail to extract four specific, implementable patterns. This is the upgrade path from awareness to action.
Pattern 1: KV Cache Fork-Join — O(1) Subagent Parallelism
Claude Code's subagent architecture exploits prompt caching to create Unix fork() for LLM agents. When a parent agent spawns subagents, each child inherits the full conversation context as a byte-identical copy — the API treats it as a cache hit with zero redundant prefill. Spinning up 5 parallel subagents costs roughly the same as one sequential call plus marginal new tokens. Three execution models exist: fork (inherits context), teammate (shared workspace, separate context), and worktree (full git-level isolation). The choice between them is an economic decision, not just architectural. Target >80% cache hit rate on forked subagents.
Pattern 2: 3-Layer Tiered Memory with Compaction
The memory architecture treats the context window like a database treats RAM — as an expensive, scarce resource requiring tiered storage. Layer 1: an always-loaded index (~150 chars/line pointer table). Layer 2: topic-specific knowledge files loaded on demand. Layer 3: raw transcripts accessed only via grep. Write discipline is database-textbook: write topic file first, then update index — never the reverse. If a fact can be re-derived from the codebase, don't store it.
The autoDream overnight consolidation runs in a forked subagent with deliberately limited tool access — Anthropic treats memory maintenance as an untrusted workload that could corrupt the main context.
Five types of compaction exist in the codebase, analogous to LSM-tree compaction: accumulate writes in hot tier, periodically compact into cleaner representations. Memory is treated as a hint, not truth — the agent verifies before using stored knowledge.
Pattern 3: SYSTEM_PROMPT_DYNAMIC_BOUNDARY
System prompts are split into a cached stable front half and a dynamic back half that changes per turn. Cache-breaking content is explicitly annotated with DANGEROUS_uncachedSystemPromptSection markers. If you're running agents without this pattern, you're paying full token costs on every turn for your (presumably massive) system prompt. Refactor: deterministic content in the front, session-specific in the back, explicit markers for anything that breaks the cache.
Pattern 4: Tool Gating — Less Is More
Claude Code defaults to 19 tools from 60+ available: AgentTool, BashTool, FileReadTool, FileEditTool, FileWriteTool, NotebookEditTool, WebFetchTool, WebSearchTool, TodoWriteTool, plus planning and MCP tools. Notably absent: no SearchCodebaseTool (BashTool + grep), no RunTestsTool (BashTool again). The tool set is minimal and composable, not comprehensive. Additional tools are gated behind explicit context signals. Multiple sources confirm that constraining tool sets dramatically improves tool selection accuracy.
Cross-Source Divergence
Sources disagree on how much of this is novel vs. well-understood database engineering applied to a new domain. The Engineer's Codex and AINews analyses emphasize the patterns are borrowed from database index design (tiered storage, compaction, write-ahead discipline). Turing Post and Unwind AI frame the self-improving procedure generation in competing frameworks (Hermes Agent) as potentially more ambitious. The consensus: Claude Code's patterns are proven in production at scale, which matters more than novelty.
What to do
Prototype the 3-layer memory architecture (index → topic files → transcripts) for your highest-value agent system this sprint
Restructure system prompts to use stable/dynamic boundary pattern with explicit cache-break markers
Benchmark subagent forking with your API provider's prompt caching — measure actual cache hit rates on forked context
Audit your agent's tool count — if >20 defaults, constrain to composable primitives and gate the rest