Ask a coding agent to "fix this bug" and it reads the code, changes a line, runs the tests, and tells you it is done. The bug we handed over took Claude Code 12.8 seconds and Codex about 20 seconds.
But something is odd. The model inside each agent has never seen your code. It cannot open a file or run a command. It only writes text. So who fixed the bug?
The answer is a loop. Once you see it, you can tell why an agent reads the same file again, why it forgets what you said earlier, and why it sometimes goes around in circles.
In this post we look at, in order:
- The model only writes text: tool lists and tool requests
- The same bug, given to Claude Code and to Codex
- The loop in the Codex source
- The model has no memory: tokens sent per call, and caching
- When the conversation fills up: truncation and compaction
- Why agents go in circles
- Two layers of safety: approval and the sandbox
- Undo: checkpoints and git
How to read the numbers. [Official docs] means material published by Anthropic. [Measured] means numbers we measured ourselves on our Mac. [Source] means we read and confirmed it in the public Codex repository (
openai/codex, commit54201ea). Measurements were taken October 31 to November 1, 2026, with Claude Code 2.1.316 (Claude Opus 5.5) and Codex CLI 0.164.0 (GPT-6.1 Sol). The companion video is in Korean.
1. The model only writes text
What a model does is simple. Text goes in, text comes out. It has no ability to open files or run commands. Ask it to fix code it cannot see and all it can do is guess, sometimes inventing files that do not exist.
So the agent program gives the model a list of tools before your request: read a file, search, edit, run a command. Even then the model cannot do these things itself. It just writes a short request: "please run this command."
- When the model wants a tool, its reply contains a
tool_useblock and stops withstop_reason: "tool_use". - The application runs the request on your machine and sends the result back as a
tool_result[Official docs] (Tool use).
Claude Code and Codex are that application. Anthropic's docs call this layer around the model, which handles tools and context, the agentic harness [Official docs] (How Claude Code works). In short: agent = model + agentic harness.
In the Codex source, when it builds the request to the model, it puts the list of usable tools into the tools field (core/src/session/turn.rs, lines 1758–1764) [Source].
2. The same bug, two agents
The task is a small Python project that computes shipping fees. Orders of 50,000 won or more ship free, but there is a bug: an order of exactly 50,000 won still gets charged shipping. The condition uses > and should use >=. The prompt was just this:
There's a bug where shipping is still charged when the order total is exactly 50,000 won. Fix it.
Claude Code: four model calls
We set it up to print one line per model call. [Measured]
- Call 1: asks for the file list. Part of the search command errors out, and that error goes back to the model as the result.
- Call 2: reads three code files at once.
- Call 3: changes one line and runs the tests in the same step. Result: OK (3 tests pass).
- Call 4: the summary answer we see.
It took 12.8 seconds in total. That is the actual wait including CLI startup; the processing time the CLI logged was 11.5 seconds. [Measured]
Codex: five model calls
We gave the same bug to Codex (clean config folder, writes allowed only in the workspace). [Measured]
- Calls 1 and 2: look at the file list and find the shipping code.
- Call 3: reads the code and runs the tests first to confirm they really fail.
- Call 4: changes one line, then runs the tests and
git diffagain. - Call 5: the summary answer.
It took 20.2 seconds. The order differs a little, but the work is the same: the model asks, the program runs, the result is appended to the conversation, and the model is called again. This repeats until the model answers without requesting a tool.
3. The loop in the Codex source
In the Codex code this cycle is literally a loop (turn.rs, line 490). While handling one request, it keeps going around inside it. [Source]
- On every pass it copies the entire conversation history and sends it to the model. That is the
clone_historyline (lines 589–601). - If the model's reply contains a tool request, it runs the tool and sets
needs_follow_uptotrue, meaning "go around once more" (stream_events_utils.rs, lines 365–368). - If there is no tool request, it exits the loop (
turn.rs, line 750). That is the moment the model says it is done.
4. The model has no memory
Here is the part many people miss: the model has no memory. So every call resends the whole conversation from the start: instructions, tool descriptions, your request, the files read, the test results, everything. The more calls, the more it sends. When an agent seems to read the same file again, it is because the model cannot remember what it saw and receives it all again each time.
Codex requests carry store: false (core/src/client.rs, line 1163), meaning "do not store this conversation on the server." Codex holds the conversation and sends it every time. [Source]
Tokens sent per call
Here is how much Claude Code sent on each call. [Measured]
| Call | Input tokens sent | Read from cache | Newly sent |
|---|---|---|---|
| 1 | 17,211 | 11,266 | 5,945 |
| 2 | 17,406 | 17,209 | 197 |
| 3 | 17,917 | 17,404 | 513 |
| 4 | 18,303 | 17,915 | 388 |
| Total | 70,837 | 63,794 (90.1%) |
About 70,000 tokens to change one line, roughly $0.08 at API prices. Codex was nearly the same: five calls of about 14,000 to 15,000 tokens each, 73,631 tokens in total, 90.9% of it from cache. [Measured]
Prompt caching
Prompt caching reuses stored computation when the beginning of a request is identical to last time. [Official docs] (Prompt caching)
- Cached input is billed at 0.1× the base input price. For Opus 5.5, which we used here, it is 0.05×, one twentieth.
- But the prefix (tools → system → messages) must match 100%. If anything changes up front, everything from that point on is recomputed.
That is why sending the same content many times does not blow up the cost.
5. When the conversation fills up: truncation and compaction
So agents treat the conversation like a budget.
- Claude Code: command output goes in as-is up to about 30,000 characters. Beyond that, it saves the output to a file and shows the path plus the first 2,000 characters. File reads are capped at 25,000 tokens [Official docs] (Tools reference).
- Codex: each tool result is cut to about 10,000 tokens. The model config has
"limit": 10000(models-manager/models.json, lines 15–18). When output overflows, it keeps the head and tail, cuts the middle, and adds a marker saying how many tokens were removed (utils/string/src/truncate.rs) [Source].
If the conversation still fills up, both agents summarize and compact it.
- Old tool results get dropped, and detailed instructions from early on can be lost. Anthropic's docs recommend putting rules that should always hold in
CLAUDE.md[Official docs] (How Claude Code works). In Codex,AGENTS.mdis reloaded into the initial context after compaction [Source]. - Codex starts compacting when the conversation reaches 90% of what the model can take (
protocol/src/openai_models.rs, lines 563–566,* 9 / 10). [Source] - The summarization prompt is public too. It asks the model to write a handoff note for another model that will take over, covering progress so far, key decisions, and what remains (
compact/prompt.md). [Source]
When an agent forgets what you said earlier, it is not carelessness. It was pushed out to make room.
6. Why agents go in circles
A weaker model that gets no search hits often tweaks a word and searches again. It does not notice it is going around in place.
We searched the Codex source (core/src) for a guard against this and found no code that watches for repeated calls. The loop ends when the model stops requesting tools, when a person stops it, or on an error. There is a comment to the effect of "as long as compaction works well, we shouldn't worry about an infinite loop" (turn.rs, line 707). It prevents the conversation from overflowing, but not repeating the same work. [Source] We did not find a repetition guard in the Claude Code docs either.
So when an agent goes in circles, a person needs to cut in and redirect it.
7. Two layers of safety: approval and the sandbox
Both agents have two layers of safety.
- Approval (permissions): asks a person before doing anything risky.
- Sandbox: the operating system blocks things while a command runs. On macOS it uses Seatbelt, on Linux bubblewrap. Writing outside the sandbox gets
Operation not permittedfrom the OS [Official docs] (Sandboxing).
The Claude Code sandbox applies to shell commands and limits writes to the working folder, the temp folder, and folders you explicitly allow. It is off by default [Official docs]. The Codex sandbox policy file starts with (deny default), "block everything by default" (sandboxing/src/seatbelt_base_policy.sbpl, lines 7–8), and always adds the current folder and temp folders as writable (protocol/src/protocol.rs, lines 1421–1427) [Source].
Trying it: create a file on the Desktop
We turned on the sandbox in Claude Code and asked it to create a note file on the Desktop. [Measured]
- The first attempt was blocked by the OS:
operation not permitted. - The model asked to rerun outside the sandbox (
dangerouslyDisableSandbox). - That request was denied at the permission step (one denial logged).
- The model said it could not create the file and asked what to do, offering three options. Nothing appeared on the Desktop.
Codex is similar. When the sandbox blocks a command, it tells the model to ask again with a reason to run outside (require_escalated + justification), and a person must approve before it runs outside (on_request.md, line 32) [Source].
The model does not decide what it is allowed to do. It only asks.
8. Undo: checkpoints and git
If you don't like what the agent changed, can you undo it? Here the two agents differ.
- Claude Code: every prompt that starts a turn creates a checkpoint. From the
/rewindmenu (or Esc twice) you can restore code and conversation together, or just one. But files changed only through shell commands are not tracked, and the docs say to use git for those [Official docs] (Checkpointing). - Codex: it used to make file copies called "ghost snapshots," but the current code says snapshots are no longer produced (
core/src/config/mod.rs, lines 237–238). The conversation-rewind feature is documented as changing only conversation history and not reverting local file changes (app-server-protocol/src/protocol/v2/thread.rs, lines 1308–1310) [Source].
So when working with Codex, commit to git often.
Summary
When you ask for a fix, this loop runs several times inside. The model writes a request, the program runs it, and the result is appended to the conversation before the model is called again.
- The model makes the decisions.
- What it can see and touch is set by the outside program (the agentic harness).
- The model has no memory, so it gets the whole conversation every time, and caching keeps that from getting expensive.
- When the context fills up, compaction can push out early instructions, so put rules that should always hold in
CLAUDE.mdorAGENTS.md.
Next time an agent does something impressive, or something strange, think of this loop.
Limits of this check
- This is one one-line bug, given once to each agent. Call counts and tokens vary with the task, settings, and model. When we ran the same task twice more in an environment with personal settings, Claude Code again made four calls, but the first input was larger, so it sent around 130,000 tokens in total. [Measured]
- The Codex source is as of commit
54201ea. With the OpenAI provider, compaction happens server-side, so the public summarization prompt is for other providers. Line numbers and behavior may change in later versions. - None of these mechanisms makes a weak model smart. They stop wasted effort and risky actions, but if the model picks the wrong fix, they only help it be wrong faster and more safely.
Watch the video
We walked through the same material with real runs and the Codex source on screen (in Korean).
Sources
- Anthropic, Tool use overview
- Anthropic, Prompt caching
- Claude Code docs, How Claude Code works
- Claude Code docs, Tools reference
- Claude Code docs, Sandboxing
- Claude Code docs, Checkpointing
- OpenAI, openai/codex — commit
54201ea:turn.rs,stream_events_utils.rs,client.rs,models.json,truncate.rs,openai_models.rs,seatbelt_base_policy.sbpl,protocol.rs,config/mod.rs,thread.rs













