---
title: "Context Rot"
description: "The progressive degradation of LLM reasoning performance as context length and irrelevant tokens accumulate."
section: "concepts"
type: "concept"
created: "2026-08-22"
updated: "2026-08-30"
confidence: "high"
tags: ["agents", "context-engineering", "anti-patterns"]
canonical: "https://pyweb.dev/wiki/context-rot"
---
# Context Rot

**Context Rot** is the phenomenon where an LLM's reasoning accuracy, instruction adherence, and recall degrade as the context window fills with intermediate conversational turns, noisy tool outputs, and historical artifacts.

## The Mechanism
Transformer attention is not uniform across thousands of tokens:
1. **Lost in the Middle:** Information placed in the center of a long context is retrieved with significantly lower fidelity than tokens at the very beginning (system prompt) or the very end (latest turn).
2. **Attention Dilution:** Every irrelevant token in context consumes an attention budget, increasing the probability of hallucinations and missed edge cases.
3. **Compounding Noise:** When an agent misinterprets a noisy tool result and replies with flawed assumptions, that flawed exchange remains in context, poisoning subsequent reasoning steps.

## Mitigations
- **Context Clearing (`/clear`):** Reset the context completely between distinct, modular tasks.
- **Handoff Artifacts:** Compress multi-turn discussions into clean, structured handoff documents rather than carrying raw conversation logs forward.
- **Subagent Delegation:** Offload verbose investigations (searches, log reading, scraping) to isolated subagents and return only the distilled summary.
- **Strict Progressive Disclosure:** Load references and documentation on-demand rather than dumping everything into the initial system prompt.

## Rule of Thumb

Compaction triggers on token budget pressure, not on quality degradation
you can observe - by the time answers degrade, the rot predates them.

```mermaid
flowchart LR
    A[Long session] --> B[Turns + tool outputs accumulate]
    B --> C[Attention diluted]
    C --> D[Instruction adherence drops]
    C --> E[Recall of early context drops]
    D & E --> F[Fix: compact / restart / re-inject constraints]
```

## Failure Modes

| Symptom | Root cause | Fix |
|---|---|---|
| Answers degrade on long tasks | Attention diluted by accumulated turns | Compact or restart; never let turns pile unbounded |
| Early instructions forgotten | Lost-in-the-middle placement | Re-state critical constraints at the END of context |
| Tool outputs flood the window | Verbose results kept verbatim | Summarize tool output before it enters history |

## Related
[smart zone](/wiki/smart-zone), [handoff artifacts](/wiki/handoff-artifacts), [context engineering](/wiki/context-engineering), [prompt bloat](/wiki/prompt-bloat), [subagents and context management](/wiki/subagents-and-context-management), [ai coding taxonomy](/wiki/ai-coding-taxonomy).

---

## Agent Navigation

cluster: person (170 pages) | betweenness: 82.7

### References (outbound)
- [Smart Zone](https://pyweb.dev/wiki/smart-zone.md)

### Referenced by (inbound)
- [AI Coding Taxonomy & Agent Experience](https://pyweb.dev/wiki/ai-coding-taxonomy.md)
- [Codex Harness Architecture](https://pyweb.dev/wiki/codex-harness-architecture.md)
- [Generator-Evaluator Loop](https://pyweb.dev/wiki/generator-evaluator-loop.md)
- [LLM Message Protocol](https://pyweb.dev/wiki/llm-message-protocol.md)
- [Multi-Agent Orchestration](https://pyweb.dev/wiki/multi-agent-orchestration.md)
- [Progressive Disclosure](https://pyweb.dev/wiki/progressive-disclosure.md)
- [Prompt Bloat](https://pyweb.dev/wiki/prompt-bloat.md)
- [Smart Zone](https://pyweb.dev/wiki/smart-zone.md)
- [Tool Calling Loop](https://pyweb.dev/wiki/tool-calling-loop.md)

### Evidence (verified primary sources)
- [aihero-dev-homepage-2026](https://pyweb.dev/wiki/raw/articles/aihero-dev-homepage-2026.md) | origin: https://www.aihero.dev/ | ingested: 2026-08-22 | sha256: 231157fed45f82922924a050e09b5b81a443891814fc1d72c874d864a6075419
- [agentic-engineering-trends-2026-synthesis](https://pyweb.dev/wiki/raw/articles/agentic-engineering-trends-2026-synthesis.md) | origin: https://pyweb.dev/wiki/raw/articles/agentic-engineering-trends-2026-synthesis | ingested: 2026-08-24 | sha256: 6c78ca873a4df069f1606e9f68538de7b428633720e48e184fad0ea31b5d2a25
- [aihero-ai-coding-dictionary-2026](https://pyweb.dev/wiki/raw/articles/aihero-ai-coding-dictionary-2026.md) | origin: https://www.aihero.dev/ai-coding-dictionary | ingested: 2026-08-27 | sha256: 52b0a5da7c9f6dd60dfdbf29031bcf6107c2765b6ef5b3a7f96cc607f42b06c7

### Machine endpoints
- Knowledge graph: https://pyweb.dev/api/graph.json
- Graph analysis: https://pyweb.dev/api/graph-analysis.json
- Context index: https://pyweb.dev/llms.txt
