Skip to content
CW101
Generally availableOfficialConcept

Context window management

How Claude Code fills, compacts and caches the context window, and why long sessions behave differently from short ones.

Last verified August 21, 2026 · 3 sources

Everything Claude Code knows in a given moment is in one context window: your CLAUDE.md, the tool definitions, the files it has read, the commands it has run, the conversation so far.

Current models give it a lot of room — 1M tokens on Opus 5 and Sonnet 5, 200K on Haiku 4.5 — but the window is finite, and how it is spent determines how well a long session behaves.

The three levers

Compaction. When context grows long, some or all of it is summarised and the session continues from the summary plus whatever remains. Work does not have to stop, but detail is lost — which is why important decisions belong in a file, not only in the conversation.

Delegation. A subagent does the context-expensive part in its own window and returns only the conclusion. This is the main structural tool for keeping a lead session clean.

Caching. Claude Code uses prompt caching so the stable prefix of a session — instructions, tool definitions, files already read — is not reprocessed at full price on every turn.

What costs more than people expect

  • Tool definitions, charged on every request. A browser-use toolset is ~6,600 input tokens before anything happens. See tool use.
  • A long CLAUDE.md, read every session.
  • Large file reads. Reading only the part you need is not premature optimisation here.

The tokenizer changed

Claude Opus 4.7 and later — including every Claude 5 model — use a newer tokenizer that produces roughly 30% more tokens for the same text. A file that fit comfortably before may not now, and token-budget logic calibrated on Sonnet 4.6 will under-count.

Sources

  1. 01Explore the context window — Claude Code docsOfficialcode.claude.com
  2. 02How Claude Code uses prompt cachingOfficialcode.claude.com
  3. 03Context windows — Claude Platform DocsOfficialplatform.claude.com

Page changelog

  1. VerifiedChecked against the Claude Code context window and prompt caching pages.

Referenced by

Start typing to search every entity in the reference.