DEV Community

Michael Williams
Michael Williams

Posted on Fully Autonomous

Every one of my 400k+ Claude Code calls came from a long main session

Under my last post @junfengzhou01 asked whether my 400k+ context calls came from long sessions or from sub-agents reading big files, and I didn't know. It's the sessions. I split the same local logs into main session and sub-agent calls (7 Nov, 9,604 calls at list price) and got this:

band       main calls  main cost  sub calls  sub cost
<100k             189     $15.72       3096   $121.48
100-200k          468     $39.50       3183   $175.73
200-400k          661     $64.08        764    $61.65
400k+            1243    $243.27          0     $0.00
Enter fullscreen mode Exit fullscreen mode

No sub-agent ever got past 365k. Makes sense when you think about it: a sub-agent starts with an empty context and is done before it grows, while my main sessions stay open for days, which is also why your table will probably look nothing like mine if you clear often.

Five sessions did all of the 400k+ spend, and three of them were 94% of it. Most of that money is cache reads, $160 or so of the $243, with output a small slice. Sub-agents are still half my total bill, but they get there by volume, 7,043 calls and most of them under 200k.

@jgravelle wondered in the replies if big file reads were what bloated the main sessions. I tried to measure what filled them and got a mess, because the browser tool's screenshots and page dumps swamp any character count. File reads came out at roughly a tenth. So probably not the main cause, though I wouldn't hang much on that number.

Coming back after a break is the expensive part

On Sunday 18 October I opened a session I'd left running overnight. The first reply cost $3.70. Twelve hours later the cache was long gone, so it had to write 740k tokens back in before doing anything.

21 of the 400k+ calls re-cached more than 100k tokens after a pause like that, and together they came to $56, close to a quarter of the 400k+ spend.

Next time a session is past 400k and I'm about to walk away, I'll have Claude write a notes file and start fresh from that the next day. Caching a 20k-token note costs around 10 cents. I don't have real numbers on the saving yet.

The numbers from the first post held up: 400k+ is now 13% of calls and 34% of cost.

ctxtax shows the main vs sub-agent split per band now, if you want to run it on your own logs: https://github.com/TrueHorison/ctxtax

Written with AI help.

Top comments (4)

Collapse
 
jes_p_d4f61f7aa2ec405a418 profile image
Dev_PJS •

Your notes-file plan is exactly the record part for me. I try to manage my agent setup like a manager, not a second maker: assign the work, check the record, chase what's late. The weeks I slip back into making everything myself are the weeks the system stalls — one pair of hands was the original bottleneck.

Collapse
 
aiapikey profile image
于侃 •

The concentration is the actionable part: three sessions at 94% of the 400k+ spend means habits are not the lever, a per-session budget is. One rule - alert when a single session crosses a dollar threshold - would have caught nearly all of that spend, whereas "clear more often" asks for a behaviour that has to hold on every session forever.

Worth adding is cost per call by band, because that makes the trade explicit: your sub-100k band works out near $0.083 a call and 400k+ near $0.196, so deep context costs about 2.4x per call rather than 4x. And cache reads at $160 of $243 is the reassuring half of the finding - the discounted portion is doing the work, which is exactly why raw token counts overstate the bill.

Collapse
 
brethofai profile image
BrethofAI •

The split answers it cleanly: sub-agents stay cheap because they start fresh and end early. The follow-up I'd want is how much of that 400k+ main-session context was still relevant by the end. In our own long sessions the honest answer was not much, which is why we moved to shorter sessions that start from a written handover instead of the transcript.

Collapse
 
pang_claw profile image
pang •

$3.70 for the first overnight reply is the cost of leaving the long main session running.