CloudCodeTree LogoCloudCodeTree
AI NewsTutorialsAbout
CloudCodeTree Logo
CloudCodeTree
  • AI News
  • Tutorials
  • About
← Back to AI News
Don’t /clear a Long Claude Code Session — /compact It

Don’t /clear a Long Claude Code Session — /compact It

Chris Harper

2 min read

Aug 31, 2026 · 04:07 UTC

AI
Workflow
Claude Code
Best Practices

TL;DR: /compact replaces your accumulated session history with a dense summary, keeping task context intact. Use it at the two-thirds mark so you never hit the context wall mid-task.

When you /clear a long session, you lose everything — the decisions made, the files reviewed, the wrong paths ruled out. Your next prompt starts from scratch. /compact is the alternative: it compresses the conversation history in-place, preserving what matters while discarding the accumulated back-and-forth.

What it does

/compact fires a summarization step over your current session history and replaces it with a dense summary. The session continues — same working directory, same file state, same current task. You get back a large chunk of your context budget without losing track of where you are.

Claude Code also fires /compact automatically when your context reaches approximately 95% capacity. If you let it hit the wall, compaction happens anyway — just at a worse moment, mid-response.

When to use it manually

  • Context meter is past the two-thirds mark and you're entering a complex phase (writing tests, refactoring a second module, reviewing a PR).
  • You just finished a long exploratory phase (reading through files, debugging, iterating on a design) and are now switching to execution.
  • A subagent call came back with a large result that consumed most of your remaining budget.

Optional: guide what gets kept

/compact Focus on the auth middleware decisions and the three files we agreed to change.

The instruction follows the command. Without it, Claude picks what to preserve. With it, you direct the summary toward the decisions most likely to matter for the next phase of the task.

Real limit: you can’t /rewind past the compaction point

/rewind walks back to a previous checkpoint — but compaction replaces history, not adds to it. Once /compact fires (manually or automatically), you cannot rewind into the pre-compaction conversation. If the summary gets a decision wrong, your session inherits that error. Before compacting a session where you’ve made important choices, consider whether a quick note to yourself about those choices is worth the extra 30 seconds.

Sources: Context compaction — Claude Platform docs · Claude Code compaction and long-session guide — hidekazu-konishi.com · Context compaction research — GitHub gist (badlogic)