Skip to main content

Context Window & Context Rot

Understanding context windows is essential for effective coding agent usage. This guide explains what context windows are, how performance degrades as they fill, and strategies to manage them.

What Is a Context Window?

A context window is the total amount of text (measured in tokens) that an AI model can process in a single interaction. This includes:

  • Input: Your conversation history, file contents, tool results
  • Output: The model's responses

Different models have different context window sizes. See the Models page for specific limits.

Token Basics

A token is roughly 4 characters or 3/4 of a word. A 200k token context window can hold approximately 150,000 words or about 500 pages of text.

Context Rot: Performance Decay

Context rot refers to the degradation in model performance as the context window fills up. This manifests as:

  • Ignoring instructions - The model may overlook earlier instructions
  • Over-indexing - Focusing too heavily on recent or prominent text
  • Reduced accuracy - More mistakes in code generation and reasoning
  • Slower responses - Longer processing times as context grows

The relationship isn't linear: performance typically remains good until about 60-70% capacity, then degrades more rapidly.

Performance

100%├────────────────╮
│ ╲
80%├ ╲
│ ╲
60%├ ╲
│ ╲
40%├ ╲
│ ╲
20%├ ╲
│ ╲
0%├──────────────────────────╲────
0% 20% 40% 60% 80% 100%
Context Usage

1M Context Window

Some models (Claude Opus 4.6, Claude Sonnet 4) support an extended 1M-token context window — 5x the standard 200K limit. This can be enabled via the Claude Code model picker by selecting "Opus (1M context)". See the Claude Code setup guide for configuration details.

Benefits

  • Hold larger codebases in memory without hitting token limits
  • Work with multiple large files simultaneously
  • Maintain longer conversation histories

Tradeoffs

  • Context rot still applies — a larger window gives you more room, but performance still degrades as usage increases. The degradation curve is the same shape, just stretched across more tokens.
  • Cost — requests exceeding 200K input tokens are billed at 2x the standard input rate.
  • Latency — larger contexts increase processing time, especially time-to-first-token.

Best Practices with 1M Context

  • Use /compact regularly, even with the larger window — context rot doesn't disappear, it just starts later
  • Monitor the context indicator — the same percentage thresholds apply (50%, 70%, 90%)
  • Reserve the 1M window for tasks that genuinely need it (e.g., large codebase refactors, multi-file analysis)
  • For typical development tasks, the standard 200K window is sufficient and more cost-effective

Managing Context in Claude Code

Claude Code provides several tools to monitor and manage context usage.

Context Indicator

Below the prompt, you'll see a percentage indicator showing current context usage:

> Your prompt here
[42% context]

Slash Commands

CommandDescription
/contextExamine what's currently in your context window
/clearClear the context completely, starting fresh
/compactCompress the conversation while preserving key information

Plan Mode Auto-Clear

When you accept a plan in Plan mode, context is automatically cleared before implementation begins. This:

  • Improves plan adherence
  • Gives the agent a fresh start for implementation
  • Prevents earlier exploration from interfering with execution

Best Practices

Keep Tasks Small

The most effective strategy is limiting task scope:

  • One behavior change per task - Don't combine unrelated changes
  • PR-sized diffs - If it wouldn't fit in a single PR, break it down
  • Clear acceptance criteria - Know when the task is complete

Start Fresh for New Tasks

When switching to a new task:

  1. Complete or abandon the current task
  2. Use /clear to reset context
  3. Provide fresh context for the new task

Use Plan Mode Effectively

For complex tasks:

  1. Enter Plan mode to explore and design
  2. Refine the plan iteratively
  3. Accept the plan (auto-clears context)
  4. Let the agent implement with fresh context

Monitor Context Usage

  • Below 50% - Full performance, no concerns
  • 50-70% - Consider if you can complete soon or should compact
  • Above 70% - Strong candidate for /compact or /clear
  • Above 90% - Likely experiencing degradation, clear recommended

When to Use Each Command

ScenarioRecommended Action
Starting a new, unrelated task/clear
Long conversation, same task/compact
Debugging, need to see what model "knows"/context
Performance feels degraded/compact or /clear
About to implement an approved planLet auto-clear handle it