The Claude Code Leak: 10 Agentic AI Harness Patterns That Change Everything
Following the recent leak of Anthropic’s Claude Code source code, our research team at DistributedApps.ai performed a deep dive into the repository to decode the agentic AI engineering patterns hidden within its vast architecture.
We identified 10 fundamental patterns that serve as the backbone for production-ready agentic systems. These are not merely specific to Anthropic; they are universal principles essential for any team building at the frontier of AI.
Starting tomorrow, we are launching a 10-part series exploring each pattern in detail, featuring direct code examples from the codebase. Here is a preview of what’s ahead:
Chapter 1: The Harness Paradigm
The most fundamental insight from the Claude Code codebase is that the challenge of production AI is not about the model — it is about the harness. The model provides intelligence, but the harness provides control. A well-designed harness can make even a modest model reliable and safe, while a poorly designed harness can make even the most capable model dangerous.
The harness addresses five core challenges: constraining the action space through tools, managing conversation state, enforcing safety through permissions, handling failures gracefully, and optimizing resource usage. The three-layer architecture — Model Layer, Harness Layer, and UI Layer — separates concerns and enables clean system design. The Tool interface is the fundamental abstraction that enables the harness to reason about tool behavior and make intelligent decisions.
In the full series: We examine the harness paradigm in detail, showing how the three-layer architecture separates concerns, how the Tool interface creates a uniform contract for all actions, and how the core challenges of safety, reliability, and scalability are addressed through permissions, compaction, and multi-agent coordination.
Chapter 2: Tool Architecture and the Tool Contract
Every tool in the Claude Code system implements the same interface, creating a uniform contract between the model and every possible action it can take. This interface covers identity, execution, validation, permissions, and presentation. The key insight is that the harness must be able to reason about tool behavior — whether tools can run concurrently, whether they modify state, whether they require special permissions — and make intelligent decisions without understanding the tool’s internals.
Zod schemas provide type-safe validation at every boundary. Behavioral properties like isConcurrencySafe and isReadOnly enable optimization. The buildTool factory provides conservative defaults that make new tools safe out of the box.
In the full series: We walk through the complete Tool interface, explaining each field and showing how they work together to create a tool system that is both expressive and safe.
Chapter 3: The Query Engine — Orchestrating AI Conversations
The QueryEngine is the central orchestrator of the AI conversation lifecycle. It manages the back-and-forth between the user, the language model, and the tool execution environment. The query loop implements what we call the “continue sites pattern” — multiple exit points that can either terminate the turn or continue to the next iteration with updated state, enabling sophisticated error recovery.
The harness withholds recoverable errors and attempts recovery through multiple strategies: context collapse drain, reactive compact, max output tokens escalation, and multi-turn continuation. Token budgets are enforced at multiple levels to prevent runaway costs.
In the full series: We trace the complete query loop, identifying all continue sites and showing how they enable graceful degradation and self-healing behavior.
Chapter 4: Permission Systems and Safety Guardrails
The permission system in Claude Code is not a single check but a layered pipeline. First, general permission rules are evaluated — allow lists, deny lists, ask lists. Then tool-specific checks run, allowing tools to implement custom logic. Then automated classifiers can make fast-path decisions. Finally, if no automated path resolves the decision, the system falls back to interactive user approval.
The system operates in multiple modes — default, auto, plan, acceptEdits, bubble — each representing a different balance between automation and user control. The canUseTool function is the central gatekeeper, ensuring that every tool use is evaluated before execution.
In the full series: We examine the canUseTool function and trace a permission evaluation through all layers, showing how the system makes intelligent decisions without frustrating users.



