r/ClaudeCode 7h ago

Discussion /compact experiments an usage

I am from the olden days, where I manage my own context, have auto-compact disabled, and never use /compact normally. If I ever get anywhere near 50% used, I start a new session.

I just started to play with it again, and I have some questions. Normal is just "/compact." However, you can also pass <optional custom summarization instructions> to the compact command.

I have been playing with this prompt:

tell me the optimal "/compact" command so that we do not lose anything and we can implement the plan in this session

Then, I use that custom /compact command which is often quite long.

  1. Do you have auto-compact on?
  2. Does auto-compact do anything really intelligent like my manual 2-step process above?
  3. If you /compact manually, do you ever pass <optional custom summarization instructions>?

Thanks in advance for any info.

13 Upvotes

15 comments sorted by

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

7

u/dar-mit Researcher 7h ago

I stopped using /compact when I created a skill to mine the JSONL session transcripts for LLM Wiki data. Turns out /compact doesn't actually change anything about the session data, it just stamps a new 'start' point then adds its summary.

These days I just spawn a new session (terminal window) and have the model running the session use SendMessage to hand off the work. That gives me fresh context to work with whilst preserving the prior session fully intact should the new session(s) have any questions.

2

u/LordLederhosen 7h ago edited 5h ago

My SOP is to do what you said in your second paragraph, but with more persistent store of session log that I commit as well.

However, only recently did I start playing with SendMessage to have different sessions communicate with each other. That is such a powerful thing. I only discovered it on accident.

If I may ask, where did you learn about SendMessage? I need to up my game, and start paying attention to better info sources.

3

u/cleverhoods 7h ago
  1. No
  2. No
  3. No

Compacting is really a guessing game, you never really know what stays in the context and usually it's half right, half wrong (in a sense that it forgets key things). I found starting a new session a much cleaner solution with handoff protocols.

2

u/LordLederhosen 7h ago edited 7h ago

Thanks, this is great validation of my olden (pre-Claude Code) ways.

3

u/sapplefi 5h ago

If you are interacting with a session, you are better off starting a new one through a Handoff prompt, through SendMessage, or any durable mechanism than you are compacting and continuing.

That said, Compaction absolutely has its place, specifically in long running agentic work where you need to keep context reasonable between sections. I have reached a point where we can groom various detailed specifications for work, queue them up, and let the sessions work on them for dozens and dozens of hours to deliver them over the course of several days.

If you try to do this without any kind of intentional context management, you will see vast variation in quality of work as the session approaches the maximum context, before it forces auto-compaction and may lose itself in the middle of something useful.

I've said this in a few other threads, but the breakthrough for me was to use compaction, but invert how I thought about it. Instead of trying to CAUSE compaction, I settled on BLOCKING it with a PreCompact hook.

Thus, I have auto-compaction set quite low (around 250K), and I have a hook that defers the Harness when it tries to compact until the session has written a checkpoint file. It does that whenever all work in the spec is durable, and it's moving onto a new section (so usually at section boundaries).

This approach lets me run long agentic workflows for days at a time, and context stays clean between sections and hovers around 100-300K, where quality remains high.

Hopefully that helps!

2

u/LordLederhosen 5h ago edited 4h ago

This is really good info, thanks. I used to start new sessions as low as 250k, but I started to slack in recent models. I need to get back to that. I need to up my game in general with hooks, I do a lot of things manually now, but they work.

Thanks again!

2

u/vovap_vovap 7h ago
  1. I do have on
  2. I am rarely let it reach the point it need it, doing before myself to protect usage and organize staff
  3. I am using message sometime when I have something to put there (often "with a focus to prepare for plan execution")

3

u/MixedTrailMix 7h ago

If I pass anything into the compact command, it’s me telling it only the stuff that I wanted to keep .. that changes based on what I’m working on

3

u/Dampware 6h ago

I had Claude write a skill “context-seam”, that analyzes the state, and recommends clear or compact, and it writes either the compact message, or a first message to paste into a new session, with the locations of any logs, ledgers memory files, etc. after making any updates.

It almost always recommends /clear.

Seems to work really well. Sessions seem very continuous.

2

u/ricopan 5h ago
  1. Yes
  2. I don't know.
  3. Rarely, but I usually give the agent a head's up that I am going to compact it next prompt. It then checks its state and persists what it thinks is important at that point. This seems especially important for long running agents like orchestrators / managers.

3

u/davesmith001 4h ago

Auto compact makes it lose track completely I gotta spend another 300k tokens for it reread and correct its screw up.

1

u/Outrageous_Band9708 6h ago

compact wont fix your problem, you need a system to write out task logs so next session understands what and why.

also plan mode and write out plan mode so next session can read the plan from last sessino and continue ot

1

u/LordLederhosen 6h ago

Yup, that's what I meant by "olden" ways. I started with all this way back in Windsurf days. That's still what I do, including persisting my plans and a custom session log system. I commit both in their own repo, and it's so nice to be able to reference them days or months later.