DEV Community

Carlos Oliva Pascual
Carlos Oliva Pascual

Posted on • Originally published at stacknotice.com

Claude Code /compact vs /clear (2026): Managing Long Sessions Without Losing Quality

You start a Claude Code session sharp. An hour in, responses get vague. Two hours in, Claude starts contradicting earlier decisions.

It's not Claude getting worse. It's what happens when a context window fills up and nobody manages it.

Full guide at stacknotice.com/blog/claude-code-compact-clear-context-2026

Why sessions degrade

As the context fills, earlier information gets less weight, contradictions between early and late instructions emerge, and Claude has less room to reason. The session that started great ends frustrating.

/compact — compress without losing flow

Summarizes earlier conversation history while keeping recent context intact. Key decisions and agreements are preserved in shorter form.

Use when:

  • Session is 45-60+ minutes in
  • You're mid-task and don't want to lose context
  • Responses are getting shorter or less precise

Preserves: current task state, key agreements, CLAUDE.md conventions
Loses: step-by-step detail from early in the session

> /compact

Claude: Summarized. Here's what I kept:
- Building checkout flow with Stripe
- Server actions for mutations (not API routes)
- Webhook handler done, working on UI next

Ready to continue.
Enter fullscreen mode Exit fullscreen mode

Session continues. No re-explaining needed.

/clear — hard reset

Wipes the conversation completely. CLAUDE.md reloads automatically.

Use when:

  • Finished one task, starting something unrelated
  • Session went the wrong direction
  • /compact isn't enough

Preserves: CLAUDE.md, your project files
Loses: everything from the conversation

The decision

Still on the same task?  →  /compact
New task or wrong direction?  →  /clear
Enter fullscreen mode Exit fullscreen mode

Patterns that help

Front-load context — tell Claude what you're building and the constraints at the start. It carries more weight early in the context.

Break large work into sessions — 4 hours of coding doesn't need one session. Finish the DB layer, /clear, start the API layer fresh.

Use /compact proactively — don't wait for quality to drop. Run it at natural checkpoints.

Reference CLAUDE.md instead of re-explaining — your conventions reload automatically. Don't waste context repeating them.

Extended thinking note

Ultrathink uses 3-5x more context per response. If you use it regularly, run /compact more aggressively — after every 2-3 extended thinking calls.


Full guide with the full decision tree at stacknotice.com/blog/claude-code-compact-clear-context-2026

Top comments (2)

Collapse
 
alexshev profile image
Alex Shev

The practical split is preserve decisions, discard incidental tokens. Compacting should keep what changed, why it changed, current constraints, open risks, and the immediate next action.

What usually breaks long sessions is not losing every detail. It is losing the one constraint that made the next tool call safe. A good handoff summary should read like operational state, not a diary.

Collapse
 
stacknotice profile image
Carlos Oliva Pascual

"Operational state, not a diary" — that's a much sharper framing than how I put it in the article. I'm keeping that.

Constraint loss is exactly the failure mode I've run into most often. Not "Claude forgot what we built," but rather "Claude forgot why we structured it this way." The next suggestion is technically correct in isolation, yet it breaks an invariant the team agreed on three turns earlier.

One thing I've started doing is putting those load-bearing constraints directly into CLAUDE.md instead of leaving them only in the conversation. That way they survive a /clear, not just a /compact.

For example:

Current Constraints

  • Server actions only — no client-side database fetches
  • This flow is already rate-limited upstream; don't add another layer
  • Auth middleware handles redirects; layouts do not

It feels redundant when you write it down, but it pays off immediately in the next session when Claude doesn't "helpfully" reintroduce a layer you've already decided against.

The remaining gap is dynamic context: constraints that emerge during the session as a result of something you've just discovered. Those usually don't make it into CLAUDE.md quickly enough, and /compact becomes the only defense.

Which is probably your point: a compact written as operational state is essentially a CLAUDE.md generated on the fly.