Explainer
Context rot: why long contexts fail and what to do
Why models get worse as their context fills up, from lost-in-the-middle to distractors and poisoned context, and the practical fixes for agents and RAG.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
Context windows grew from a few thousand tokens to a million in a few years. It is tempting to read that as “just put everything in”. In practice, models get less reliable as their context fills, well before the limit. The term that stuck for this is context rot: the gradual decline in how well a model uses what is in front of it as the input grows.
This explainer summarises the evidence, names the failure modes you will see in agents and RAG systems, and lists the fixes that work.
What the research shows
Lost in the middle (2023). Liu and colleagues tested models on question answering over many documents and found a U-shaped curve: accuracy was highest when the relevant document was at the start or end of the context and dropped when it sat in the middle. Long-context models were not immune. (arXiv 2307.03172)
Context rot (2025). Chroma’s technical report, published 14 July 2025, tested 18 models from Anthropic, OpenAI, Google and Alibaba on deliberately simple tasks. Its central finding: “model performance consistently degrades with increasing input length”, even when the task does not get harder. Several details matter for builders:
- Even a single distractor (text related to the question but not answering it) reduced accuracy, and more distractors compounded it.
- Accuracy fell faster with length when the question and the relevant passage shared fewer words, which is the normal case for real user questions.
- On a memory benchmark, models did much better with a focused prompt of about 300 tokens than with the full conversation of about 113,000 tokens containing the same answer.
Newer models handle long inputs better than the ones in these studies, and providers publish strong long-context results. The direction of the effect has held up in practice, though: more context is not free, and irrelevant context costs accuracy.
Newer evidence (checked 25 November 2026)
Two later studies sharpen the picture, and both test something closer to real use than finding a planted fact.
- Length hurts even when retrieval is perfect. Du and colleagues, in a paper submitted on 6 October 2025, gave models inputs where all the relevant information could be retrieved perfectly and still found that “performance still degrades substantially (13.9%–85%) as input length increases”, well within the models’ advertised limits. The drop persisted when the irrelevant text was replaced with whitespace, and even when it was masked so the model attended only to the relevant tokens (arXiv 2510.05381). Length itself, not only distraction, has a cost.
- More context, more made-up answers. A study by JV Roig submitted on 9 March 2026 ran 35 open-weight models on document question answering at 32K, 128K and 200K tokens. Fabricated answers rose steeply with length: the best model fabricated 1.19% of answers at 32K, the rate nearly tripled at 128K, and every model exceeded 10% at 200K (arXiv 2603.08274). The study covers open-weight models only, so treat it as a direction, not a number for the model you use.
Meanwhile windows kept growing: every current Claude model accepts 1M tokens (Anthropic models overview). A bigger window raises the ceiling on what fits. It does not change how much of it the model uses well, so the fixes below still apply.
Four ways long contexts fail
Drew Breunig’s June 2025 essay “How Long Contexts Fail” gives useful names to what you see in agent logs (dbreunig.com):
- Context poisoning. A mistake gets into the context (a hallucinated fact, a wrong tool result, a misread file) and the model keeps building on it. In agents, a wrong early conclusion in a summary can steer every later step.
- Context distraction. The context grows so long that the model leans on it too much, repeating earlier actions from its history instead of reasoning afresh.
- Context confusion. Irrelevant material, including too many tool definitions, pulls the model towards worse choices. The essay cites results where small models failed with dozens of tools and succeeded with fewer.
- Context clash. New information contradicts older information in the same context, and the model cannot reconcile them. A task split across many turns, with early guesses left in the history, is the common case.
You will recognise these from long coding-agent sessions: instructions from the start ignored, a rejected approach proposed again, a fact from one file confused with another.
What to do about it
The general principle is the same as in context engineering: give the model the smallest set of high-signal information it needs for the current step.
For RAG:
- Retrieve fewer, better passages. Five relevant chunks usually beat twenty. Add a reranker so the best evidence comes first.
- Put the most relevant material at the start or end of the context, not in the middle, and keep the question close to the evidence.
- Remove near-duplicates. They are distractors that look relevant.
- Measure retrieval separately from generation, so you know whether a bad answer came from a bad context. Chunking strategies for RAG shows how.
For agents:
- Clear between unrelated tasks. A fresh context with a good instruction file beats a long one full of another task’s leftovers.
- Compact deliberately at task boundaries, with instructions about what to keep, and check the summary for errors before continuing. A wrong summary is context poisoning in its purest form.
- Use a handoff file: write the state to a document, review it, clear, and resume from it. Agent memory and compaction walks through the routine.
- Delegate noisy work (searches, logs, test runs) to subagents so only their conclusions return.
- Load tools and instructions on demand. Enable only the MCP servers a task needs; move specialist instructions into skills that load when relevant.
- Trim tool outputs. Return the first error, not the whole log.
For prompts in general:
- Remove contradictions. If the system prompt says one thing and a later document another, say which wins.
- State the task again near the end of a long prompt.
- Prefer structure (headings, tags) so the model can find things.
How to tell if it is happening to you
- Quality drops late in long sessions or long documents and recovers when you start fresh.
- The model contradicts instructions it followed earlier.
- Answers cite a related but wrong passage (a distractor).
- An agent repeats actions or re-proposes rejected ideas.
- Your eval scores improve when you shorten the context, with nothing else changed.
The last one is the test worth running: take a set of failing cases, cut the context to what is relevant, and rerun. If they pass, you have a context problem, not a model problem.
Next steps
- Apply the fixes to coding agents in Agent memory and compaction, which walks through handoff files and deliberate compaction.
- See the wider discipline these fixes belong to in what is context engineering?
- Learn the discipline in Context engineering basics.
- Improve what retrieval puts in the context with Hybrid search and reranking.
Covers
Related
- Agent memory and compaction in practice
Keep long Claude Code sessions accurate with compaction, CLAUDE.md, auto memory, subagents and a summarise-and-restart routine, and know what survives each.
- What is context engineering?
Context engineering is deciding what a model sees at each step. Why the term replaced prompt engineering for people building agents, and what the work involves.
- Context engineering techniques: what the model should see
What to put in a model's context at each step, what to leave out, and how instruction files, retrieval and tools fit.
- Context rot
The gradual decline in a model's accuracy and instruction-following as its context fills up with long, stale or irrelevant content.
- Context window
The maximum number of tokens a model can consider in one request, covering both the input you send and the output it writes.