AI Coding Agents
Context Rot in Coding Agents: What the Evidence Shows
Context rot is the decline in accuracy or recall that can occur as a model’s input grows. Studies on 2023 to 2025 models found failures on specific retrieval and reasoning tasks within advertised context limits. For coding agents, test where reliability slips on your own tasks, then keep the evidence those tasks need close at hand.
Context rot is the decline in accuracy or recall that can occur as a model’s input grows. The advertised context window describes how much space the model has for conversation history and its new output. To find out how reliably your coding agent uses that space, test whether it can retrieve the evidence and follow the constraints your tasks require. Start with a task where you can verify the answer from the repository, then vary what the agent sees.
What the studies measured
These studies measure different skills, from exact retrieval to code repair.
| Study (date) | Models tested | What it measured | Headline result |
|---|---|---|---|
| Lost in the Middle (Jul 2023 preprint) | A set including explicitly long-context models | Multi-document question answering and key-value retrieval, varying where the answer sits | Accuracy was often highest when the relevant information appeared near either end of the input |
| RULER (Apr 2024) | 17 models, all claiming 32K or more | 13 synthetic tasks: needle variants, multi-hop tracing, aggregation | Nearly perfect on the vanilla needle test, but “almost all models exhibit large performance drops” with length; about half stay satisfactory at 32K |
| NoLiMa (Feb 2025) | 13 models claiming at least 128K | Needles designed to have minimal lexical overlap with the question | At 32K, 11 of 13 models fell below 50% of their short-context baselines; GPT-4o dropped from 99.3% to 69.7% |
| Chroma Context Rot report (Jul 2025) | 18 models, including GPT-4.1, Claude 4, Gemini 2.5, Qwen3 | Retrieval tests that control input length, question similarity, or distractors | Performance varied with length, and one distractor reduced accuracy in Chroma’s test |
| LongCodeBench (May 2025, rev. Oct 2025) | From Qwen2.5 14B up to Google’s flagship Gemini | Question answering and bug fixing built from real GitHub issues | Drops such as “from 29% to 3% for Claude 3.5 Sonnet, or from 70.2% to 40% for Qwen2.5”; the authors call long context “a weakness for all models” |
| LoCoBench (Sep 2025) | Long-context models | 8,000 software-engineering scenarios across 10 languages, 10K to 1M tokens | “Substantial performance gaps”; long-context code understanding is “a significant unsolved challenge” |
| Gemini 2.5 technical report (Jul 2025) | Gemini 2.5 Pro | A livestreamed Pokémon Blue agent, used as a case study | When context grew significantly beyond 100k tokens, the agent tended to repeat actions from its history instead of forming new plans; Google labels the observation anecdotal |
LongCodeBench uses real GitHub issues for comprehension and repair, while LoCoBench generates software-engineering scenarios. Their results give you reasons to test coding tasks alongside simple retrieval. RULER adds a useful comparison within one benchmark. The same models could score nearly perfectly on the basic needle test while showing large drops across the full 13-task suite as the input grew.
Four failure patterns to watch for
Position. In Lost in the Middle, accuracy was often highest when the relevant information appeared near either end of the input. Chroma observed no notable position effect on its specific needle task. In a coding session, a file read early may end up buried under later tool output. Test whether the agent can still cite the exact error, decision, or constraint when you move it within an otherwise fixed transcript.
Distractors. Chroma found that one distractor reduced accuracy relative to the needle-only baseline in its test. In a coding session, a similarly named configuration key can act as a distractor. Unrelated log lines add length and are a separate condition to test. The distinction changes what you trim. If the agent confuses two similarly named settings, retain the relevant setting with its full path and scope. If long logs are the problem, try passing the failing test and a small slice of the log.
Low-similarity needles. NoLiMa used questions with minimal lexical overlap with the facts needed to answer them. In coding, “why does checkout double-charge” may require linking a user-visible symptom to a function named retry_without_idempotency_key. Include that sort of question alongside an exact symbol lookup. If only the symbol lookups pass, test how well the agent finds the right code from issue reports or stack traces before expanding its read budget.
Repetition in agents. Google’s Gemini 2.5 report describes an anecdotal tendency for the Gemini Plays Pokémon agent, a harness run by an independent developer, to repeat actions from its history as context grew significantly beyond 100k tokens. Its appendix also describes false game-state information persisting in goals and summaries. If a coding agent repeatedly runs the same failed command, test whether a fresh session with the verified failure and a new next step breaks the loop.
What vendors say about current models
As of November 30, 2026, the Claude API defaults to a 1M-token context window on the models Anthropic lists with that capacity. Standard pricing applies to those long-context requests except on Claude Haiku 5.5, where prompts over 100,000 tokens cost more. Anthropic documents automatic context-awareness tags for Claude Sonnet 4.5 and Claude Haiku 4.5 only. Those tags let the model track remaining capacity.
Anthropic’s engineering post describes a finite “attention budget” and recommends curating the context around the task. The same post recommends three techniques: compaction, structured note-taking, and sub-agent architectures for focused work in clean windows.
Claude Code’s best-practices page says that with larger windows and automatic compaction, running out of context is rare. It still recommends /clear between unrelated tasks to improve focus and avoid carrying the previous task’s history into later requests.
What transfers to your coding agent
The studies date from 2023 to 2025 and vary in what they hold constant. A retrieval test that holds the question fixed can help isolate the effect of added input. A repair benchmark measures a broader task that can fail after the model finds the right file. The Pokémon case follows an agent making many decisions, with earlier decisions becoming part of its later input. A retrieval score alone gives you little information about how an agent will recover from a wrong turn.
Test the failure patterns separately. A buried fact, a similar but wrong result, and a repeated action can each send an agent off course. Use the smallest working set that meets your own accuracy target. If the lookup succeeds but the patch fails, keep separate measurements for evidence retrieval and repair. That tells you where to spend the next round of evaluation.
Test your own agent and repo
Use a needle-in-repo test to estimate your setup’s effective range. Treat it as a local evaluation for a particular model, repository, and workload.
- Pick a fact only your repository knows, such as an unusual constant, a non-obvious function name, or a configuration value with a surprising default. Write a question that requires the fact with minimal overlap in wording. Record the expected answer and its source before you run the test.
- Run the same questions in fresh sessions with the same model, tool access, and answer file. Use a fixed sequence of tool results or capture the exact input if your runner lets the agent explore.
- Vary the amount of unrelated material while holding the answer position steady. Then vary position with input size held steady. In a separate comparison, swap in a plausible distractor of roughly the same size as the unrelated material it replaces.
- Repeat each setup across several facts. Score the answer and file citation separately, and record the input size. A correct value with a wrong citation passes the answer check and fails the evidence check.
- Choose the largest tested setup that meets your preset accuracy target as a provisional upper budget. Use a smaller tested setup for routine work if it already passes and leaves room for the next set of tool results.
For example, ask which setting governs checkout retries when an upstream request times out. Record the expected setting and its defining file. For the position test, move the same file evidence within the same input. For the distractor test, put a similarly named worker timeout in a different file without moving the answer. If the agent consistently cites the worker setting only in the distractor condition, try passing fully qualified settings and module paths on the next run. If misses rise with additional unrelated text, try trimming log bodies while retaining the failing test name and stack frames.
Include a second check that requires a small repo change and an existing test command. Score whether the agent identifies the right target before it edits, whether it honors the constraints, and whether the requested check passes. Repeat the evaluation when you change models or agent versions. A working-set budget based on successful lookup alone can miss costly retries during edits.
Keep the working set small
Use your evaluation results to choose which content enters the next request and which stays available on demand.
- Clear between tasks. Claude Code’s guidance:
/clearbetween unrelated tasks because “it costs nothing, and it means the next task doesn’t keep paying for the previous one’s history.” Carry forward any verified decision that also applies to the new task. - Compact with a focus.
/compactaccepts instructions, so you decide what the summary keeps instead of letting an automatic pass guess. After compaction, check that the agent can still find the evidence needed for the next action. - Delegate exploration to subagents. Anthropic’s engineering post describes sub-agents exploring “tens of thousands of tokens or more” and returning “a condensed, distilled summary of its work (often 1,000-2,000 tokens).” Ask the subagent to return the finding, the file that supports it, and any uncertainty you need to resolve.
- Give the model a budget where the API allows it. Anthropic offers beta task budgets on supported models. If you need a hard cap on repository reads, enforce it in the tool runner and record which reads were skipped.
- Position what must be found. Identify hard constraints and exact error text that the next action depends on. Test whether restating those details near the current request improves recall on your agent.
What to do next
If an early wrong assumption is already steering the agent inside your session, read the sibling guide on when to compact, rewind, or start a fresh session. If you are deciding what a compaction should keep verbatim versus summarize, see lossless versus lossy context compaction. For background, the context window explainer covers the mechanics, managing long sessions covers handoff notes and continuity, and measuring token savings shows how to verify that any of this actually reduced spend.
Sources
- Lost in the Middle: How Language Models Use Long Contexts (arXiv, accessed 2026-11-30)
- RULER: What’s the Real Context Size of Your Long-Context Language Models? (arXiv, accessed 2026-11-30)
- NoLiMa: Long-Context Evaluation Beyond Literal Matching (arXiv, accessed 2026-11-30)
- Context Rot: How Increasing Input Tokens Impacts LLM Performance (Chroma, accessed 2026-11-30)
- LongCodeBench: Benchmarking Long-Context LLMs on Rich Code Understanding (arXiv, accessed 2026-11-30)
- LoCoBench: A Benchmark for Long-Context LLMs in Complex Software Engineering (arXiv, accessed 2026-11-30)
- Gemini 2.5: Pushing the Frontier with Advanced Reasoning, Multimodality, Long Context, and Next Generation Agentic Capabilities (Google DeepMind via arXiv, accessed 2026-11-30)
- Claude context windows (Anthropic, accessed 2026-11-30)
- Effective context engineering for AI agents (Anthropic, accessed 2026-11-30)
- Claude Code best practices (Anthropic, accessed 2026-11-30)
Interactive report
- The Long-Context Mirage: A model can accept a million tokens and still miss the line of code you need. Follow the published accuracy results, then price the decision to keep, trim, or leave a long conversation.
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
Context Rot in Coding Agents: What the Evidence Shows. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/context-rot-long-context-coding/
Sources
- Lost in the Middle: How Language Models Use Long Contexts
- RULER: What’s the Real Context Size of Your LongContext Language Models?
- NoLiMa: LongContext Evaluation Beyond Literal Matching
- Context Rot: How Increasing Input Tokens Impacts LLM Performance
- LongCodeBench: Benchmarking LongContext LLMs on Rich Code Understanding
- LoCoBench: A Benchmark for LongContext LLMs in Complex Software Engineering
- Gemini 2.5: Pushing the Frontier with Advanced Reasoning, Multimodality, Long Context, and Next Generation Agentic Capabilities
- Claude context windows
- Effective context engineering for AI agents
- Claude Code best practices