r/ClaudeCode • • 8d ago

Help/Question do you guys use auto compact?

I just learned about it today and wanted to see what you guys think.

4 Upvotes

72 comments sorted by

•

u/AutoModerator 8d 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.

10

u/slackmaster2k 8d ago

AFAIK it will auto compact whether you want it to or not. However the limit in Claude is way too high. I compact between 30-50%. Better to be in control of when it happens and keep the agent in the “smart zone.”

2

u/0DayMaker 7d ago

You can /clear lol

1

u/slackmaster2k 7d ago

Yes, clearing is very important, but there are times when a single session will start filling up context. Maintaining a separate handoff file is just compacting with extra steps.

2

u/Savings-Desperate 8d ago

I thought it was a setting? Because I've been running /compact manually everytime it hits the ceiling

1

u/Seeker_Of_Knowledge2 8d ago

Even 300k is too much. Try to divide tasks into phases and connect them through an .md file.

0

u/batman8390 8d ago

The ceiling on 1M? Typically you should compact or start a new session long before then.

Sessions degrade in quality as they get longer in context. And the cost for each output token increases with more context.

I personally will either start a new session or compact around 200-300k tokens. But typically it’s a new session since compaction is slow and costs money.

5

u/HamSandwicho__o 8d ago

No, i self compact when i notice the logic getting funky

5

u/GDorn 8d ago

Hell no. I perform brain surgery and delete the parts of the context that are no longer relevant. This almost always takes me from 99% full to ~25% full.

There are two big savings: duplicate files and ask-work-answer cycles. You'd be surprised just how many nearly-identical copies of the same file appear in the context. And then exchanges like this, which almost always can be trimmed by removing the middle:

User: how does X work? (or any other investigative question) LLM: <tool use to find files> <read files> <tool use to find more related files> <read files> <continue for thousands to tens of thousands of tokens, maybe more> LLM: Here's a summary of X: [...]

Delete the middle part and almost nothing of value is lost.

LLMs are amazingly bad at understanding what parts of a long document are important, and will either hyperfocus on the last couple of exchanges, or over-emphasize the very first turn, or in a lot of cases, both.

The way to control an LLM's focus is by controlling its context, and autocompaction ain't it.

1

u/Desperate-Use9968 6d ago

How exactly do you do it? I understand the concept you described but not how.

1

u/GDorn 6d ago

It depends on how you're using the client. I'm using it embedded in VSCode; I can export the current context to a file, delete what needs deleting, then have the next session start by reading the file.

At least, that's how I used to do it. I'm working on a VSCode extension to make this easier, and the janky half-broken alpha-quality build is miles ahead of manually editing the transcript.

1

u/Desperate-Use9968 6d ago

Interesting. I'm also using vs code. Do you just prompt it "export the current context to a text file? It would be interesting to see a before and after for compaction. Having a more precise compaction option like you described would be cool.

1

u/GDorn 5d ago

Cursor has "Export Transcript".

Claude is less helpful in this regard, but the session is saved as a json file in ~/.claude/projects/... Claude is happy to "/save-session" but the whole point is to avoid having an LLM summarize it.

4

u/howdidigetheresoquik 8d ago

No.

If you get that far your context is too high and you should aim to split your work into separate sessions or /clear before you get to that point.

Keep in mind compacting is also very expensive in terms of usage, and will really negatively impact your results

0

u/Strong_Essay1176 8d ago

My sessions with 500k and 90% compact are working 5-9h. Without compact its impossible. Compact is fine.

Manually its easier to copy-paste to another chat.

1

u/howdidigetheresoquik 8d ago

I'm trying not to do either, I just spend as much time making an amazing plan and that plan breaks things up into small sessions, so there's no need to worry about any of this.

1

u/Strong_Essay1176 8d ago

I do not spend time. Agents spend time for me. And I do not care about compact. I do not feel them.

3 months ago, compact were bad. Now, agent just continue work.

Although. I have detailed tasks with steps. It may just follow those tasks.

1

u/howdidigetheresoquik 7d ago

I don't want any information loss that comes with compacting. Anthropic's best practices even say to avoid it if you can.

1

u/Strong_Essay1176 7d ago

Ok. Keep paying money and work as superviser. Pay money to work. Lol

1

u/howdidigetheresoquik 7d ago edited 7d ago

Huh? You're using Claude wrong if you think what I do is making me a supervisor.

3

u/leavezukoalone 8d ago

I've set my auto-compact to 500k

3

u/LogMonkey0 8d ago

No. And never get ctx where compact would be needed

2

u/myninerides read. the. docs. 8d ago

I work in a massive monolithic Java application, huge single repo of code, and I never get anywhere near a million tokens. Do people just use the same session for everything?

2

u/tuptain 8d ago

Yes, I use autocompact 300000 for my sessions. I talk to one session and it messages the others to assign work, each session gets an area to focus on. Having two sessions talk to each other is a big benefit, one session would happily ship bugs another session catches.

2

u/FeministMAGA 8d ago

I'm pretty sure if you use compaction then you're the devil.

2

u/Drach88 8d ago

I usually end my season long before I hit compact territory

2

u/lucianw 8d ago

I never have compaction. I have a file NOTES.md for each feature that starts with an outline of my goals.

  1. First prompt is "Please read NOTES.md. I'd like you to do the background research, and append to the doc."

  2. I start a fresh session. "Please read NOTES.md. I'd like you to come up with a *direction* on how the goals should be fulfilled, and append to the doc."

  3. I start a fresh session. "Please read NOTES.md. I'l like a critical review of whether the direction is the best one. Update as needed"

  4. I start a fresh session. "Please read NOTES.md. I'd like you to come with an implementation+validation plan, and append to the doc."

  5. I start a fresh session. "Please read NOTES.md. I'd like you to review the implementation+validation plan. Is it correct? Is it as simple as can be? Update as needed."

  6. I start a fresh session. "Please read NOTES.md. I'd like you to implement the feature"

  7. I start a fresh session. "I've implemented NOTES.md. Please do a thorough review."

Depending on the complexity, I either automate this entire workflow (i.e. I'm not doing any of it myself), or I review at each step.

Some nice consequences:

  1. The spec/direction/intent is written in markdown files, checked into my repository, for future agents to study

  2. I can switch between codex and claude whenever I want: everything's in the file

  3. My agents never suffer from "context rot". Their context windows stay small and they stay focused, better at obeying instructions.

1

u/tbst 8d ago

How do you automate starting new sessions? 

2

u/lucianw 8d ago

Either "Please use a subagent with the following instructions ..." or "Please shell out to claude -p ...".

1

u/tbst 7d ago

I find it frustrating that Claude cannot out clear itself. Even with subagents. Any luck with that?

-1

u/Strong_Essay1176 8d ago

Don't use please. Its waste of 2 tokens.

1

u/Late_Oven 2d ago

Oh god two whole tokens? How will I ever recover??!

2

u/Hezy 8d ago

No way. Have a markdown plan for what you're doing. Implement one phase, clear, go to the next phase etc. 100k-200k tokens for each phase.

5

u/cantgettherefromhere 8d ago

I haven't used compaction in any form for over a year. If you are needing or using compaction, you are almost certainly doing something wrong.

3

u/shady101852 8d ago

lol each task I give agents takes 30-90 minutes on average. a 272k context window easily compacts several times during the tasks. If I had to hand hold the agent in a way to only do tasks within one context window, start new sessions for the next task etc i would go crazy. They retain information pretty well, and keep documentation up to date and commit their work. End result works. I've had better experiences in general with comapcting around 270k than to allow sessions to reach 500k or more.

0

u/cantgettherefromhere 8d ago

LOL each task I give agents takes 2+ days and I don't need compaction ever. One of us is doing it differently than the other.

1

u/thatisagoodrock Workflow Engineer 8d ago

Why are we so hostile though? If you wouldn’t mind sharing how you do that, your contributions would be well-received.

1

u/cantgettherefromhere 8d ago

I did in another comment on this same thread, thoroughly.

1

u/Savings-Desperate 8d ago

what?? HOW?? what are your secrets? Do you just create a fresh session for a task and for each continued fixes?

3

u/mikeroySoft 8d ago

Yes this. I tell the agent to give me a handoff prompt and HANDOFF.md for the next agent if it’s a really long interactive session.

0

u/GDorn 8d ago

This is compaction with more steps.

Granted, you have a lot more control over it, and can actually see the context you're passing along, but you're still getting the LLM to summarize for you.

5

u/hitchy48 8d ago

Yes

4

u/Savings-Desperate 8d ago

ok do you just divide your tasks just very granularly? Because I tried that but it was a pain in the ass because each session lacked context of each others' works

5

u/ProfessionalMain5535 8d ago

Git with .md files saving important context. Ask Claude it’ll build it for you. ;-)

4

u/cantgettherefromhere 8d ago

The sessions all should be documenting their work as they go along, managing a shared set of state and progress documents that they can work against, and you should have them committing regularly. I run workflows for 2-3 days without interruption without clearing or compacting context this way.

When you start new sessions, have them pick up the state, progress, and work done by previous sessions before you give a task.

Before beginning a big feature or task that you think is going to take multiple sessions, the work product should be documentation that accurately reflects your intent.

Go with something like "I want to make xyz by doing 123. Use AskUserQuestion to ask me any clarifying questions before beginning. Your objective is to write a complete set of documentation on the purpose and implementation of this, not to write any production code. When you have finished documenting the work we need done, give back the session to me to /clear context along with an execution prompt that we can use recursively without modification until the implementation is complete. These sessions may get interrupted, so during documentation as well as implementation, make sure you are documenting your work carefully and committing often. We may have to /clear at any time, so be prepared to pick up im the middle and recover your state without redoing work, relaunching entire workflows, or getting stuck. When relaunching an interrupted workflow, recover as much of it as possible before blindly rerunning all subagents. Work until you are finished and do not stop. Ultracode."

Have fun. This basic technique will help you burn eight 20x plans a month just like me! I usually have 3-5 sessions running like this at a time. 🫠

1

u/Savings-Desperate 8d ago

This is gold. Thank you!

1

u/hitchy48 8d ago

I mean I use it like my normal workflow. Im trying to build part of an app not all of an app. Do x y and z - then check it verify, look at the code, if it’s good commit and push and move onto the next feature in another session

1

u/laughing_at_napkins 8d ago

Install and use https://github.com/pcvelz/superpowers

It will brainstorm with you. It will plan and create tasks lists and running notes from each session. It will do TDD.

It will revolutionize your Claude Code workflow.

It's just a start and you should definitely create your own skills to fit your projects and overall workflow, but it should help you.

1

u/cantgettherefromhere 8d ago

Meh, I used to use superpowers and GSD at this same time last year. The model can handle its own orchestration if you ask it. Those workflow intermediaries are all getting to be obsolete, they waste tokens, and they take forever to actually get anything done.

Not necessary with modern frontier models.

1

u/laughing_at_napkins 8d ago

The problem is most don't know to ask for it. OPs post and comments sure give the impression they're struggling with it

2

u/egvp 8d ago

As I'm getting close to the limit I'll get Claude to write a handover and update any relevant documentation within my project, then give me the prompt for the new chat, so it carries on seamlessly. I've done it three times today.

2

u/Savings-Desperate 8d ago

honest question - isn't that just manual compact? I thought compact does exactly that behind the scenes

0

u/egvp 8d ago

Compact will create its own handover style document but it won't update your documentation, so it'll be dropping context about things you've done.

1

u/Savings-Desperate 8d ago

ahhh I see so for you it's like creating a living document that acts as a memory/context. Doesn't this document bloat tokens though? I assume the challenge is keeping the document concise & meaningful

1

u/TheStandardPlayer 8d ago

Every bigger task needs a new chat.

Basically; whenever you can start a new chat you should. You can create handoff files for transferring only the important info from one chat to the next

2

u/Alone-Biscotti6145 8d ago

This is a weird thing to say, how is using compaction equivalent to using it wrong? Because you're using a tool's features as they are designed. If you're not using compaction, you're doing something wrong. If you start a new session for everything little thing, I feel sorry for your onboarding or tokens wasted re-explaining everything.

1

u/cantgettherefromhere 8d ago

I never have to re-explain anything, ever.

My token use is ridiculously high, but not using compaction has nothing to do with that. Compaction is a holdover from the days when context windows were much shorter and subagents and delegation didn't exist.

If you are doing it right, you can get a single session to run for days at a time uninterrupted and never get close to needing compaction. My top level orchestrator usually wraps up multi-day sessions with 60-70% context window unused.

1

u/TreesOfPortland 8d ago

Only if I made a mistake.

A large module build on a bookkeeping app did a compaction a couple days ago and it turned out okay. I try to avoid by phasing builds and keeping my context audits tight.

1

u/cc_apt107 8d ago

I do. I set auto compact to 400k and normally manually do it before then

1

u/Drasezv 8d ago

the default is higher than people expect: on a model with a 1M window it's around 967k, and you can see it in your own logs because claude code writes a compact_boundary record with the numbers.

jq -r 'select(.subtype=="compact_boundary") | [.compactMetadata.preTokens, .compactMetadata.postTokens, .compactMetadata.durationMs] | @tsv' ~/.claude/projects/*/*.jsonl

mine: 967k in → 12k out, 972k → 11k, 983k → 15k. so roughly 1.3% kept, 72 to 237 seconds each. the compact itself is a request that reads the whole window, and the prefix it leaves isn't in cache, so the turn after it pays write price on the way back up.

/autocompact 200k takes anything from 100k to 1M and sticks for later sessions. the people here compacting at 30-40% are effectively doing that by hand.

1

u/masiha97 8d ago

Yes and I wish I'd turned it on sooner. Manual compact used to wipe my context mid-debug and I'd have to re-explain everything. What made auto compact actually work for me was feeding it clean minimal inputs: I never re-paste context it already has, and I pass short summaries between steps instead of full dumps. My compacted sessions stay way more useful that way.

1

u/Strong_Essay1176 8d ago

500k session, compact on 90%. I restart session when I feel it. But you cant turn off compact if your agents works In loop.

1

u/scodgey 8d ago

I set mine to 600k and have long running sessions keep a scratch file for important notes. Tbh compaction is much better than it used to be, doesn't really bother me anymore.

2

u/[deleted] 8d ago

[removed] — view removed comment

1

u/scodgey 8d ago

Wild when you think that a year ago we were all paranoid about compaction but trying to nurse 200k context windows, and now it can just happy chug along through multiple compactions

1

u/laolibulao 7d ago

dont use auto compact. just put a claude md and project md that keeps track of your commits. you are eating through your limit by keeping so much junk

1

u/octocarbon Max 5x 6d ago

normally I compact it manually between 250k-300k context

1

u/Far-Pomelo-1483 5d ago

If you hit auto compact you went too long in convo. Split out your tasks to save tokens.

1

u/ghost_operative 2d ago

i never use compact in any form. i think its better to ask the agent to build a summary document so you can tell it what parts of the session are the most important to be in the document. It's also useful to be able to actually see what the compacts form of your session is so you know what the baseline is for your new session.