The /compact command in Claude Code takes a long conversation and replaces it with a lean, structured summary. It’s the fix for a session that’s grown bloated: every turn is dragging the entire history along, and each new message costs more than the last. Compacting drops that wordy history and keeps only what matters going forward.
The thing most people miss is that compacting isn’t free. It saves you tokens on every future turn, but the act of compacting consumes tokens too.
Where the tokens go
The summarization cost. When you run /compact, Claude reads your entire conversation up to that point, feeds it into a dedicated summarization prompt, and writes a structured summary. You pay input tokens to re-read everything currently in context, and output tokens for the summary it generates. This is a one-time hit.
The cache-miss penalty. This is the real gotcha. Claude Code leans heavily on prompt caching — message it repeatedly within a short window and you pay only a fraction of the cost, because the history is already cached. But if you run /compact after a long break, when the cache has expired, Claude has to re-read the full uncompacted history at full price before it can compress it. Same command, very different bill. Specifically: Anything within roughly 5 minutes of your last message hits a warm cache and is cheap. If you’re curious, you can read up on the details here and here.
The payoff. Once compaction is done, the giant history is gone, replaced by the summary plus rehydrated context like recent file states and your current TODO list. Because what’s left is dramatically smaller, every turn after that costs significantly less than it would have if you’d left the session uncompacted.
So the mental model is simple: you pay a small tax now to stop paying a large tax on every turn from here on. The trick is to pay that tax when it’s cheapest (specifically: within 5 minutes of your last message).
When to run it
Compact proactively at task boundaries. Don’t wait for the automatic compaction that kicks in around 85–95% of capacity. Run /compact right when you’ve finished a feature or squashed a bug, while the context is clean and there’s a natural seam in the work. The summary comes out cleaner too, because you’re compacting a completed unit rather than a half-finished mess.
Compact before you close the laptop — not after. If a session is getting heavy and you’re about to stop for the day, run /compact at the end of the work block while the history is still cached and cheap to read. If you wait until the next morning, the cache has expired and you’ll pay full price to reload the giant history just to compress it. Same shrink, worse timing.
Put permanent context in CLAUDE.md, not in compact instructions. If you notice yourself feeding the same project rules or structural constraints into /compact every time, that’s a sign they belong in a CLAUDE.md file instead. Claude reads that file automatically, it stays cached, and it can’t get lost or diluted during a compaction.
Used this way, /compact stops being a thing you do in a panic at 95% capacity and becomes a routine you run at the seams of your work — cheap to do, and it keeps the whole session fast and lean.