Yeda AI Tips · #015

Keep Your Context Fresh: Fighting Context Rot in Claude Code

Your AI gets dumber the longer you talk to it. Not because the model changed — because the conversation did. Every file it read, every dead-end it tried, every correction you made is still sitting in the context window, competing for attention with the thing you actually need right now. Call it context rot: quality quietly drops as the chat grows, and most developers only notice after the assistant starts contradicting itself or forgetting a decision from ten minutes ago.

Why context rot happens

A model's context window isn't a scratchpad it revisits selectively — it's the entire working memory for every response. As a session runs long, that memory fills with things that were relevant to task A but are now noise for task B: half-finished plans, rejected approaches, large file dumps you no longer need, and your own back-and-forth corrections. None of that gets deleted automatically. It just accumulates, and the signal-to-noise ratio for the current task keeps dropping.

The fix isn't a smarter model — it's session hygiene. Treat context like a workspace you tidy between jobs, not a running log you let pile up.

Signals it's happening

Any one of these is a cue to intervene — not to push through and hope the next message clears things up.

Two moves: clear and compact

Claude Code gives you two levers for managing this, and they solve different problems.

Clear early, clear often. When you're switching tasks — done with the auth refactor, moving to the API docs — wipe the slate. A fresh context means the model isn't dragging yesterday's decisions into today's unrelated work. Don't wait until the session feels sluggish; clear as a matter of routine between jobs, not as a last resort.

Compact when you need continuity. Sometimes you can't just clear — you're mid-task, the session is large, and you still need what came before. Compacting shrinks the history while preserving the thread, so you can keep going without carrying the full transcript forward.

SituationMove
Starting an unrelated taskClear
Same task, context getting largeCompact
Long session, key decisions must surviveCompact with explicit keep-notes
Just wrapped up and stepping awayClear

Compact with care, not by default

The mistake is compacting blindly and hoping the summarizer keeps what matters. It won't always guess right. When you compact, tell it explicitly what to keep — your database schema decisions, your API contract choices, anything that took real back-and-forth to settle. Those are exactly the details that are expensive to re-derive and cheap to lose. Everything else — exploratory dead ends, verbose file contents you no longer need, resolved side conversations — can go.

A useful mental model: before compacting, ask "what would I be annoyed to re-explain in five minutes?" That's your keep-list. State it directly in the compact instruction rather than trusting the default summary to guess.

A concrete habit

  1. Set up a status line that shows context percentage, if your setup supports it — it turns "the AI feels off" into a number you can act on before quality visibly degrades.
  2. Clear at every task boundary, even if the session still "feels fine." Don't wait for symptoms.
  3. When you must keep going through a large session, compact with an explicit keep-note: "keep the DB schema decision and the API auth approach, drop the rest."
  4. If the assistant starts repeating a rejected suggestion or losing a constraint, that's a signal you waited too long — clear or compact immediately rather than trying to talk it back on track.

Power tricks

Building an AI feature? Yeda AI designs, audits, and ships production LLM systems.

Talk to us · Read the blog