
What is Context Rot?
Context rot is the gradual degradation of AI agent or assistant performance that occurs as a session accumulates tokens — causing the model to lose focus on earlier instructions, contradict previous decisions, repeat itself, or fail on tasks it handled correctly earlier in the same session.
Why It Matters
Context rot is one of the most common and least-acknowledged failure modes in production AI applications. A model can handle a task perfectly at turn 5, but fail the identical task at turn 40 — not because the task changed, but because the context window is now crowded with irrelevant history that dilutes the model's effective attention.
For AI coding assistants and long-running agents, context rot typically becomes noticeable after 30–60 minutes of use. This has driven an entire category of tooling — from memory compression systems to sub-agent architectures — specifically designed to prevent or reset it.
How It Works
Context rot arises from three compounding factors:
- Attention dilution — transformer attention is distributed across all tokens; more tokens means proportionally less attention on the critical ones
- Instruction drift — system prompts and early user context receive less relative attention as the context grows
- Noise accumulation — failed tool calls, verbose API responses, and intermediate reasoning steps crowd out the signal
The result is a model that "forgets" constraints it was given earlier, reverts to default behaviors, or makes the same mistakes it corrected in turn 10.
Prevention and Recovery
| Approach | Mechanism | |----------|-----------| | Sub-agent spawning | Fresh agents with clean contexts handle isolated sub-tasks (e.g., GSD for Claude Code) | | Context compression | Raw outputs compressed to minimal summaries before injection (e.g., Context Mode) | | Memory externalization | Persistent vector databases store cross-session context outside the window (e.g., Claude Mem) | | Session limits | Hard limits on session length, with automatic summarization and handoff |
Practical Example
A developer uses a coding agent for 45 minutes. After 40 tool calls, the agent starts suggesting variable names it was explicitly told not to use in turn 3, and rewrites a function it already fixed in turn 12. The instructions from early in the session have been effectively displaced by accumulated tool output noise — this is context rot.
Source
Community pattern documented across Claude Code, Cursor, and Codex workflows (2025–2026). See: Claude Code Context Mode