Chapter Goal:
Compare 12 major AI Agent frameworks and products—Claude Code, Claude Agent SDK, OpenAI Agents SDK, Codex, Gemini CLI, Cursor, Cline, Aider, OpenHands, LangGraph, AutoGen, and CrewAI—across ten architectural dimensions. The goal is to understand their design trade-offs and establish a reference framework for the deeper architectural analysis of Claude Code that follows.
5.1 Why Compare Architectures Side by Side?
One of the best ways to understand an architecture is not to study it in isolation, but to place it within a broader landscape and compare it with its neighbors.
If you study Claude Code by itself, you may assume that its architecture is simply “the way things should be designed.” Once you compare it with other systems, however, a much more important insight emerges:
Every architectural decision is a trade-off among multiple possible alternatives.
This chapter compares 12 major frameworks and products, which can broadly be divided into two categories.
1. Coding Agent Products
These are complete products designed for end users:
- Claude Code
- Codex
- Gemini CLI
- Cursor
- Cline
- Aider
- OpenHands
2. Agent Frameworks and SDKs
These are developer-oriented building blocks for creating Agent applications:
- Claude Agent SDK
- OpenAI Agents SDK
- LangGraph
- AutoGen
- CrewAI
This classification reveals an important distinction between products and frameworks.
Products provide a complete Harness, including terminal or IDE interfaces, permissions, session management, and user interaction. Frameworks generally focus more on helping developers build the Agent Loop and application logic.
Understanding this distinction is essential to understanding the unique value of Claude Code.
Why compare these systems at all?
Because architectural trade-offs become visible only through comparison.
For example, the question of whether to use an explicit graph, as in LangGraph, or an implicit loop, as in Claude Code, becomes much easier to understand when both approaches are examined side by side. Looking at either architecture in isolation can easily lead to incomplete conclusions.
5.2 Ten Architectural Dimensions
Before comparing the frameworks, we first need to define the ten dimensions used in this chapter.
Each dimension corresponds to a core responsibility of an Agent Harness:
- Agent Loop — How is the execution loop implemented? Is it an explicit
whileloop or graph-driven? - Tool System — How are tools defined, registered, and executed?
- Context — How is context managed? Is there a context compaction mechanism?
- Memory — How is memory maintained across sessions?
- Permission — How are permissions and human-agent interactions controlled?
- Subagent — Does the system support subagents or multi-agent execution?
- MCP — Does it support the Model Context Protocol?
- Persistence — How are sessions and state persisted?
- Sandbox — Does it provide sandboxed execution or isolation?
- Human-in-the-loop — How can humans intervene during execution?
These dimensions are not arbitrary. They are an expansion of the nine major Harness responsibilities discussed in Chapter 4.
By comparing systems across these ten dimensions, we can see where each framework places its architectural emphasis—and which parts of the Harness it chooses to make first-class capabilities.
5.3 Architecture Analysis by Framework
5.3.1 Claude Code
Positioning: Anthropic’s official terminal-based Coding Agent and the primary research subject of this book.
Architectural Characteristics
- Agent Loop: An explicit
while (true)loop, implemented throughqueryLoopinsrc/query.ts, combined with a comprehensive state machine.transitions.tsdefines states such as Terminal and Continue. - Tool System: More than 40 built-in tools, including Read, Write, Edit, Glob, Grep, Bash, Task, and Todo. These tools share a unified Tool interface and support both sequential and parallel execution.
- Context: One of the most sophisticated context-management implementations among Coding Agents. It includes multiple compaction strategies such as
autoCompact,microCompact, andsessionMemoryCompact. Additional mechanisms such asreactiveCompact,snipCompact, andcontextCollapseappear as call sites in the current source tree and therefore require further verification. Claude Code also incorporates context budgets and diminishing-return detection. - Permission: A fine-grained permission system with three primary policies: Allow, Deny, and Ask. Rules can also be persisted.
- Subagent: The Task tool can delegate work to subagents, including parallel execution.
- MCP: Full MCP client support.
- Persistence: Comprehensive session persistence, including resume and fork capabilities.
- Sandbox: Supports workspace and worktree isolation.
- Human-in-the-loop: Permission approval, Plan Mode, interruption, and recovery.
Key Insight
Claude Code represents a benchmark for Harness completeness.
It covers almost every major Harness dimension and provides a relatively mature implementation across them. This is precisely why it serves as the central subject for the reverse-engineering approach used throughout this book.
5.3.2 Claude Agent SDK
Positioning: Anthropic’s official SDK for building Agent applications, designed primarily for developers.
Architectural Characteristics
Claude Agent SDK can be understood as an attempt to extract the core Harness capabilities of Claude Code and expose them as a programmable SDK.
It provides capabilities such as:
- Agent Loop
- Tools
- Subagents
- MCP integration
However, it does not include the terminal UI and complete CLI product experience of Claude Code.
Relationship with Claude Code
The relationship between the two is architecturally significant.
Claude Code can be viewed as a product built on top of Agent-oriented SDK capabilities.
This separation demonstrates an important principle:
Core Harness capabilities and product interfaces can be separated.
The Harness provides reusable execution capabilities, while the product determines how those capabilities are exposed to users.
This is another manifestation of Model-Harness Separation, discussed later in the book. The core Harness capabilities can be generalized, while product forms can vary significantly.
5.3.3 OpenAI Agents SDK
Positioning: OpenAI’s official Agent development framework, evolved from Swarm.
Architectural Characteristics
- Agent Loop: A Python-based
Runnerandrun()execution model, with support for handoffs. - Tool System: Python functions can be directly exposed as tools. Function signatures and docstrings can be used to generate tool schemas.
- Subagent: Multi-Agent collaboration can be implemented through handoffs, while Agents can also be exposed as tools.
- MCP: Later versions added support for MCP.
- Guardrails: Provides input and output guardrails.
Key Insight
OpenAI Agents SDK emphasizes simplicity and Python-native development.
Tools can be defined with Python functions, while handoffs provide a straightforward abstraction for multi-agent collaboration.
Its design philosophy can be summarized as:
Make Agent development feel as natural as writing ordinary Python code.
5.3.4 Codex
Positioning: OpenAI’s Coding Agent, available through CLI and IDE integrations.
Architectural Characteristics
Codex has a positioning very similar to Claude Code: both are terminal-oriented Coding Agents with capabilities such as file manipulation, shell execution, and iterative self-correction.
One notable characteristic of Codex is its strong emphasis on sandboxed execution.
By default, code execution takes place in an isolated environment, reducing the potential security impact of agent-generated operations.
Key Insight
The competition between Codex and Claude Code can ultimately be viewed as:
Two leading AI labs exploring different interpretations of the Coding Agent Harness.
Comparing their differences—such as sandbox defaults and context-management strategies—helps expose some of the fundamental architectural decisions involved in building production-grade Coding Agents.
5.3.5 Gemini CLI
Positioning: Google’s terminal-based Coding Agent.
Architectural Characteristics
Gemini CLI follows the same general Coding Agent pattern, providing:
- File operations
- Command execution
- Iterative self-correction
- Agent-style task execution
Its distinctive characteristic is deep integration with Google’s ecosystem, including the Gemini model family and Google services such as search.
5.3.6 Cursor
Positioning: An AI-first IDE rather than a CLI-based Coding Agent.
Architectural Characteristics
Cursor represents the IDE form of the Coding Agent.
Its biggest architectural difference from Claude Code is the interaction layer.
Cursor embeds Agent capabilities directly into a full development environment containing:
- Code editor
- File explorer
- Debugging tools
- IDE-based interaction
Claude Code, by contrast, primarily operates through a terminal interface.
Key Insight
Cursor and Claude Code represent two major forms of Coding Agent interaction:
IDE-first vs. CLI-first
IDE-oriented Agents emphasize visualization and an immersive development experience.
CLI-oriented Agents emphasize lightweight operation, scriptability, automation, and composability.
Neither approach is universally superior. The right choice depends largely on the user’s workflow and the surrounding engineering environment.
5.3.7 Cline
Positioning: An open-source Coding Agent implemented as a VS Code extension.
Architectural Characteristics
Cline is open source, making its implementation fully inspectable. As a result, it is frequently used as a learning resource for understanding Coding Agent architectures.
It supports multiple models and provides a complete:
Plan → Execute → Verify
execution cycle.
It also places a strong emphasis on human approval, allowing users to review and confirm operations within the IDE.
Key Insight
Cline’s greatest value is transparency and learnability.
It is one of the Coding Agents whose internal implementation can be studied in depth, making it particularly useful for developers who want to understand how Coding Agents actually work under the hood.
5.3.8 Aider
Positioning: An open-source terminal Coding Agent focused on AI pair programming.
Architectural Characteristics
Aider represents a minimalist approach.
Its core execution model can be summarized as:
- Send the user’s request and relevant code information to the model.
- Let the model generate edits.
- Apply the edits to the codebase.
- Commit the changes to Git.
Aider also places significant emphasis on repository understanding through a “repository map.”
Instead of putting the entire repository into the model’s context, Aider creates a compressed structural representation of the repository and allows the model to reason about the codebase based on this map.
Key Insight
The repository-map approach is particularly important.
It demonstrates that a Coding Agent does not necessarily need to place an entire repository into the model’s context.
Instead, the model can work effectively with a structured representation of the repository.
This idea becomes highly relevant to the discussion of code understanding later in the book.
5.3.9 OpenHands
Positioning: An open-source autonomous software engineering Agent platform, originally known as OpenDevin.
Architectural Characteristics
OpenHands takes a more research-oriented approach to Coding Agents.
It models the Agent around an event-driven architecture.
The Agent and its tools communicate through an Event Stream, while events can be persisted and replayed.
OpenHands also provides built-in sandboxing through Docker, allowing Agent-generated operations to run in isolated environments.
Key Insight
The Event Sourcing architecture used by OpenHands is particularly valuable from an engineering perspective.
It transforms the Agent’s entire execution process into a replayable and auditable event stream.
This provides an extremely strong foundation for observability, debugging, auditing, and execution analysis.
5.3.10 LangGraph
Positioning: A framework from the LangChain ecosystem for expressing Agent workflows as graphs.
Architectural Characteristics
The central idea behind LangGraph is:
Use an explicit graph or state machine to define Agent control flow.
Each step of the Agent execution is modeled as a Node, while transitions between steps are represented as Edges.
The graph can support:
- Loops
- Conditional branches
- Parallel execution
- State transitions
Key Insight
LangGraph represents a design philosophy fundamentally different from Claude Code:
Explicit Graph vs. Implicit Loop
LangGraph allows developers to explicitly define and visualize the control flow. This makes the system more predictable, testable, and controllable.
Claude Code, by contrast, allows the model to make decisions dynamically inside an execution loop. This makes it more flexible, but also less predictable.
Both approaches have legitimate use cases:
- Explicit graphs are well suited to tasks with clearly defined processes.
- Agent loops are better suited to tasks requiring exploration and dynamic decision-making.
This distinction directly connects to the Agent vs. Workflow discussion in Chapter 1.
5.3.11 AutoGen
Positioning: Microsoft’s framework for multi-agent conversation and collaboration.
Architectural Characteristics
AutoGen focuses on multi-agent conversations.
Multiple Agents can participate in a shared conversation and collaborate through message passing.
Its core abstraction is the Conversable Agent, where Agents communicate with each other through structured interactions.
Key Insight
AutoGen provides an important abstraction for multi-agent collaboration.
However, it also exposes one of the recurring problems with multi-agent architectures:
The cost and unpredictability of multi-agent conversations.
When multiple Agents continuously communicate with each other, token consumption can grow quickly, while the overall execution may become difficult to control.
Multiple Agents do not automatically produce a better system.
Sometimes they simply produce more conversations—and a much larger bill.
5.3.12 CrewAI
Positioning: A framework focused on role-based multi-agent collaboration.
Architectural Characteristics
CrewAI emphasizes four primary abstractions:
- Role
- Goal
- Task
- Crew
Multiple Agents are organized into a “crew,” with each Agent assigned a specific role and responsibility.
The conceptual model resembles a small organization in which different employees perform specialized tasks.
Key Insight
CrewAI’s role-playing abstraction is highly accessible to business users and is useful for demonstrating multi-agent concepts.
However, it is more naturally suited to demonstrative and workflow-oriented multi-agent scenarios. Its robustness for complex real-world software engineering tasks remains a more open question.
5.4 Comprehensive Architecture Comparison
| Framework / Product | Type | Agent Loop | Context Management | Permission / HITL | Subagents | MCP | Sandbox | Core Characteristic |
|---|---|---|---|---|---|---|---|---|
| Claude Code | Product | while + state machine | ★★★★★ | ★★★★★ | Strong (Task) | Strong | Yes | Benchmark for Harness completeness |
| Claude Agent SDK | SDK | while | ★★★★ | ★★★ | Strong | Strong | Optional | Separation of SDK and product |
| OpenAI Agents SDK | SDK | Runner loop | ★★ | ★★★ (Guardrails) | Handoff | Supported | Optional | Python-native simplicity |
| Codex | Product | while | ★★★ | ★★★ | Supported | Supported | Strong, default sandbox | Sandbox-first approach |
| Gemini CLI | Product | while | ★★★ | ★★★ | Supported | Supported | Yes | Google ecosystem integration |
| Cursor | IDE | while | ★★★ | ★★★ | Supported | Supported | Yes | IDE-native Coding Agent |
| Cline | Plugin | while | ★★★ | ★★★★ | Supported | Supported | Yes | Open-source and highly learnable |
| Aider | CLI | map-reduce | ★★ (Repository Map) | ★ | None | No | No | Minimalism + repository map |
| OpenHands | Platform | Event-driven | ★★★ | ★★★ | Supported | Supported | Strong, Docker | Event sourcing |
| LangGraph | Framework | Explicit graph | ★★ | ★★ | Supported | Supported | Optional | Explicit control flow |
| AutoGen | Framework | Conversation | ★ | ★ | Strong, conversational | Supported | Optional | Multi-agent conversations |
| CrewAI | Framework | Role-based collaboration | ★ | ★ | Strong, team-based | Supported | Optional | Role-based multi-agent design |
Note: The ratings above are architectural heuristics rather than standardized benchmark scores. They are intended to provide a comparative mental model, not a quantitative evaluation.
5.5 Architectural Patterns Revealed by the Comparison
The side-by-side comparison reveals several important architectural patterns.
5.5.1 Implicit Loops and Explicit Graphs Are Two Major Design Paths
Claude Code, OpenAI Agents, and Aider primarily follow an implicit-loop approach, where the model dynamically decides what to do inside an execution loop.
LangGraph follows the explicit-graph approach, where developers define the control flow explicitly.
The fundamental difference is:
Who controls the workflow?
- Model-controlled: implicit Agent loop
- Developer-controlled: explicit graph or workflow
In production systems, mature engineering teams often combine both approaches.
Use deterministic workflows for predictable processes, and Agent loops for tasks that require exploration, judgment, or dynamic planning.
This principle directly corresponds to the Agent vs. Workflow distinction discussed in Chapter 1:
Agents are better suited to unknown exploration; Workflows are better suited to known repetition.
LangGraph can be viewed as a more powerful form of explicit Workflow orchestration, while the Claude Code execution loop represents a relatively pure Agent-oriented approach.
The best architecture is often not one or the other.
It is the deliberate combination of both.
5.5.2 Context Management Is a Major Differentiator for Coding Agents
Among Coding Agents, the maturity of context management can have a direct impact on the practical ceiling of the product.
Claude Code’s strength comes partly from sophisticated context management, including compaction, budgeting, prioritization, and related mechanisms.
Aider takes a different approach through its repository map, using a compact structural representation instead of attempting to place the entire repository into the model’s context.
These approaches represent two major strategies for managing large coding contexts:
- Compression — reduce the amount of information while preserving important context.
- Indexing / Representation — provide a structured representation that allows the model to navigate a larger information space without loading everything at once.
This reveals a somewhat counterintuitive fact:
In Coding Agent competition, the winner may not simply be the Agent with the strongest model, but the Agent that manages context most effectively.
Most major Coding Agents already have access to highly capable models from providers such as Anthropic, OpenAI, and Google.
The differences in practical performance can therefore come from the surrounding Harness—especially how effectively it retrieves, prioritizes, compresses, and maintains context.
5.5.3 Security and Permissions Separate Products from Toys
Frameworks such as LangGraph, AutoGen, and CrewAI generally place less emphasis on end-user permission management and sandboxing.
Their typical assumption is:
The developer is responsible for security.
Products such as Claude Code, Codex, and Cursor have a different responsibility.
They allow AI Agents to interact with real users, real files, real development environments, and potentially real production systems.
Therefore, permissions and sandboxing become first-class product capabilities.
This leads to an important architectural principle:
Security is the boundary between an Agent toy and a production Agent system.
A framework can leave security decisions to developers.
A product cannot.
Once an Agent operates on a user’s actual filesystem, credentials, source code, or infrastructure, security becomes part of the core Harness rather than an optional extension.
5.5.4 MCP Is Becoming a Common Standard for Tool Ecosystems
Almost all major Agent frameworks and products are moving toward support for MCP (Model Context Protocol).
The importance of MCP goes beyond simply adding another integration protocol.
It changes the abstraction boundary of the tool ecosystem:
Tools can move from framework-specific implementations toward cross-framework standards.
This means tools can potentially be reused across different Agent environments.
For example, an MCP Server built for one Agent environment can potentially be consumed by other MCP-compatible systems such as Claude Code, Cline, or Cursor.
This is an important sign that the Agent tool ecosystem is moving toward greater interoperability and maturity.
5.6 How to Choose an Agent Architecture: A Practical Decision Framework
After comparing all of these systems, the obvious question is:
Which one should I use?
A practical decision framework is as follows.
1. If You Want to Use a Coding Agent
Choose a product such as:
- Claude Code
- Codex
- Cursor
These products provide a relatively complete Harness out of the box.
You do not need to build the execution environment yourself.
2. If You Want to Learn How Coding Agents Work
Study:
- Cline — open source and transparent
- Claude Code — for a deep architectural case study
- Aider — minimal and easy to understand
These projects provide different perspectives on Coding Agent implementation.
3. If You Want to Build an Agent Application
Consider an SDK such as:
- Claude Agent SDK
- OpenAI Agents SDK
These SDKs provide an appropriate abstraction level without requiring you to reinvent the entire Agent runtime.
4. If You Need Precise Control Over Execution Flow
Consider LangGraph.
Its explicit graph model allows developers to define, inspect, test, and control the execution path.
5. If You Want to Demonstrate Multi-Agent Collaboration
Consider:
- AutoGen
- CrewAI
They provide intuitive abstractions for multi-agent collaboration and role-based execution.
However, be cautious about applying multi-agent patterns to real production engineering tasks. Adding more Agents does not necessarily make a system more reliable.
The Core Decision Framework
The most important point is not to memorize which framework is “best.”
Instead, ask two questions first:
Question 1: Are you trying to use an Agent or build one?
- Use → Product
- Build → SDK / Framework
Question 2: Is your task deterministic or exploratory?
- Deterministic → Workflow / Graph
- Exploratory → Agent Loop
Once these two dimensions are clear, the architectural choice becomes much easier.
The real skill of an AI Application Architect is not knowing every framework.
It is knowing why a particular architecture is appropriate for a particular problem.
Chapter Summary
This chapter compared 12 major Agent frameworks and products and established a common architectural coordinate system.
The key takeaways are:
1. Product vs. Framework
Products such as Claude Code and Cursor provide a relatively complete Harness, while frameworks such as LangGraph and AutoGen focus more on providing the building blocks for Agent execution.
2. Two Major Execution Models
There are two major architectural paths:
- Implicit loop:
while+ model-driven decision making - Explicit graph: state machine + developer-defined control flow
3. Claude Code’s Distinctive Position
Claude Code stands out primarily because of its Harness completeness, covering context management, tools, permissions, subagents, MCP, persistence, sandboxing, and human interaction.
4. Four Major Architectural Patterns
The comparison reveals four important patterns:
- Context management is a major differentiator for Coding Agents.
- Security and permissions separate production products from prototypes.
- MCP is becoming a common standard for Agent tool ecosystems.
- Implicit loops and explicit graphs represent two major approaches to Agent control flow.
5. A Practical Selection Framework
Start with two questions:
Are you trying to use an Agent or build one?
and
Is your task deterministic or exploratory?
These two questions provide a practical starting point for selecting an Agent architecture.
With this architectural coordinate system established, we can now move into Part II, where we examine the most important components of the Agent Harness in depth:
- Chapter 6 — Context Engineering
- Chapter 7 — Tool System
- Chapter 11 — Permission System
These chapters will move from comparing architectures to understanding how a production-grade Agent Harness actually works.



