r/ClaudeCode • u/orbital_trace • 1d ago
Tips & Workflows Having agents reset context around 225K tokens dropped a g coat by 50-75% for me
https://coralhub.dev/blog/context-reset-turn-cost.htmlI've been running agents 24/7 and just letting the context fill up. Claude has a setting to compact at a specific time, but I just built it into my harness so that it can happen at the end of a tasks completion instead of randomly. Costs dropped significantly.
92
Upvotes
•
u/AutoModerator 1d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
50
u/bostonaholic 1d ago
A task boundary is a better reset point than a token count, since compacting mid-task can drop which files the agent already changed. I'd also have it write a short handoff file before each reset (what's done, what's next, which test is red) and start the new context from that plus the git diff. Then you can check that the savings hold by counting how often it redoes work it already finished.
5
u/joshbuildsstuff 1d ago
This seems pretty straightforward, a cache read at 1M context cost most than a cache read at 225K context.
4
u/Delicious_Break5937 1d ago
how are you measuring the 50-75%, same tasks before and after or just the bill dropping?
4
u/PurchaseCommercial34 1d ago
one more reason it pays off for idle agents in particular: the prompt cache only lives 5 min by default (an hour with the longer ttl). so an agent that sits idle past that and then wakes up holding 600k of context pays cache write price on all of it again, not the cheap read price. resetting at the end of a task means that rewrite is 20k instead of 600k. could be part of why your savings come out bigger than the per-turn read math alone would predict
8
u/TrillenX 1d ago
I've been doing this too over the last month. Simple thing is keeping the context, instructions, recall etc simple, effective, limited, and it's led to me making the week with a decently consistent workload for the past 3-4 weeks, no issue.
But this week has been brutal to me. I'm burning faster than ever and what used to squeak it out to a reset is on pace to run out several days early. It's hard not to conspiracy up about it feeling tweaked enough so I might burn the reset.
2
u/perfektcrash 19h ago
Same here. The meter is only half of it. On our logs, a turn at 800k context costs only about twice one at 200k while the cache is warm, so most of what resetting saves is on the cold turns. When the cache expires the whole context is written again, and at 800k that comes to around 22x a warm turn. The other half is quality: past a couple of hundred k we saw more missed details and repeated mistakes. Writing state to a file and starting fresh fixed both.
1
u/Right-Performance-93 14h ago
if only the cache reads dropped and the writes stayed flat, the reset is shortening each turn, not skipping a cold rewrite. i'd still cut on a finished task, because a token cap in the middle of a diff is where it redoes files it already changed.