← All guides

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

BenchmarkFinding
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

SourceWhat 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 docsAbout 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:

  1. Tool output piles up. A test run, a grep or a file read can add thousands of tokens each.
  2. 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”.
  3. Compaction turns detail into a summary. That keeps the session alive, but it loses things.

What compaction loses

ToolWhat can be lost
Claude CodePath-scoped rules and nested CLAUDE.md files “are summarized away”. Root CLAUDE.md and auto memory are reloaded from disk
Claude APIThe docs offer a custom summary prompt for when the default summary “drops something a later turn needs”
OpenAI APIThe compaction item is encrypted, so you cannot see what was kept
OpenClawOlder 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.md is reloaded after compaction.
  • OpenClaw: MEMORY.md loads at session start, and memory/YYYY-MM-DD.md daily notes are searchable.
  • Any agent: a progress.md file 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

ToolSetting
Claude APIContext editing, strategy clear_tool_uses_20250919: by default it clears old tool results at 100,000 input tokens and keeps the last 3
OpenClawagents.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

SymptomLikely causePage
Quality drops, window not fullContext rotThis page
”Context limit reached” or frequent compactionCapacityWhy your context fills up
A local model forgets after 10 promptsnum_ctx too smallContext window traps
Errors after compaction in your own API clientThe compaction block was not sent backClaude API loses context after compaction

Honest Caveats

  1. Benchmarks are not your codebase. They show the pattern, not how fast your model rots on your task.
  2. Newer models rot more slowly. RULER and NoLiMa tested 2024 and early-2025 models.
  3. We did not measure this ourselves. All numbers come from the sources below.
  4. Clearing context is not free. A fresh session must read the files again, which costs tokens and time.

Sources

See Also

Read next

MCP vs CLI vs API Explained: What Your Agent Should Use
MCP, a CLI and a plain API call can all give an agent the same ability. They differ in token cost, reliability, auth and how easy they are to control. The 2026 benchmarks, the new stateless MCP spec, tool search, and a decision rule with the OpenClaw settings for each.
Pass Rate vs Completion Rate Explained: Agent Benchmarks
Why the best coding agents pass only 40% of Android Bench 2.0's long tasks but complete over 80% of the work. Pass rate vs completion rate, pass@k vs pass^k, harness effects, saturated benchmarks, and a checklist for reading any agent benchmark claim.
Tool Search Explained: Why 100 Tools Make Agents Worse
Every tool you give an agent costs context and makes the right tool harder to pick. How tool search works (regex, BM25, embeddings), what it does to prompt caching, when code mode is better, and how to set it up in the Claude API, OpenAI and OpenClaw.
Context Window Traps (2026): Why Your Local Agent Breaks After 10 Prompts
Ollama's default context is far below what an agent harness needs. The system prompt and tool schemas alone eat 15-20K tokens, so a 4-8K window silently truncates your tools. How to check it, set it, and budget the KV cache VRAM.