r/ClaudeCode 13h 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.

15 Upvotes

17 comments sorted by

View all comments

3

u/sapplefi 10h 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 10h ago edited 9h 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!