# Context Rot

> The Context Rot is the degradation of model performance as the context grows long and cluttered.

## What is context rot in LLMs?

The effect where a model pays less attention to important details and makes more mistakes as the context fills with long logs, outdated attempts and irrelevant files. Reduced by starting new sessions, compaction and sub-agents.

- Topic: Agentic Coding
- Type: concept

## Example

Wrong:

```text
The build fails. Here is the full CI log:
<4,000 lines of install and test output>
Also read every file in src/ and fix it.
```

Right:

```text
The build fails in `src/api/client.ts`.
Error (lines 212–230 of the CI log):
TypeError: Cannot read properties of undefined (reading "id")
Read only `src/api/client.ts` and its test, then fix the cause.
```

Passing only the relevant error and files keeps the context small, so the model focuses on the details that matter.

## Common mistakes

- Assuming a bigger context window means the model uses everything in it equally well.

## Key points

- Only files and tool outputs relevant to the task are loaded into context, not whole folders.
- Large tool outputs are truncated or summarized before being added to context.
- Long tasks are split into fresh sessions or sub-agents with clean context.

## Interview questions

### Does a bigger context window prevent context rot?

No. A larger window lets more text fit, but quality still tends to drop as the context fills with long, noisy or outdated content.

### How do I fix an agent that gets worse in a long session?

Start a fresh session with a short summary of the goal and current state, or delegate subtasks to sub-agents that work with a clean context.

### What is the difference between context rot and hallucination?

Context rot is a cause: details get missed as context grows. Hallucination is one possible effect: the model states things that are not true.

## Related cards

- [Context Window](https://wonderium.dev/ai/context-window.md)
- [Context Compaction](https://wonderium.dev/ai/context-compaction.md)
- [Context Engineering](https://wonderium.dev/ai/context-engineering.md)
- [Sub-Agent](https://wonderium.dev/ai/sub-agent.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/context-rot
- Last updated: 2026-11-25
