Context Rot Explained: Why Agents Get Worse Over Time
Your agent was sharp for the first hour. Now it repeats a fix you rejected, forgets a rule from the start, and edits the wrong file. The window is not full. This is context rot: models get less accurate as their input grows, even far below the limit. This guide shows the data, explains why a bigger window does not fix it, and lists the habits and settings that do.
Bottom Line
- Context rot is real and measured. Models get less accurate as the input grows, even on simple tasks and far below the window limit.
- A bigger window does not fix it. At 1M tokens, Anthropic’s own 8-needle score was 76% for Opus 4.6 and 18.5% for Sonnet 4.5.
- Long sessions make it worse in three ways: more tokens, more noise from failed attempts, and details lost when compaction summarizes.
- The fixes are habits, not hardware: one session per task, decisions in files, short instruction files, and old tool output cleared.
- This is a quality problem, not a capacity problem. If your window fills up, read why your Claude Code context fills up.
What Context Rot Is
Anthropic’s Claude API docs define it in one line: “As token count grows, accuracy and recall degrade, a phenomenon known as context rot.”
The same docs add that “more context isn’t automatically better”. Each token you add competes for the model’s attention with all the others. Anthropic’s context engineering post calls this an attention budget.
For an agent, this means the context you collect while you work is not free. Every log, file read and failed attempt makes the next answer a little worse.
The Evidence
Chroma: 18 models, one result
Chroma’s “Context Rot” study (July 2025) tested 18 models from Anthropic, OpenAI, Google and Alibaba, with 194,480 calls.
- Focused input beat full input for every model. On a memory test, the focused version was about 300 tokens and the full version about 113,000. Every model scored much higher on the focused version.
- Similar but wrong text hurts. One distractor lowered accuracy. Four lowered it more.
- Even copying fails. In a task that asked models to repeat a list of words, errors grew with length. Some models started to produce random words at about 500 to 750 words.
- Indirect questions rot fastest. When the question used different words from the answer, accuracy fell faster as the input grew.
NoLiMa and RULER: the window you get is smaller than the one you buy
| Benchmark | Finding |
|---|---|
| NoLiMa (2025, 13 models) | At 32K tokens, 11 of 13 models fell below half their short-input score. GPT-4o fell from 99.3% to 69.7% |
| RULER (2024, 17 models) | Only about half the models that claim 32K or more did well at 32K. Qwen2 72B: 96.9 at 4K, 53.7 at 128K |
These are older models, and newer ones degrade more slowly. The pattern is the same.
1M tokens is not 1M useful tokens
| Source | What it says |
|---|---|
| Anthropic, Opus 4.6 launch (February 2026) | 8-needle test at 1M tokens: Opus 4.6 76%, Sonnet 4.5 18.5% |
| Google Gemini docs | About 99% for one fact, lower accuracy when several facts must be found |
| Claude Code docs | ”Compaction works the same way at the larger limit.” |
A large window is useful. It holds a big codebase or a long document. But a model that sees 800,000 tokens does not use all of them equally well.
Where in the input matters, sometimes
The 2023 “Lost in the Middle” paper found that models do best with facts at the start or end of the input, and worst in the middle. Chroma’s 2025 test found no clear position effect. Do not rely on placement. Keep the input small instead.
Why Long Agent Sessions Rot Faster
A chat grows by a few hundred tokens per turn. An agent grows much faster:
- Tool output piles up. A test run, a
grepor a file read can add thousands of tokens each. - Failed attempts stay in. The model now sees your rejected fix next to the real one. Claude Code’s docs say a third correction “mostly adds to a conversation that already contains two failed attempts”.
- Compaction turns detail into a summary. That keeps the session alive, but it loses things.
What compaction loses
| Tool | What can be lost |
|---|---|
| Claude Code | Path-scoped rules and nested CLAUDE.md files “are summarized away”. Root CLAUDE.md and auto memory are reloaded from disk |
| Claude API | The docs offer a custom summary prompt for when the default summary “drops something a later turn needs” |
| OpenAI API | The compaction item is encrypted, so you cannot see what was kept |
| OpenClaw | Older details survive only as a summary. Long tool results are trimmed to 2,000 characters for the summarizer. Images become markers |
Anthropic’s long-running agents post (November 2025) found that compaction alone was not enough for multi-session work. Its fix was a progress file and a feature list on disk.
The Fixes
1. One session per task
Start a new session when the task changes. Claude Code’s docs give a rule: after two failed corrections, run /clear and write a better prompt. The same docs say “a focused context gets you better answers and costs less.”
2. Keep decisions in files, not in the chat
A rule in the chat can be summarized away. A rule in a file is read again.
- Claude Code: root
CLAUDE.mdis reloaded after compaction. - OpenClaw:
MEMORY.mdloads at session start, andmemory/YYYY-MM-DD.mddaily notes are searchable. - Any agent: a
progress.mdfile with what is done, what failed, and what is next.
3. Keep instruction files short
Claude Code’s docs target under 200 lines per CLAUDE.md: “Longer files consume more context and reduce adherence.” Codex caps AGENTS.md at 32 KiB by default. OpenClaw cuts bootstrap files that pass its character limits.
4. Clear old tool output
| Tool | Setting |
|---|---|
| Claude API | Context editing, strategy clear_tool_uses_20250919: by default it clears old tool results at 100,000 input tokens and keeps the last 3 |
| OpenClaw | agents.defaults.contextPruning.mode: "cache-ttl" (off by default) |
Anthropic reported that context editing alone gave a 29% improvement on its agent test, and 39% with its memory tool. It cut token use by 84% in a 100-turn web-search test.
5. Send big reads to a subagent
A subagent reads the large files or logs in its own context and returns a short summary. The main context stays small. Our when to use a subagent page covers when this helps.
6. Tune compaction in OpenClaw
The settings are under agents.defaults.compaction:
{
agents: {
defaults: {
compaction: {
mode: "safeguard", // the default for new configs
keepRecentTokens: 20000, // the default: recent turns kept word for word
memoryFlush: { enabled: true }, // writes notes to memory before it compacts
},
contextPruning: { mode: "cache-ttl" }, // trims old tool results
},
},
}
memoryFlush is on by default. It runs a silent turn before compaction, so the agent can write durable notes to its memory file first.
How to Tell Rot From Other Problems
| Symptom | Likely cause | Page |
|---|---|---|
| Quality drops, window not full | Context rot | This page |
| ”Context limit reached” or frequent compaction | Capacity | Why your context fills up |
| A local model forgets after 10 prompts | num_ctx too small | Context window traps |
| Errors after compaction in your own API client | The compaction block was not sent back | Claude API loses context after compaction |
Honest Caveats
- Benchmarks are not your codebase. They show the pattern, not how fast your model rots on your task.
- Newer models rot more slowly. RULER and NoLiMa tested 2024 and early-2025 models.
- We did not measure this ourselves. All numbers come from the sources below.
- Clearing context is not free. A fresh session must read the files again, which costs tokens and time.
Sources
- Chroma: Context Rot (July 2025)
- NoLiMa (2025) and RULER (2024)
- Lost in the Middle (2023)
- Claude API: context windows, compaction and context editing
- Anthropic: Effective context engineering for AI agents (September 2025)
- Anthropic: Effective harnesses for long-running agents (November 2025)
- Anthropic: Claude Opus 4.6 (February 2026) and context management (September 2025)
- Claude Code: context window, best practices, memory
- Gemini API: long context and OpenAI: compaction
- OpenClaw docs: compaction, memory, compaction settings
See Also
- Harness engineering explained: context is one layer of the harness
- Why your Claude Code context window fills up: the capacity side
- Context window traps for local agents:
num_ctxand KV cache - When should you use a subagent: isolate big reads
- OpenClaw memory systems compared: what to keep on disk