How we raised savings on Claude Code, Codex, Pi and OpenCode
Plans changed on 2026-11-24. See current plans at /pricing.
Context Mode sits between your coding agent and the model. Each agent builds its requests in its own way, so a method that saves money on one agent can do nothing on another. This post shows what we changed for each agent, how we measure, and what we tried that did not work. The measured figures are on Benchmarks by agent, with a public evidence file for each one.
The short version
- Keep the cached part still. Lines that change per session move out of the start of the request, so the provider can read that start from cache.
- Fit each agent. Pi and OpenCode each get their own adapter. For Codex, we edit the request where it is, instead of moving its bytes to a new place.
- Send less tool output, and lose none. Passing tests fold to a short summary. Large output is cut only after it is saved in full, with a note that says how to read it back.
- Fewer model calls. Short hints help the agent fix and rerun in one call, and a loop guard stops it from running the same failing check again and again.
- Measure it straight. The same tasks run direct and through Context Mode, on the same model and the same reasoning effort, and a run counts only if its task check passes.
The seven tasks
These are the same seven tasks on Benchmarks by agent:
- npm test fix loop (about 600 tests): run
npm test, fix the bug that makes one test fail, run the tests again. - Test fix loop (minitest): the same in Ruby.
- Repo history question (git log, 320 commits): find the commit that changed a default, and name its hash and author.
- Code search (grep over 150 files): find the files that call a function with one option.
- One large JSON file (800 orders): read one field of one order in a saved API response.
- One-line edit: change one value in a config file and nothing else.
- Large document processed with a script (npm registry, several MB): fetch the npm registry document for React and report its version count, its tags and two publish dates.
Each task has a check. The test suite must pass, the hash and author must be right, the file list must be exact. A session that misses its check does not count as done, whatever it cost.
What we measured
Each agent ran the seven tasks twice: once direct to the model provider, once through Context Mode. The figures below are the ones on the benchmarks page. Each figure links to its evidence file.
- Claude Code, Claude Haiku 4.5: 91.1% lower cost, 28 of 28 runs passed through Context Mode.
- Codex, GPT-6.2 Sol (default effort): 62.6% lower cost, 28 of 28 runs passed through Context Mode.
- Pi, Claude Haiku 4.5: 74.5% lower cost, 28 of 28 runs passed through Context Mode.
- OpenCode, Claude Haiku 4.5: 78.4% lower cost, 27 of 28 runs passed through Context Mode.
The cost of each task, in each arm, and every run, are on that page. The same tasks on T3 Code are there too. Method for the earlier published Claude Code runs: the benchmarks docs.
1. Keep the start of the request still
Every model call sends the whole conversation again. The provider can read the part that did not change from cache, and a cache read is cheap. On Claude Haiku 4.5, per million tokens, fresh input costs $1, a cache read $0.10, a 5-minute cache write $1.25 and a 1-hour cache write $2 (Anthropic prompt caching, read 2026-12-03). The cache only works for the part of the request that is exactly the same as before, starting from the very first token.
So the first rule is to keep the start of the request still:
- Move per-session lines out of the start. Pi and OpenCode put lines that change every session, like the date and the working folder, into their system text. Context Mode moves them after the stable part. The text does not change, only its place.
- One hour for what stays, five minutes for the rest. The stable start gets a 1-hour cache mark, because the next session reads it too. The fast-moving end of the conversation gets the 5-minute mark.
- No cache write that nothing will read. A 5-minute write costs 1.25 times fresh input. When a call is very likely the last one of a session, Context Mode does not mark it for caching.
The 4,096-token floor on Haiku 4.5
A provider only caches a prompt above a minimum length. Anthropic lists 4,096 tokens for Claude Haiku 4.5. A start shorter than that is not cached, even if it is marked for caching, and every call pays the fresh-input price for it.
So when an agent's stable start falls just under the floor, Context Mode adds working notes for the agent to that start, so it crosses the floor and gets cached. When it is well above the floor, we trim what the agent does not need. Short tasks of two or three calls, such as a one-line edit or a git-log question, feel this floor most: every call still reads at least those 4,096 tokens.
2. An adapter for each agent
We first ran Pi and OpenCode through the same methods we built for Claude Code. The tasks still passed, but the saving was small, and on the large JSON task the cost was not lower. The methods were aimed at a request shape these agents do not send.
So Context Mode now spots Pi and OpenCode from their own system text and applies an adapter for each:
- The per-session lines move behind the stable start, as above.
- OpenCode sends some tool definitions that a session never uses. Context Mode drops the unused ones from the request.
- OpenCode asks the model for a short title for each new session. Context Mode writes that title from the first message instead of paying a model call for it. It only changes the name in your session list.
- Hints that name a tool use that agent's own tool names.
Claude Code requests stay exactly the same with or without these adapters.
Codex: stop moving its bytes
Our first Codex measurement through the gateway did not save money. Context Mode had moved some of Codex's messages into a new place in the request, and the provider's cache no longer lined up. The fix for Codex is to edit Codex's own bytes where they are, and to change nothing that does not need to change.
Codex has two more limits. Its backend rejects the setting that asks for a longer cache, and it rejects explicit cache marks. So for Codex, keeping the request still is the only cache method there is.
3. Send less tool output, and lose none
A tool result is paid for on every later call, not once. Context Mode makes the large ones smaller, with one rule we do not bend: it never cuts data and leaves it looking whole.
- Passing tests fold. The failing test and its output stay whole. The passing lines fold into a short summary. That is the part the agent needs to fix the bug. More on folding.
- Large output is cut only with a full copy. When a long output is shortened, the full output is saved first, and the note in its place says it was shortened and gives the search to read the rest. If the full copy cannot be saved, the output goes to the model whole. A cut with no note is the only data loss that looks like no loss, so we do not allow it.
4. Fewer model calls
Each model call reads the cached start again and writes new output. Fewer calls is often the biggest saving left after caching. Context Mode adds short hints to tool results at the point where they help:
- Fix and rerun in one call. When a test run fails, the hint says: fix the cause, then rerun the tests and show the result in the same call. After a change of ours, this hint stopped firing on Pi and OpenCode. We found that, put it back, and those test-fix tasks used fewer calls.
- Print what the question needs. For a large output, the hint says to save it to a scratch file and print only the lines the answer needs, instead of reading the whole file into the conversation.
- Write the answer out. The user does not see tool output. When an agent answers "the versions are listed above", the user gets nothing. So the hint asks for every requested item in the answer itself. A short answer that skips the facts is an unfinished task, not a saving.
A loop guard watches for an agent running the same failing check again with the same failure. When it sees that, it suggests making the check print each case with its input, expected and actual value, so the agent can see which case broke.
How we measure
- Direct against Context Mode. The same task, the same agent version, the same model. One arm calls the provider directly, the other goes through Context Mode.
- Quality first. A session counts only if its task check passes. We read the answers too, because a check can pass on text that would not help you.
- No shortcuts. We never lower the reasoning or thinking effort, and we never send a request to a cheaper model. Memory, skills and recall are off in these runs, so the saving is from the methods in this post.
- Small first, then confirm. We try ideas on one or two sessions per task, and confirm the ones that win on four.
What did not work
- Distilling script output. We tried shortening what the agent's scripts print. On the large document task, the agent's answer had to copy those lines. Both Pi and OpenCode missed the check, so we dropped it.
- Codex's own warm cache. Codex's stock request start is already warm in the provider's cache. Restoring it exactly made the first call read most of that start from cache, yet every task got worse. A warm cache is not the same as a cheap request. We reverted it.
- A very small Codex start. Cutting it further put it under the provider's cache minimum, so almost nothing was read from cache within a session. We went back.
- A self-checking edit command. On Codex, an edit command that checks its own result made the one-line edit task worse: the model ran its parts as separate commands, which meant more calls.
- Our own note made Pi waste calls. A note on editing files led Pi to call its edit tool with empty input. A rewritten note that names the edit tool's required fields made that rare.
Where the rest of the cost is
Context Mode does not touch the model's answer or its reasoning. On the large document task, a large part of what's left is the answer the model has to write, so cutting input only goes so far. On the one-line edit, Pi writes its change as a longer shell command while OpenCode uses its own edit tool; that difference in output shows up in the two rows on Benchmarks by agent.
Try it
Install your agent its own way, then connect it to Context Mode with one command. Your own Anthropic or OpenAI account pays the model.
- Set it up: Quick start, or one gateway for 7 coding agents.
- How the cache layout works: Prompt caching and How saving works.
- The figures, and every run: Benchmarks by agent. Earlier published Claude Code runs: Benchmarks.