Claude Code's Core Is a While-Loop. The Infrastructure Around It Has Five Layers.
A paper from VILA Lab (arXiv:2604.14228) analyzed Claude Code’s publicly available TypeScript source and reached a conclusion that challenges the dominant framing around coding agents: the model is not the hard part.
The core agent loop, as implemented, is a simple while-loop: call the model, run the approved tools, append the results to context, repeat. The researchers describe it as the smallest component in the entire system.
What surrounds that loop is where the engineering actually lives.
The Five-Layer Architecture
The paper identifies the following infrastructure layers wrapped around the core loop:
Permission system — 7 operational modes controlled by an ML-based classifier that routes each tool call to the appropriate authorization level. Not a static allowlist: the classifier makes a judgment call per action.
Context compaction pipeline — 5 stages of compression and summarization that activate as the context window fills. Context management is described as “a major design problem” — the pipeline exists because naive accumulation of tool outputs would exhaust the context window within a few turns on any non-trivial task.
Extensibility mechanisms — four distinct extension points: MCP (external tool servers), plugins, skills, and hooks. These allow the harness to be extended without touching the core loop.
Subagent delegation — a mechanism for spawning sub-tasks with worktree isolation, so parallel work doesn’t corrupt the primary session state.
Session storage — append-oriented, meaning state accumulates rather than overwrites. This is a deliberate design choice with implications for auditability and recovery.
The Broader Insight
The paper’s most transferable observation: “Autonomy does not remove infrastructure. It increases the burden on infrastructure.”
A model that can run shell commands and edit files cannot be treated like a chatbot with extra tools. Every action has side effects. Every side effect requires a boundary. The engineering weight scales with the model’s capability, not inversely.
The paper compares Claude Code’s architecture against OpenClaw, an independent open-source agent gateway that answers the same design questions from a different deployment context. Where Claude Code uses per-action ML classification for safety, OpenClaw uses perimeter-level access control. Where Claude Code manages a single CLI loop, OpenClaw operates as an embedded runtime within a gateway control plane. Same design problems, different engineering choices driven by different deployment constraints.
What This Means for Agent Builders
The paper identifies six open design directions for future agent systems, grounded in empirical and architectural literature. It doesn’t claim Claude Code has solved these — it maps where the unsolved problems are.
The implication for teams building on top of frontier models is direct: a capable model inside a weak harness will underperform a less capable model inside a well-engineered one. The scaffolding is not incidental. It is the product.
The codebase for the analysis is published at GitHub under the VILA-Lab organization.