Lesson13 min

Session Management

Course-correcting early, clearing often, and recognizing when a conversation has rotted past saving.

The skill nobody teaches

Most Claude Code frustration isn't prompting — it's session hygiene: knowing when to interrupt, when to rewind, and when to declare a conversation dead. The mechanics take five minutes to learn. The judgment about when to use them is this lesson.

Interrupting and rewinding

Esc stops Claude mid-action, context preserved. The moment you see it heading the wrong way — wrong file, wrong approach — stop it then. Watching a wrong approach complete, out of politeness to a language model, just makes the cleanup bigger.

Esc+Esc or /rewind opens checkpoints. Every prompt you send creates one, and you can restore the conversation, the code, or both to any earlier point. "Undo that" works for simply reverting changes.

Checkpoints change the economics of risk: try the ambitious refactor — if it fails, rewind to the pre-attempt state and try differently, having lost only minutes. Without checkpoints you'd hedge; with them, bold attempts are cheap.

Clearing: the two-failures rule

/clear wipes the conversation and starts fresh (your code and CLAUDE.md persist — it's the conversation that resets). Use it between unrelated tasks, always: leftover context from the auth bug actively misleads work on the CSS task.

The less obvious rule: after two failed corrections on the same issue, stop correcting. /clear and write a better prompt that incorporates what the failures taught you. A session that has gone wrong twice is full of poisoned context — wrong attempts, your corrections, half-applied fixes — and every subsequent response is conditioned on that debris. A clean session with a better prompt almost always beats a long session with accumulated corrections.

The debugging spiral, concretely: two wrong fix attempts on a build failure, then —

/clear
The build fails with [exact error]. The root cause is likely in the
token refresh path (src/auth/refresh.ts). Fix it and verify the
build succeeds.

Solved in one pass. The two failures weren't wasted — they told you where the root cause lives, and that knowledge went into the fresh prompt instead of rotting in the old session.

Compaction and side questions

When a long session nears its context limit, Claude Code summarizes older history to make room — compaction. You can steer it: /compact Focus on the API changes tells it what to preserve. Better, set policy once in CLAUDE.md: "when compacting, always preserve the list of modified files and test commands." (And recall from the hooks lesson: a SessionStart hook with a compact matcher can re-inject critical context deterministically after compaction.)

/btw answers a side question in an overlay that never enters conversation history — "what's the syntax for a TypeScript mapped type?" answered without polluting the session with an off-topic exchange.

Sessions across sittings

/rename names a session; treat named sessions like branches — one per work stream. claude --continue resumes the most recent session, claude --resume picks from a list. Multi-day work doesn't have to start cold each morning.

The failure patterns

Recognize these five and you'll know when to reach for each tool:

  1. The kitchen-sink session. Auth bug, then CSS, then dependencies, then a feature — one session. Context from each contaminates the next. Fix: /clear at every task boundary.
  2. Correcting-over-and-over. Five attempts at steering a session that keeps misfiring. Fix: the two-failures rule.
  3. The over-specified CLAUDE.md. Rules accreted until the model ignores the file entirely. Fix: the litmus test from the memory lesson — prune.
  4. The trust-then-verify gap. Accepting "done, tests pass" without evidence, discovering otherwise at commit time. Fix: demand the test output; better, the Stop-hook gate from the hooks lesson.
  5. Infinite exploration. An unscoped "investigate the codebase" filling the window with file reads. Fix: scope it narrowly, or push it into a subagent.

The common thread: context is a finite, degradable resource. Long sessions accumulate not just information but misinformation — failed attempts, superseded decisions, stale state. The instinct to preserve a long conversation because it "has so much context" is usually backwards: what it has is debris. Distill what mattered into a good prompt or a CLAUDE.md line, and start clean.

A useful self-check at any point in a session: "If I started fresh right now, what would I put in the first prompt?" If that imagined prompt captures everything that still matters, the rest of the conversation is dead weight — clear and send it. If you can't write it, you've found the context actually worth keeping.