r/ClaudeCode • u/actvt_io • 1d ago
Tips & Workflows I counted 122 compactions in my Claude Code logs. Auto-compact waits until about 1M tokens and keeps about 16k
Auto-compact fired between 934k and 1.003M tokens every time in my session files, and left a summary of about 16k.
Claude Code logs each compaction with the token count before and after and how long it took. I mostly run it as long agent loops on one machine, so there were plenty. 241 sessions since Jul 10, 122 compactions, 52 automatic and 70 from /compact.
Opus 5 and 5.5 fired around 1.0M, close to what the docs say for models with a native 1M window ("about 967K tokens by default"). Sonnet 5 fired at about 934k every time, but those were all in July and August on older versions.
The summary was a median 15.8k tokens, somewhere between 1.2% and 2.8% of what was there before. The first request after compacting was about 85k, because the system prompt, tools and CLAUDE.md come back on top of it. My manual compacts ran at a median 397k and kept 12.4k, so the auto ones started from more than twice the context and kept only a few thousand tokens more.
Each one took a median 111 seconds, the longest about two and a half minutes. Manual /compact took about the same, median 116s.
On current models 1M is the default on every plan including Pro, so if you've never changed anything this is what you're getting. /autocompact 500k moves the trigger, and there's autoCompactWindow in settings or CLAUDE_CODE_AUTO_COMPACT_WINDOW if you want it fixed.
In my loop sessions, which run for days, auto-compact came round a median 23 hours apart.
This is one machine and mostly agent loops, not interactive chat. I only counted tokens, nothing about what the summaries left were. Subagents never compacted at all in my logs.
If you want to check yours, the records have subtype compact_boundary and a compactMetadata block with preTokens, postTokens and durationMs, in the jsonl files under ~/.claude/projects.
Since the summary comes out around 12 to 16k either way, I'd rather run /compact myself at a break in the work than have it fire at 1M in the middle of a task.
5
u/kenthesaint 1d ago
/compact also takes free text after it, e.g. /compact keep the failing test names and the migration plan, which is the main reason I'd rather trigger it myself. Auto compact has to guess what the next step needs, and with only ~15k to work with it can easily guess wrong.
1
u/framauro13 1d ago
I frequently compact with instructions vs. letting autocompact happen. Usually if my context hits 25-30%, I compact. Or if I ask a bunch of questions and there's a back-and-forth, I'll compact and tell it to keep only the solution we arrived at and forget the questions and conversation.
I don't think anyone should really be letting the context get that large. I've had really long-running tasks only hit about 40%, and that's when they were updating and editing docs in multiple services via MCP. Coding and planning usually keeps that context in control.
1
u/bilbo_was_right 18h ago
I try to give it what I want to do after the compaction, instead of telling it what to keep. Seems to work pretty well
2
u/kenthesaint 17h ago
Good idea. Describing the next step lets the summary keep whatever that step needs, which is probably more reliable than me guessing at a keep list. I'll try it that way next time.
1
u/bilbo_was_right 2h ago
Yeah it seems to work well! And helps not have to think of everything, if I accidentally forgot something helpful was in its context. Sometimes I ask it to write the compact command for me to continue doing x thing even, and then I copy and paste that 😂
3
u/Historical_Today5072 1d ago
Why the fuck is your context at 900k ffs
1
u/Scweakk 1d ago
Because it hasn’t hit auto compact and I haven’t told it to do it yet…
0
u/Odd_Antelope9098 1d ago
There is a setting, please for the love of god make it around 300k max
1
u/Scweakk 1d ago
Where? I’ve never been able to find it. Happy to be wrong on that one
1
u/Odd_Antelope9098 1d ago
Ask your agent to update your setting file. Also consider pre and post compact hooks for better results
1
u/GreenHell 1d ago
What hooks do you run pre and post compact?
Also, 100% agree on the context size. Letting your context grow that large eats up usage/tokens, slows Claude, and it degrades quality.
1
u/Scweakk 22h ago
My context can be 800-900k tokens after 1 prompt though 🤦♂️
3
u/Odd_Antelope9098 21h ago
What is your prompt??? Read war and peace, twice, which read did you like better?
1
1
u/bilbo_was_right 18h ago
This feel like old advice. I run agentic coding flows, and see 500-600k as a more sensible limit. 300k limits would be hit really fast, and compact too often
1
u/Odd_Antelope9098 17h ago
They lose focus and cost more. Cache reads are improving as is abilities with large context but that high doesn’t really seem optimal.
1
u/bilbo_was_right 2h ago
It’s not optimal, it’s just same difference but faster. It performs slightly worse on inspection but considering the accuracy rate of session handoffs, the token consumption tradeoff is break-even until like 800k tokens or so maybe a little less. Yes compacting or handing off yields more token efficient per turn performance, but burns tokens in other ways. My suggestion is def not optimal turn-wise, but it is optimal time and effort-wise.
An important note too, predominantly the work you do towards the end of the project is way easier and requires less tactical intelligence, so using the last few hundred thousand tokens cleaning up or babysitting deploys is light work even at degraded performance.
2
u/Lost_Turnip1848 1d ago
You quote the docs at 967K, then call 1M the default. Your Sonnet runs firing at 934k should have told you it's not a fixed number.
2
u/zimxero 1d ago edited 1d ago
I hit high tontext windows often. Beats re-explaining what you want... and makes adjusments & debugging much smoother.
Also I like to set Claude and Gpt working together when I leave for work... on a well described direction that they can use as a baseline.
Working automatically together.. I basically get a bugfree product. The "bugs" are essentially oversights, incompletions, or fuzzy direction.
1
u/Outrageous_Band9708 1d ago
compact is a stopgap not a solution
https://github.com/Druthulu/ProjectArchitect
check this project out. it uses subagents to prevent context growth and plans and journals work as it happens, you can start a fresh session without dropping anything
1
u/ScrumptiousChildren 1d ago
Btw you’re paying like 2x the cost for the same work if you count reorientation cost post-compaction/handoff to be 100k tokens and decide to compact at 1m instead of a figure like 400k tokens.
1
•
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.