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
- The assistant re-suggests something you already rejected in this same session.
- Responses get vaguer or more generic as the conversation goes on.
- It starts mixing up details from an earlier, unrelated task.
- It "forgets" a constraint you stated clearly a few messages ago.
- If you're running a status line with context percentage, you watch it climb into the 70–90% range with no sign of slowing.
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.
| Situation | Move |
|---|---|
| Starting an unrelated task | Clear |
| Same task, context getting large | Compact |
| Long session, key decisions must survive | Compact with explicit keep-notes |
| Just wrapped up and stepping away | Clear |
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
- 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.
- Clear at every task boundary, even if the session still "feels fine." Don't wait for symptoms.
- 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."
- 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
- Never let a session run "forever." Long-running sessions accumulate noise the model can't filter out on its own — clear between jobs is the default, not the exception.
- Compacting without keep-notes is a gamble. A generic compact can quietly drop the one decision you actually needed preserved — always state what to keep.
- Watch the signals, not just the clock. Vague answers and repeated suggestions aren't the model getting worse at coding — they're the context getting worse at being useful. Treat them as your cue to act.
Building an AI feature? Yeda AI designs, audits, and ships production LLM systems.