Writing / Repost
What a night of agents costs
One night of agents, measured call by call, and the context threshold that minimises the cost.
Between midnight and 1 pm on 6 October 2026, my agents made 4,057 Claude Code calls and 4,936 DeepSeek calls. The Claude calls came to $415 at the providers' list prices. The plan charges a flat fee, so that figure is the equivalent list-price cost, a unit of account, not a bill. The lead agents spent 81% of their share re-reading their own context. The context size that minimises cost per call has a closed form. On the measured numbers it is about 160,000 tokens for Claude and 200,000 for DeepSeek Flash. Claude Code's default automatic compaction threshold is about 967,000 tokens; that is a ceiling, not the measured optimum.
The setup
Intent is the agent harness I'm building to replace opencode for my own work. That night it was also the thing being built. One Claude Code session led each of two repositories, apeiron and intent. A lead reads the plan, writes briefs, dispatches workers, checks what comes back and commits. Workers ran as Claude subagents (Opus and Sonnet), as DeepSeek Flash sessions inside opencode, and as Gemini 3.8 Flash jobs in Antigravity. Every build went through one shared cargo lock.
Each route has its own meter:
| Route | What I pay | What the meter shows | Per-call log on this machine |
|---|---|---|---|
| Claude Code, Max 5× | flat monthly | a percentage of a 5-hour window and of a week | transcripts: tokens by class, compactions, limit messages |
| ChatGPT plan (Codex CLI, desktop app) | flat monthly | a percentage of a week | Codex CLI: tokens and the meter itself; desktop app: none |
| DeepSeek API | $40 a fortnight, prepaid | dollars | opencode: tokens and cost |
| Antigravity | flat monthly | a percentage per model family | one line per job, no timestamp |
| Vertex, OpenAI API, OpenRouter, Space Bunny | credits or free | dollars or nothing | opencode |
Only DeepSeek bills money as it goes; the credit routes show dollars against a grant. The rest show a percentage, so the first job is to find a unit in which the percentage is linear.
A unit for a flat-rate plan
Claude Code writes every call to a transcript under ~/.claude/projects, with its token counts: uncached input, cache reads, cache writes (5-minute and 1-hour) and output. It also writes a per-session cost-state record with its own dollar figure. That figure fits Opus 5.5 at $3 input and $15 output per million tokens, and Sonnet 5.5 at $2 and $10, with cache reads at a tenth of input and writes at 1.25× (5 minutes) or 2× (1 hour). 124 of 140 session records fall inside the bounds that table allows. Of the other 16, thirteen Opus records are up to 14% below it, and two Opus and one Haiku record are above it. The Haiku one includes web searches, which are priced separately. I don't know why the Opus ones are off. I priced every call at that table, after deduplicating by message and request id.
The window that opened at 5:50 hit its limit at 10:11, when the sum read $192.3. The next window opened at 10:50. When its meter showed 35%, the sum read $66.0, which is 34.3% of $192.3. Two readings agree to within one point, so these dollars are a linear unit for the plan, and the 5-hour cap is about $192. Another $14.90 was recorded inside that window after the limit message, almost all of it from subagents already running. I haven't established how the limit treats calls in flight.
Commits give a rough outcome rate. Since midnight, intent's main gained 17 commits for $143 of Claude spend, $8.40 each. Apeiron's gained 39 for $272, $7.00 each.
Where a call's money goes
A model call is stateless. Every call sends the whole conversation: the system prompt, the tool definitions, every message and every tool result so far. Prompt caching makes the repeat cheap, a tenth of the input price, but it is paid on every call. The lead makes many small calls, about 100 an hour with a median of 10 seconds between them, on a large context, so reading dominates. A subagent starts fresh and pulls in files, so writing is a larger share of its cost.
So the cost of a call is linear in the context it carries:
c(C) = p_r·C + p_w·g + p_o·oIn words. c of C equals p r times C, plus p w times g, plus p o times o
a call pays the read price on the whole context, the write price on what is new, and the output price on what it writes
Variables. C context tokens at the call; g new tokens per call; o output tokens per call; p_r, p_w, p_o dollars per token for a cache read, a cache write and output
For the leads that night, the mean context was 399,000 tokens and g averaged 1,857 new tokens per call (median 1,238).
Compaction is an order quantity
Compaction trades one cost for another. A long context costs reads on every call. A compaction costs a summary, a rebuilt cache, and the work of fetching again some of what the summary dropped. A shop deciding how much stock to order at once makes the same trade: stock on the shelf costs a little per unit per day, and every order has a fixed cost. Ford Harris solved that in 1913 ("How many parts to make at once", the economic order quantity), and this is the same equation.
Let b be the context just after a compaction and K the context at which the next one fires. Between the two, context grows by g per call, so a cycle lasts (K − b)/g calls, and the average context is b + (K − b)/2. One compaction costs a read of K plus a fixed part E:
E = p_o·s + p_w·(W + R)In words. E equals p o times s, plus p w times W plus R
the summary is paid as output, the new prefix is written to the cache, and the work the summary dropped is fetched again
Variables. s summary tokens; W tokens written to the cache on the first call after the compaction; R extra tokens fetched in the next 40 calls, over the growth of the 40 calls before
Averaged over a cycle, the cost per call is
f(K) = p_r·(b + (K − b)/2) + g·(p_r·K + E)/(K − b) + p_w·g + p_o·oIn words. f of K equals p r times the average context, plus g times the cost of one compaction over K minus b, plus the per-call write and output
a high threshold makes every call read more; a low one compacts more often
Variables. K the threshold in tokens; b the context just after a compaction; the rest as above
The first term rises with K and the second falls. Setting the derivative to zero gives
K* = b + √(2·g·(b + E/p_r))In words. K star equals b plus the square root of two g times b plus E over p r
compact once the context has grown past its floor by the square root of twice the growth rate times the compaction cost, counted in token reads
Variables. K* the cost-minimising threshold; E/p_r the compaction cost in units of one cached token read
The fourteen compactions in my transcripts give b = 71,000 tokens (51,000 to 90,000), s = 14,000 (10,600 to 19,100), W = 44,000 and R = 24,000. A compaction takes a median of 85 seconds. At Opus prices E is $0.63, the price of 2.1 million cached token reads, so K* = 160,000.
Three things follow.
Only price ratios enter K*. Opus and Sonnet have the same ratios, so a Sonnet lead has the same K*. DeepSeek Flash's ratios differ. A cache hit costs $0.003 per million tokens, a miss $0.15 and output $0.60, reasoning included; those three prices reproduce opencode's own cost record for each of 78,000 calls to within 10⁻¹⁵ dollars. That checks the arithmetic from tokens and prices to the recorded cost. It is an internal consistency check, not an independent measurement of the provider's bill. Output costs 200 cache reads on DeepSeek and 50 on Claude, so a compaction costs DeepSeek more reads, and its K* is 198,000 on b = 19,000 and g = 2,542.
The bottom of the curve is flat. With r the ratio of K − b to K* − b, the part of f that depends on K grows as (r + 1/r)/2. Compacting at 300,000 costs 18% more per call than at 160,000. At 400,000 it is 36% more, and at the default 967,000 it is 151% more. The transcripts also show compactions at 164,000, 292,000 and 468,000. The effective threshold varies, so 967,000 is a ceiling rather than a fixed policy.
A threshold names a compaction cost. I set Claude Code to compact at 400,000, because at 200,000 it seemed to spend more time compacting than working. The time measures smaller than that. At 200,000, an 85-second compaction comes every 69 calls, about every 40 minutes, so roughly 4% of wall time. Solving the K* equation for E, 400,000 is the optimum when a compaction costs $8.70. The tokens account for $0.63. The remaining $8 is whatever a compaction loses that a token count doesn't see: a decision the summary dropped, a question asked twice, a result checked again. That is an outcome, and nothing in the transcripts measures it yet.
Two smaller rules
The cache has two lifetimes. A 1-hour write costs 2× the input price and a 5-minute write 1.25×. When the next call comes after its entry has expired, the whole context is written again. Use the hour when
P(gap > 5 min)·p_w5·C > (p_w1 − p_w5)·gIn words. the chance of a gap over five minutes, times the 5-minute write price, times C, is greater than the price difference times g
take the longer lifetime when the expected rewrite of the whole context costs more than the premium on the new tokens
Variables. P(gap > 5 min) the measured share of gaps between consecutive calls that exceed five minutes; p_w5, p_w1 the write prices for the two lifetimes
For the leads, 4.5% of gaps exceed five minutes, so the hour wins by 16 to 1 ($0.067 against $0.004 per call). Claude Code already uses it. For subagents, 2.7% of gaps exceed five minutes, and the two sides are within 8% of each other.
The second rule is whether to read a file inline or send a worker. A token that enters the lead's context is written once, then read on every call until the next compaction, so it costs p_w + p_r·(K − C)/g. Delegate when
(T − d)·(p_w + p_r·(K − C)/g) > SIn words. T minus d, times the price of a token held in context, is greater than S
send a worker when the tokens it keeps out of the lead's context cost more than the worker does
Variables. T tokens the task would add inline; d tokens in the worker's digest; S the worker's cost
At the default threshold, halfway through a cycle, a token held by an Opus lead costs $98 per million. A Sonnet subagent's median task cost $1.64, so delegating paid above 17,000 tokens. At K*, a held token costs $13 per million and the break-even rises to 124,000. A smaller threshold makes inline work cheaper, so the two rules have to be set together.
Across routes
DeepSeek shows money, and it shows more than the ledger has. From midnight to 12:30, the dashboard billed $8.84 for 7,715 requests. Opencode recorded $6.36 for 4,936 of them. Most of the other 28% is probably intent's own evaluation runs, which call DeepSeek directly and record no cost. Those runs not recording cost is a defect in intent, and it is the first thing the ledger work fixes.
Opencode's DeepSeek sessions were served 98.9% of their input from cache. A bounded lane cost $0.05 to $0.21, so $40 a fortnight buys about 12 lane-hours a day.
Codex writes the plan's meter into its own log on every call. Only Codex does this among these harnesses. Between 3 and 5 October the weekly meter went from 3% to 99%. Plotted against Codex's tokens alone it rises too fast, because opencode's calls to gpt-6.1-sol used the same plan. With those added, it rises at 1.1 to 1.3 points per million tokens, so a week is about 80 million. It also jumps twice, by 13 and 16 points, with no logged tokens in between. Those jumps are the ChatGPT desktop app, which keeps no log on this machine.
How many agents fit
A route has budget windows. Window w has a budget B_w that refills every T_w. A mix of agents fits when
D + Σ_k N_k·c_k ≤ B_w / T_w for every window wIn words. D plus the sum over k of N k times c k is at most B w over T w, for every window
the lead's draw plus every worker's draw fits under every window's refill rate
Variables. D the lead's draw per hour; N_k the number of agents of kind k; c_k one agent's draw per hour; B_w, T_w a window's budget and length
The 5-hour window allows $38.50 an hour. Per hour of activity, an Opus lead at 400,000 tokens drew $18, an Opus subagent $12.40 and a Sonnet subagent $7.20. One Opus and two Sonnet subagents beside the lead come to $45 an hour. At that rate the window lasts 4.3 hours, and the window from 5:50 hit its limit after 4.35. I had set one Opus and two Sonnet as my limit by feel, so the feel was slightly over. A Sonnet lead compacted at K* would draw about $5 an hour. That leaves room for two Opus subagents and one Sonnet.
Build lanes have a second ceiling that money doesn't lift. There is one cargo lock. Let h be the share of a lane's time spent holding the lock. More than 1/h build lanes only adds to the queue.
Into intent
Intent currently compacts at a fixed fraction of the model's window: ratio_permille, set by hand, in Budget::derive (crates/intent-agent/src/model_loop/window.rs). It should compact at K*, computed from its own records. g and b come from its prompt-token counts, s, W and R from its own compactions, and the prices from the route's declaration. Each rule above becomes a pure function on integers (micro-dollars, tokens and an integer square root). Aeneas can extract it from the Rust source and Lean can prove it. The core lemma is the integer form of the bound behind K*:
s = ⌊√c⌋ ⟹ x² + c ≥ 2·x·sIn words. if s is the integer square root of c, then x squared plus c is at least two x s
no growth before compaction does better than the one the integer square root picks, up to the rounding of the root
Variables. x tokens of growth before a compaction, a natural number; c = 2·g·(b + E/p_r), a natural number; s its integer square root
Owed. a pure_core row for the threshold function in intent's proof register (planned)
It follows from (x − s)² ≥ 0 and s² ≤ c. The planner, the cache-lifetime choice and the delegation test get the same treatment. Intent should also log every call it makes, with its cost and, where the route reports one, the meter reading next to it, as Codex does. That record is what makes the outcome term measurable.
What this does not claim
- One night on one machine, from the logs on it. The prices are the table that Claude Code's own records fit. They are not a price list.
- K* is a model with measured terms. Nobody has yet run the same work at several thresholds and compared cost per landed commit. Until then the optimum is a prediction.
- R is the difference of two noisy averages over fourteen compactions, and two of the fourteen are negative.
- The compaction cost that matters most, lost decisions, is not measured. Intent owns its loop, so it can count re-asked questions and reverted commits after each compaction. Claude Code's transcripts can't.
- The figures I gave on the night itself used older, higher prices. These replace them.
- Antigravity logs one line per job, with no timestamp. One Claude Opus job there used the last 39% of a weekly quota in 216 seconds, about $1.90 at the prices above, so that quota is about $5 a week. One sample.
- The ChatGPT desktop app's use is visible only as jumps in the Codex meter.