# What Is Context Rot?

> What context rot is, why a bigger context window does not cure it, and how to keep an AI agent's context lean, explained simply for your AI interview.

**In short:** Context rot is the drop in an AI model's accuracy and recall as its context window fills with more text. A bigger window does not fix it on its own, so teams keep what goes in small, relevant and cleaned up.

AI and LLM interview question Q083, Prompt and context engineering. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-context-rot

## Say it in 30 seconds

Context rot is what happens when an AI model's context window fills with more and more text. Anthropic's docs describe it as accuracy and recall degrading as the window grows. The drop comes on gradually, so it is easy to miss. A bigger window doesn't fix it on its own. In my agents I keep the window lean: clear old tool results, summarise long chats, keep notes outside the window, and test recall at real lengths.

## Say it in 2 minutes

Every answer an AI model gives comes from one context window: the instructions, the chat so far, and every tool result it has pulled in. Context rot is the loss of accuracy and recall as that window fills with more text. The concept came out of needle-in-a-haystack studies, which hide one fact in a long text and test whether the model can find it. Anthropic's docs say accuracy and recall degrade as token count grows.

Why does it happen? Every new token uses up part of the model's attention budget, so its focus is spread thinner as the text gets longer. Anthropic calls the decline a performance gradient, with no sharp point where the model suddenly fails. Models also see shorter texts more often than long ones in training. A bigger window does not fix it on its own, so context has to be treated as a finite resource.

In practice I keep the window lean. Old tool results get cleared once their answer is used. Long chats are summarised, though summarising too hard can drop subtle details that matter later. Key facts go into notes kept outside the window. Heavy research goes to sub-agents that send back short summaries, and each step loads only the documents it needs.

I also test it. I hide a known fact early in a long test chat, ask for it at the end, and check the answer at the lengths real customers reach. If recall fails, I cut the context before I touch the model.

## What is context rot, in plain words?

A model reads its whole context window for each answer. That window holds your instructions, the chat so far, and every tool result the model has pulled in. Context rot is the slow loss of accuracy and recall as the window fills with more text. Anthropic's docs define it that way: accuracy and recall degrade as the window holds more text.

Picture a new hire on day one who is handed the full employee handbook, three years of emails and last quarter's reports, then asked about the leave rule. The rule is in there somewhere. The more they carry, the more likely they skim past the page that matters. A model with a full window is in the same spot. A support bot is the same: forty turns of tool results can sit ahead of the one refund rule it must follow.

- **Context window:** The text a model can read in one go: instructions, chat and tool results.
- **Token:** A small piece of text, often part of a word. Models count their window in tokens.
- **Recall:** Getting a fact back when you ask for it. Tests hide one fact in a long text to check it.
- **Tool result:** The text a tool sends back, such as a search hit or an account export.
- **Compaction:** Replacing a long history with a short summary, then starting a fresh window.

## Why does a fuller context give worse answers?

Each new token uses up part of what Anthropic calls an attention budget. Every token has to be weighed against the others, so the model's focus is spread thinner as the text gets longer. Models also see shorter texts more often than long ones in training, so they have less practice with very long inputs.

> "Studies on needle-in-a-haystack style benchmarking have uncovered the concept of context rot: as the number of tokens in the context window increases, the model's ability to accurately recall information from that context decreases." (Anthropic)
>
> "Waiting for larger context windows might seem like an obvious tactic. But it's likely that for the foreseeable future, context windows of all sizes will be subject to context pollution and information relevance concerns" (Anthropic)

The decline is a slope. Anthropic calls it a performance gradient, so there is no token count where the model suddenly fails. Plan for the slope from the start.

Here is a made-up case. A mid-size bank runs a support assistant. After 40 turns in one long chat, its window holds 40 tool results, the full chat history and the current refund rule, now buried among them. It quotes the old 30-day refund window from an early page. Nothing crashed. The answer just went stale.

*Diagram, How context rot builds up: A made-up support agent's window fills with old transaction exports and chat history. The refund rule sits among them, so the model answers from the wrong policy. Nothing errors; the answer comes out wrong.*
1. The whole window goes to the model, refund rule included, among old results.
2. The model recalls the wrong thing, so it answers from an old policy.

## How do you keep context from rotting?

Don't wait for bigger windows. Anthropic's guidance is to find the smallest possible set of high-signal tokens that gives the outcome you want. Five habits do most of the work.

1. **Clear old tool results:** Once a tool's answer has been used, the raw output rarely needs to stay. Anthropic calls this tool result clearing, one of the lightest forms of compaction.
2. **Summarise long history:** Compaction takes a conversation near the limit, summarises it, and starts a fresh window with the summary. Keep the decisions and open bugs, drop the chatter. The cost: summarise too hard and subtle details vanish, so test the summary.
3. **Keep notes outside the window:** The agent writes key facts to a file or memory store and reads them back when needed. Anthropic calls this structured note-taking.
4. **Split heavy work across sub-agents:** Each sub-agent works in a clean window and sends back a short summary. The main agent keeps the plan and stays small.
5. **Load documents just in time:** Keep file paths and links, and load a document only when the step needs it, instead of pasting everything up front.

*Diagram, Keeping everything or curating: The same made-up support agent, run two ways. Keeping every result lets the window grow until the refund rule is buried. Clearing old results and summarising keeps the window small enough to recall from.*
1. Every result stays, so the window keeps growing until the rule is buried.
2. Old results are cleared and summarised, so the window stays small enough to recall from.

Here is a small sketch of the second way. It keeps the refund rule and the last three items, and drops the rest. The numbers are made up to show the effect.

```python
# A made-up support agent after 40 turns. Each turn keeps one tool result of 3,500 tokens.
TOKENS_PER_RESULT = 3500
TOKENS_PER_RULE = 40
RULE = "policy: refund requests close after 60 days"

def size(items):
    return sum(TOKENS_PER_RULE if x.startswith("policy:") else TOKENS_PER_RESULT for x in items)

turns = [f"turn {i}: transaction export" for i in range(1, 41)]
history = [RULE] + turns
print("Kept everything:", len(history), "items,", size(history), "tokens")

def curate(items, keep_last=3):
    rule = [x for x in items if x.startswith("policy:")]
    recent = [x for x in items if not x.startswith("policy:")][-keep_last:]
    return rule + recent

lean = curate(history)
print("After curation:", len(lean), "items,", size(lean), "tokens")
print("Rule kept:", RULE in lean)
```

Output:

```text
Kept everything: 41 items, 140040 tokens
After curation: 4 items, 10540 tokens
Rule kept: True
```

### How would you spot context rot in a support bot?

Look for answers that quote old policy, a limit the customer stated twenty messages back that the bot forgets, and replies that get slower and costlier as chats run longer. Those are signs to check, so test before you blame the model.

> **Tip:** Plant a known fact early in a long test chat, then ask for it at the end. Run the test at the lengths real customers reach.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: accuracy and recall fall as the window fills.
- [ ] Why it happens: every token competes for the model's focus.
- [ ] A bigger window does not cure it, so curation matters.
- [ ] Fixes: clear old results, summarise, keep notes outside, split work.
- [ ] How you would test recall at real conversation lengths.
- [ ] It comes on gradually, so teams miss it without a test.

**Common traps**

- Trap: "A bigger context window fixes it." Better: A bigger window gives room, but recall still falls as text grows. Curate what goes in.
- Trap: "Paste all the docs in and the model will find it." Better: Recall falls with length. Load only the pages the step needs, then test recall at real lengths.
- Trap: "Context rot is an error that crashes the app." Better: Nothing crashes. Answers just get worse, which is why teams miss it.

## Can you spot the rot risk?

**Spot the risk:** Which line lets context rot set in for a support agent?

A. history.append(tool_result)  # every turn, no clean-up
B. history = summarise(history[:-6]) + history[-6:]  # compact old turns
C. history = history[-6:]  # keep only the last six items
D. history = [REFUND_RULE] + history[-6:]  # rule pinned, recent turns kept

**Answer:** A. The first line never removes anything, so the window grows every turn until the refund rule is buried. The other three keep the window small. The third drops the rule as well, which is a different bug.

**Quick check:** A support agent quotes an old refund window more often as chats get longer. What is the most likely cause?

A. The model's training data is out of date
B. Context rot: the window is full of stale text
C. The temperature setting is too high
D. The customer's account name is misspelt

**Answer:** B. Answers that get worse as the window fills, and lean on stale text, match context rot. Training data, temperature and a misspelt name don't change with chat length.

## Can you answer these from memory?

**Flash cards**

- **What is context rot?** Accuracy and recall fall as the context window fills with more tokens.
- **Does a bigger window fix it?** No. More context is not automatically better, so curate what goes in.
- **Is the drop sudden?** No. It is a gradient, so it comes on gradually and is easy to miss.
- **Lightest-touch fix?** Clear old tool results once used. Anthropic calls it one of the lightest forms of compaction.
- **What is compaction?** Summarising a long history and starting a fresh window with the summary.

## Likely follow-up questions

- Q084 What is "lost in the middle"? https://designervenkat.online/interview/ai/what-is-lost-in-the-middle
- Q096 What is compaction (summarising history)? https://designervenkat.online/interview/ai/what-is-compaction-summarising-history
- Q097 What is structured note-taking (external memory)? https://designervenkat.online/interview/ai/what-is-structured-note-taking-external-memory
- Q138 RAG vs long context: which to use? https://designervenkat.online/interview/ai/rag-vs-long-context
- Q008 What is a context window? https://designervenkat.online/interview/ai/what-is-a-context-window
- Q082 Context engineering vs prompt engineering? https://designervenkat.online/interview/ai/context-engineering-vs-prompt-engineering

## Learn it in depth

- [Context Failure Modes](https://designervenkat.online/learn/ai-engineering/context-failure-modes)
- [Context Compaction](https://designervenkat.online/learn/ai-engineering/context-compaction)
