Context rot: why LLMs get worse as the prompt gets longer
Context rot is the drop in an LLM's accuracy as its input grows, even when the answer is in the context and the window is nowhere near full. Chroma measured it on 18 models in 2025, from GPT-4.1 to Claude Opus 4 and Gemini 2.5 Pro, and every one of them became less reliable as input length increased, on tasks as simple as finding one sentence. The fix is not a bigger window: it is sending less, and putting what you send in the right place.
- Context rot is gradual, not a cliff. Accuracy slides as input tokens grow, well before the context limit, so a request can be valid, fit the window and still be answered worse than a shorter one.
- All 18 models in Chroma's study degraded. On LongMemEval questions, every model did markedly better with a focused ~300-token input than with the full ~113K-token history that contained the same answer.
- Distractors do the most damage: text that looks like the answer but is not. One distractor lowers accuracy, four lower it further, and the effect grows with length.
- Lost in the middle is one symptom: facts in the middle of a long context are used less reliably than facts at the start or end. Context rot is the wider effect of length itself.
- Prevention is mostly subtraction: retrieve wide and send narrow, drop duplicates and stale tool output, compact long sessions, and keep the question and key instructions at the edges of the prompt.
What context rot is
A context window is a hard limit: the most tokens a model will accept. Context rot is about what happens well inside that limit. As input grows, the model's attention is spread over more tokens, and its ability to find, connect and follow the right ones gets worse. Nothing errors. The request succeeds, the answer reads fluently, and it is a little less likely to be right.
The term was popularised by Chroma's 2025 report, which showed that models do not use their context uniformly: the same fact, asked the same way, is found less reliably at 100K tokens than at 1K. Three related problems are often mixed up with it.
| Problem | What happens | Visible? |
|---|---|---|
| Context overflow | The input exceeds the window, so the API rejects it or the framework truncates it | Yes: an error or missing text |
| Lost in the middle | Facts placed mid-context are used less often than facts at the start or end | No: wrong or incomplete answers |
| Context rot | Accuracy falls as total input grows, wherever the fact sits | No: gradual quality loss |
| Context poisoning | A wrong fact or hallucination enters the context and keeps being reused | Sometimes: the same error repeats |
The practical consequence: a model advertised with a 1M-token window does not give you 1M tokens of equally good attention. The window says what you are allowed to send, not what the model will use well.
What the research shows
Chroma, 2025: 18 models, all of them degrade
Chroma tested 18 models from Anthropic, OpenAI, Google and Alibaba on deliberately simple tasks, varying only the input length. The point of simple tasks was to rule out the excuse that long inputs are just harder problems.
- Less obvious matches fail first. When the question and the answer share few words (low semantic similarity), accuracy fell much faster as input grew. Real questions are usually like this: users do not phrase them the way your documents are written.
- Distractors compound the loss. Adding one passage that looked relevant but did not answer the question lowered accuracy; four lowered it further. Models differed in how they failed: Claude models tended to abstain, GPT models tended to answer confidently with the distractor.
- Focused beats full. On 306 LongMemEval questions, models scored markedly better given only the relevant ~300 tokens than given the full ~113K-token conversation history that also contained them.
- Coherent text hurt more than shuffled text. Across all 18 models, a haystack of randomly shuffled sentences was searched more accurately than the same text in its logical order. Structure that reads naturally can pull attention away from the one sentence that matters.
- Even copying breaks. Asked to repeat a long run of a common word with one different word inserted, models made more mistakes as length grew: wrong positions, wrong lengths, random output.
Lost in the middle, 2023: position matters
Liu et al. gave models 20 to 30 retrieved documents with the answer in one of them, and moved that document around. Accuracy followed a U-shape: highest when the answer was first or last, lowest in the middle. In some settings, a model with the answer buried mid-context did worse than the same model with no documents at all. Chroma's needle tests found position mattered less in its setup, which is a useful reminder that both effects exist and that your prompt shape decides which one bites.
Agents, 2026: giving up before the window is full
Xia et al. studied search agents on long-horizon tasks across four flagship models. As the agent's context filled with search results, models increasingly gave up or returned uncertain wrong answers long before running out of window, including on questions they could solve. Context management that kept peak context lower redirected the models back to searching. For agents, context rot shows up less as wrong facts and more as lost persistence.
Why long context degrades
There is no single accepted cause, but three mechanisms explain most of what the studies observe.
- Attention is a budget. Each token's attention weights sum to one across everything in context. More tokens means each relevant token competes with more irrelevant ones, and weak signals get diluted. Anthropic's context engineering post describes context as a finite resource with diminishing returns for exactly this reason.
- Similar-looking text competes. The model retrieves by resemblance. A passage that shares vocabulary with the question but answers a different one (last year's price, the wrong customer, a deprecated API) is a better match on surface features than the right answer phrased differently.
- Long examples are rarer in training. Models see far more short sequences than long ones, and long-range positions are learned from less data. Stretching the window does not stretch the experience at the same rate.
All three point the same way: the cost of an irrelevant token is not zero. It takes attention from relevant ones, and the more it resembles the answer, the more it takes.
Where context rot shows up in production
Benchmarks build long contexts on purpose. Production systems build them by accident, one reasonable decision at a time.
| Where | How the context grows | Symptom |
|---|---|---|
| RAG | top-k raised to protect recall; overlapping chunks; near-duplicate pages | Cites the wrong source, mixes two versions of a fact |
| Agents | Every tool result appended and kept: file listings, search results, logs | Repeats steps, forgets the goal, stops early |
| Coding agents | Whole files read, test output kept after it was fixed | Edits drift from earlier instructions, reintroduces fixed bugs |
| Long chats | Full history resent every turn | Ignores an early constraint, contradicts itself |
| System prompts | Rules added after each incident, never removed | Follows some rules and silently drops others |
The common thread is that context is added because it might help and rarely removed because nobody checks whether it did. Each addition looks harmless on its own. Together they push every request further down the degradation curve, and the cost goes up at the same time: the same unneeded tokens that dilute attention are billed on every call. Paste a real request into the token counter to see how much of it is history, tool output and retrieved text.
How to measure context rot in your own app
Published benchmarks tell you context rot exists; they do not tell you where your prompt sits on the curve. The cheapest test copies Chroma's LongMemEval setup: take questions you already know the answers to, and run each one twice, once with only the passages that answer it and once with the full context your app would really send.
- A gap of a few points or more means the extra context is costing you accuracy, not just money. That is the signal to cut.
- Plot accuracy against input tokens. Bucket production-like cases by context size and look for where the curve bends. That is your practical budget, whatever the model's window says.
- Add distractors on purpose. Insert a passage that resembles the answer but is wrong (an old price, a different customer) and see how often the model uses it. That is the failure your users will meet.
- For agents, track steps, not just answers. Rising step counts, repeated tool calls and early give-ups on long runs are context rot even when the final answer is fine.
How to prevent context rot
Every fix comes down to the same idea: give the model the smallest set of tokens that answers the question, arranged so the important ones are easy to find. In rough order of impact:
- Retrieve wide, send narrow. Keep top-k high so recall is not the bottleneck, then rerank and apply a relevance threshold so only passages that earn their place reach the prompt. The full method is in RAG context compression.
- Remove duplicates and near-duplicates. Overlapping chunks and copies of the same page are pure distractors: they repeat a fact without adding one, and they pull attention toward whichever version is stale.
- Clear stale tool output. Once an agent has acted on a file listing or a test log, the raw output rarely needs to stay. Replace it with a one-line result, or drop it. See agent context optimization.
- Compact long sessions. Summarise older turns into the decisions and facts still in force, and start fresh when the task changes. Coding agents do this with commands like
/compactand/clear. - Split work across clean contexts. A sub-agent that searches with its own context and returns a short answer keeps the main context small. Each context stays near the top of the curve.
- Put the question and key instructions at the edges. Start or end of the prompt, not between two long documents. For long documents, ask the question after them.
- Set a token budget per request. A ceiling turns "add it, it might help" into a choice about what to drop. Measure where your accuracy bends and set the budget below it.
- Let the model abstain. Tell it to say when the context does not contain the answer. An honest "not found" is easier to catch than a confident answer built on a distractor.
| Technique | Fixes | Effort |
|---|---|---|
| Rerank + relevance threshold | Distractors, length | Medium: one extra stage |
| Deduplication | Distractors, stale versions | Low |
| Clearing tool output | Agent context growth | Low |
| Compaction / summaries | Long sessions | Medium: summaries can drop facts |
| Sub-agents | Agent context growth | High: more orchestration |
| Question at the edges | Lost in the middle | Trivial |
| Token budget | All of the above, by force | Low once measured |
Will bigger context windows fix it?
Not by themselves. Windows have grown from 4K to over 1M tokens, and every model in Chroma's study, including the long-context ones, still degraded with length. A larger window raises the ceiling on what you can send; it does not flatten the curve below it. Newer models do degrade more slowly, so the bend moves right, but the shape stays.
There is also the bill. Long inputs cost more per call, and the big three providers also charge a higher rate per token past a threshold: Gemini 3.1 Pro doubles its input price above 200K tokens, GPT-6.1 Sol above 272K, and Claude Haiku 5.5 bills input at 5× above 100K (see Gemini API pricing, Claude API pricing and the LLM pricing tool). Sending less is the one change that improves accuracy and cost at once. The rest of the discipline is in the context engineering guide.
Frequently asked questions
What is context rot?
Context rot is the decline in an LLM's accuracy as its input gets longer, even when the relevant information is present and the context window is not full. The term was popularised by a 2025 Chroma study that found it in all 18 models tested.
Is context rot the same as lost in the middle?
No. Lost in the middle is a position effect: facts in the middle of a long context are used less reliably than facts at the start or end. Context rot is the broader effect of total length, which happens wherever the fact sits. Long prompts can suffer from both.
At how many tokens does context rot start?
There is no fixed number. It depends on the model, the task and how much of the context resembles the answer. Studies show accuracy sliding gradually as input grows, long before the window limit. Measure your own curve by running the same labelled questions with focused and with full context.
Does context rot affect Claude, GPT and Gemini?
Yes. Chroma's study covered models from Anthropic, OpenAI, Google and Alibaba, and all of them became less reliable as input grew. They differed in how they failed: Claude models abstained more often, GPT models hallucinated more often from distractors.
How do coding agents deal with context rot?
By keeping their working context small: compacting the conversation into a summary, clearing old tool output, starting a fresh session when the task changes, and delegating searches to sub-agents that return short answers instead of raw results.
Does a bigger context window solve context rot?
No. A bigger window lets you send more tokens, but the model still uses a long context less reliably than a short one. Newer models degrade more slowly, but the fix is still to send fewer, more relevant tokens.
Does context rot make LLMs more expensive?
Indirectly, yes. The tokens that cause context rot are billed like any other, and OpenAI, Anthropic and Google all charge a higher rate per token on very long prompts. Removing irrelevant context lowers the bill and improves accuracy at the same time.
Keep reading

Context Engineering: The Practical Guide
Context engineering decides what information reaches an LLM on each call. Definition, principles, workflow, anti-patterns and metrics.

RAG Context Compression vs Reranking
RAG context compression removes redundant, off-topic and low-value chunks before the model call. How it differs from retrieval and reranking, with math.

Agent Context Optimization: Stop Token Bloat
Agent context grows every step. Where waste comes from (tool output, memory, stale state) and patterns that cut input tokens without hurting task success.