
Claude Code vs Codex: Cost Per Task, Measured

Across six months of my own logs, one coding task cost a median of $6.74 in Claude Code and $1.90 in Codex, measured over the same twelve days. That is a 3.5x gap. What surprised me is where it comes from: per million tokens the two tools are within 19% of each other. Claude Code is not billing at a higher rate. It is moving 28 times more tokens.
Every comparison of these tools I could find compares pricing pages. This one compares receipts. Below is what I actually spent, parsed from the files the tools write on my own machine, priced turn by turn at published API rates.
What was measured, and what was not
This is one developer's real history on real work, not a controlled benchmark. That is the trade: nobody ran the same synthetic prompt through both agents, but nothing here is a contrived task either. It is what shipping a product with these tools actually costs.
The specifics:
- Source. Local session logs. Claude Code writes JSONL under
~/.claude/projects, Codex under~/.codex/sessions. No API dashboard, no vendor reporting. - Pricing. Published per-token list rates for the model on each turn, applied separately to input, output, cache reads and cache writes. Cache reads are billed at the cache rate, not the input rate, which matters enormously and is the reason most estimates run high.
- A "task" is one continuous working session: turns sharing a session id, split wherever there is a gap of more than 30 minutes. It is the closest honest unit to "I asked for a thing and got it."
- Window. February to August 2026 in full. The headline comparison uses the 12 days in that period where both tools were used, so neither gets credit or blame for a week the other sat idle.
One framing note that matters. I am on subscriptions, so these are not the amounts I was invoiced. They are list-price equivalents: what this same work would have cost through the API. That is the only basis on which two tools with different billing models can be compared at all, and it is also the number that tells you whether your subscription is a bargain.
The headline numbers
Twelve overlapping days, July 3 to August 1, 2026.
| Claude Code | Codex | |
|---|---|---|
| Tasks | 100 | 17 |
| Median task | $6.74 | $1.90 |
| 25th percentile | $1.72 | $0.37 |
| 75th percentile | $17.03 | $3.13 |
| Most expensive task | $146.21 | $8.78 |
| Median turns per task | 30.5 | 36 |
| Median minutes per task | 19 | 6 |
| Tokens | 1,316M | 46M |
| Cost per million tokens | $1.08 | $0.91 |
| Cache hit rate | 99.96% | 94.2% |
Read the last two rows before the first one. The rate is nearly identical. The volume is not.
And note the turn count. Codex used more turns per task in this window, 36 against 30.5, while costing a third as much. It is not doing less work. Each turn is simply carrying far less context.
Over the full six months the totals were $3,048.89 across 223 Claude Code tasks and $71.12 across 35 Codex tasks. Different amounts of use, so compare the medians, not the totals.
Why one tool costs 3.5x more per task
The cost gap is a context gap. Claude Code moved 1.3 billion tokens in twelve days against Codex's 46 million.
Look at what those tokens are:
| Bucket | Claude Code | Codex |
|---|---|---|
| Fresh input | 0.04% | 5.7% |
| Output | 0.58% | 0.54% |
| Cache reads | 95.6% | 93.7% |
| Cache writes | 3.78% | 0% |
Over 95% of everything Claude Code sent was a cache read, which is exactly what a healthy agent loop looks like. A large context gets written once and re-read on every subsequent turn at a fraction of the input rate. At 99.96%, only half a million of the 1.3 billion tokens sent were fresh input. That is the system working close to perfectly.
It is also why the raw token number is useless on its own. If you had only been told "1.3 billion tokens" you would have guessed a five-figure bill. It was $1,422.
Two structural differences drive the rest:
- Cache writes. Anthropic charges a premium to park context in the cache. In this window that premium was 3.78% of all tokens moved. OpenAI does not bill for cache writes at all, so Codex's cache-write column is a hard zero. Same technique, different meter.
- Model tier. Nearly all of the Claude Code spend was Opus-class. The observed blended rates: Opus 5 at $0.79 per million tokens, Fable 5 at $1.71, Opus 4.8 at $1.03, Sonnet 5 at $0.58, Haiku 4.5 at $0.18. On the Codex side, GPT-5.6 Sol at $0.88 and GPT-5.5 at $1.10.
That Haiku line is the one worth staring at. It is nine times cheaper per token than Fable 5 in real measured use. Model choice is a bigger cost lever than tool choice, and it is entirely under your control.
Half your money is in a handful of tasks
The distribution matters more than the average, and it is lopsided.
Across all 223 Claude Code tasks:
- The top 10% of tasks consumed 48.2% of total spend
- The top 25% consumed 73.3%
- The bottom half of all tasks accounted for 8.8%
- 41 tasks cost under $1. Fifteen cost over $50. One cost $146.21
Codex is flatter, top 10% at 34.5%, but the shape is the same.
This is the practical finding. The mean task cost of $13.67 describes almost none of my tasks. Trimming the cheap majority would save nothing. Knowing which handful of sessions ran away, and why, is where the money actually is.
In my case the expensive tail is consistent: long refactors across many files, where the context grows every turn and gets re-read every turn after that. The cost of a task scales with how long the agent stays in one conversation, not with the difficulty of the problem.
What this means if you are choosing
Some of this generalizes and some does not. Being clear about which:
Probably true for you too. The rate difference between these tools is small and the volume difference is large. Cost per task tracks context size and session length far more than it tracks which agent you picked. Spend concentrates in a few long sessions. And your cache hit rate, if you can see it, is the single most informative number available.
Specific to me. The 3.5x median gap reflects the work I gave each tool. I reach for Claude Code on large multi-file changes and Codex on narrower ones, which is most of the gap right there. Codex also has a much smaller sample, 17 tasks against 100.
The actual takeaway. Do not choose a coding agent on published token rates, because at real cache hit rates the effective rates converge. Choose on the work, then control cost with the two levers that actually move: model tier, where the measured spread was nine to one, and session length, where the top 10% of sessions carried half the spend.
If you are on a subscription, the number worth knowing is the one above: what your usage would cost at API prices. Six months of my Claude Code work priced out at $3,048.89 in list-price equivalent. That is the real value of the plan, and you cannot see it from an invoice that says the same amount every month.
How to check your own numbers
Every figure here came from files already sitting on the machine. Nothing was instrumented, and no wrapper was installed. The tools write these logs whether or not anyone reads them.
You can read them yourself. Claude Code's JSONL is plain text, one JSON object per line, with a usage object on every assistant turn. Codex is the same shape in a different directory. The work is in canonicalizing model names, deduplicating resumed sessions, and applying the four rates correctly, which is what TokenMaxxer does with the same parsers that produced this post. It reads the logs locally, keeps the four counters apart, and prices each turn against current published rates.
If you only take one number from this: find your cache hit rate. Below 60% on agent work means you are paying full price for context the provider already has.
Frequently asked questions
Is Claude Code more expensive than Codex?
Per task, yes, by roughly 3.5x in this data: a median of $6.74 against $1.90 over the same twelve days. Per million tokens the two are close, $1.08 against $0.91. The gap is driven by how much context each tool carries per task, not by the rate it bills at.
How much does one coding task cost with an AI agent?
In this sample the median was $6.74 in Claude Code and $1.90 in Codex, at published API rates. The spread matters more than the median: a quarter of tasks came in under $1.72 and the most expensive single task cost $146.21.
Why is my token count so high but my bill so low?
Because most of those tokens are cache reads, billed at a fraction of the input rate. Over 95% of the tokens in this dataset were cache reads. A 1.3 billion token month cost $1,422, which is around $1 per million.
How do I reduce what a coding agent costs me?
Two levers moved the numbers here, and neither is switching tools. Drop to a cheaper model tier for work that does not need the top one, where the measured spread was about nine to one per million tokens. Then keep sessions short, because context is re-read on every turn and the longest 10% of sessions carried roughly half of all spend.
What is a good cache hit rate for a coding agent?
High. Claude Code measured 99.96% and Codex 94.2% over the comparison window. Anything below about 60% on sustained agent work means context is being rebuilt from scratch most turns and you are paying the full input rate for it.
Does switching models save more than switching tools?
In this data, yes. The measured spread across models was about nine to one per million tokens, from $0.18 on Haiku 4.5 to $1.71 on Fable 5, while the spread between tools was under 20%. Model tier is the larger lever.
Are these the amounts you were actually billed?
No. They are list-price equivalents, meaning what the same work would cost through the API. Both tools were used on subscriptions. This is the correct basis for comparing tools with different billing models, and it is also how you tell whether a subscription is worth it.
Sources
- Measured from local session logs, February 12 to August 3, 2026: 223 Claude Code tasks and 35 Codex tasks
- Per-token rates from the vendors' published pricing, as carried in TokenMaxxer's model registry
- What is tokenmaxxing? for why raw token totals mislead
- Anthropic prompt caching documentation
- OpenAI prompt caching documentation
One developer's usage on one codebase. Different work produces different numbers, which is the argument for measuring your own rather than trusting anyone's benchmark, including this one.
