· via dev.to (home feed)
Claude Code, Codex and Pi converge on the same agent loop, diverge at the edges
An independent dev.to analysis finds three unrelated agent harnesses implementing the same five-step loop, with production loops far larger than tutorial versions suggest.

Three loops, one shape
An independent analysis published on dev.to has taken apart the agent loops of Anthropic's Claude Code, OpenAI's Codex and the MIT-licensed Pi harness, and found that three teams working in three languages with no shared code or lineage arrived at essentially the same control flow. Strip away the implementation, the author writes, and every loop reduces to five steps: build the context, call the model, execute any tool calls in the response, append the results, and decide whether to go again.
The cost of shipping that paragraph varies widely. Claude Code's query.ts weighs in at 1,729 lines of TypeScript, with the main while loop alone spanning 1,421 lines. Codex implements its loop in 983 lines of Rust, and Pi, a harness with an explicit design goal of being the small one, spends 794 lines of TypeScript on it. One caveat: the Claude Code figures come from a leaked bundle and represent a snapshot of a single build, while Codex, published under Apache-2.0 in August 2026, and Pi are on GitHub with permanent history. The author verified every number against clones taken on 2026-09-01.
Where the lines go
The five-step summary hides the hard parts, and according to the analysis those parts are what the extra lines buy. Responses stream, so tool calls can arrive before a message finishes and the harness must decide whether to start executing early. Tool calls may run in parallel or must be serialised depending on what they touch. Users interrupt mid-turn, so aborts have to unwind without corrupting the transcript. Context windows fill up, so compaction has to fire without losing the thread. Providers fail in ways that are and are not worth retrying, and approval flows can suspend the loop indefinitely while a human decides.
The author also corrects an earlier claim of their own: that open-source agent loops typically run 50 to 200 lines. Even Pi, the smallest and most deliberately minimal of the three, needs 794 lines, which suggests the real distinction was never open source versus proprietary but production code versus tutorial demos.
Three different boundaries
The interesting divergence, per the dev.to piece, is the question every harness must answer: what sits outside the loop, and how does the loop talk to it?
Claude Code keeps the boundary inside the process. Loop, tools, permission checks, compaction and UI live together and coordinate through function calls and shared state, which allows tight coordination, such as a five-level compression pipeline that can act on information the loop has not yet committed anywhere. The cost is that external programs can only drive the agent through whatever surface Anthropic chooses to expose.
Codex puts the boundary on a protocol. The agent core lives in an app-server behind a documented, bidirectional JSON-RPC 2.0 interface built on three primitives: Thread, Turn and Item. Methods include thread/start, thread/resume, thread/fork, turn/start and turn/interrupt, with streaming notifications as items begin and complete, and turn/completed carrying final token usage. Transports are stdio by default, with a Unix socket and an experimental websocket listener. The protocol even includes backpressure, returning error -32001 when request ingress saturates. The upshot is that the VS Code extension, the terminal and any third-party client are peers talking to the agent as a service; the cost is that changing wire types becomes a compatibility event.
Pi places the boundary at the extension host. It ships only four tools (read, bash, edit and write), and everything else is a hot-reloadable TypeScript extension loaded from the project, able to register tools, persist session state and render its own terminal components. Pi deliberately ships no MCP support. The cost is that the extension boundary is also a language boundary: extensions are TypeScript because the host is.
Minimalism that is not
The analysis's most counterintuitive finding concerns total size. Pi's reputation rests on minimalism, and its default system prompt measures just 550 tokens, yet its codebase totals 121,240 lines of source, within roughly four percent of Codex's core at 125,574 lines. Inside Pi, the author counts about 61,000 lines in the coding agent, 23,668 in the provider layer, 17,000 in the terminal UI and 12,640 in the agent package. The takeaway is that Pi minimises what the model has to reason about, not what its maintainers have to build.
Why it matters
For anyone building agents, the piece is a useful signal. The agent loop itself is effectively a solved pattern, and a production implementation realistically runs from hundreds of lines to well over a thousand, not the tens of lines tutorials suggest. Competitive differentiation lives at the boundary: in-process control, a wire protocol, or a runtime extension model, and that single choice constrains nearly everything else about the system. That three unrelated teams converged on the same middle also suggests the core pattern is stable enough to treat as a baseline rather than an open research question.
- #ai-agents
- #claude-code
- #openai
- #open-source
- #developer-tools