Contents Sources of context pollution

Why agents fail

Sources of context pollution

A window can fill with content nobody chose for the task. Tool schemas, instruction files, whole command outputs and failed-attempt wreckage can enter and accumulate without being weighed against the task's needs. Not all this is unchecked by default: Claude Code defers MCP schemas until a tool is used, except automatic tool search loads them upfront when they fit a documented context threshold, and Copilot CLI writes large output to a file instead of landing it whole.35 Where measured, deferred loading and filtering cut consumption substantially.

Tool definitions are one large, measured source in Anthropic's own examples. Their example puts five MCP servers with fifty-eight tools at roughly 55K tokens consumed before the conversation starts, and reports an internal case where tool definitions reached 134K.1 Loading schemas on demand cut tool-definition tokens by about 85 percent and raised accuracy on their own MCP evaluation, from 49 to 74 percent on Opus 4 and from 79.5 to 88.1 on Opus 4.5; keeping intermediate tool results out of the conversation entirely moved average usage on complex research tasks from 43,588 tokens to 27,297.1 Their threshold for switching to deferred loading is a toolset past roughly twenty tools.2 Claude Code documents plain command-line tools as more context-efficient than MCP servers because they add no per-tool listing.3

The diagram shows what fills context.

graph LR
  A[System prompt] --> W((Context window))
  B[Tool schemas] --> W
  C[Project brief] --> W
  D[File reads] --> W
  E[Tool results] --> W
  F[Subagent summary] --> W
  N[What enters, not what leaves]

Figure: Prompts, schemas, briefs, file reads, tool results and subagent summaries all consume the same context window. Instruction files pollute differently: CLAUDE.md is loaded at session start, so workflow detail for one task is present during every other. Anthropic's advice is to stay under two hundred lines and move occasional material into on-demand skills, and it names the consequence plainly: "Bloated CLAUDE.md files cause Claude to ignore your actual instructions".34 Three of its five named failure patterns are pollution: unrelated tasks interleaved in one session, an unscoped investigation that reads hundreds of files, and repeated failed corrections that leave the window full of approaches that did not work.4 Size-based guards help: a hook can grep a log and return the matching lines instead of ten thousand, and GitHub Copilot CLI writes any tool output over 20 KiB to a file and hands the model a path and a preview.35

The evidence thins where it would help most. Chroma's distractor experiments show added irrelevant material degrades performance and four distractors compound it, but those are retrieval tasks, not coding tasks.6 Cursor reports that dynamic tool loading reduced total agent tokens by 46.9 percent in runs where MCP tools were called, described as statistically significant with high variance depending on how many servers are installed.7 Nobody has published the effect of one stale file read on the next patch, so the figure above maps what arrives, not which arrival costs the most.

References

Quizzes
  1. Why does Anthropic document command-line tools as more context-efficient than MCP servers?

    • Nothing is listed per tool
    • They run faster per call
    • They return shorter output by design

    Claude Code documents CLI tools as more context-efficient than MCP servers because they add no per-tool schema listing, unlike the roughly 55K tokens Anthropic measured for five MCP servers with fifty-eight tools.

  2. Anthropic reports that loading MCP tool schemas only when a tool is used, instead of upfront, ____ the tokens consumed by tool definitions in their evaluation.

    • reduced
    • left unchanged
    • increased

    Deferred loading cut tool-definition tokens by about 85 percent and raised accuracy on Anthropic's own MCP evaluation from 49 to 74 percent on Opus 4, a result specific to that evaluation.

  3. A hook that greps a large log file for matching lines, instead of letting the agent read the whole file, is a documented way to keep unneeded content out of the context window.

    • True
    • False

    Claude Code documents exactly this: a hook can grep a log and return matching lines, cutting tens of thousands of tokens of irrelevant output down to a few hundred.

Comments

No comments yet. Start the conversation.