Claude Code holds the whole session in one context window and re-sends it every turn. Run /context to see what is filling yours, /compact at a task boundary to summarise while keeping decisions, and /clear between unrelated tasks. Auto-compaction fires near the model limit and the threshold is configurable with /autocompact. On the Claude API, Sonnet 5 and Opus 5 run a 1M token window; Haiku 4.5 runs 200K.
- Every turn re-sends the whole window, so size drives cost, latency, and accuracy together.
/contextis the first command to run. It breaks the window down by category./compactkeeps continuity,/cleardiscards it,/rewindrolls back. Three different tools.- Auto-compaction is configurable:
/autocompact 500kmoves the threshold and persists it. - Sonnet 5 and Opus 5 hold 1M tokens on the Claude API as of August 2026. Haiku 4.5 holds 200K.
What is actually in the window
A large part of the window is spent before you type anything. The system prompt, project memory, environment info, MCP tool names, and the skill listing all load at startup. Everything after that is work you caused.
Typical contributors, in the order they arrive.
| Source | When it loads | Reducible? |
|---|---|---|
| System prompt and tool definitions | Startup, every session | No |
CLAUDE.md and auto memory | Startup, re-injected after compaction | Yes, keep it short |
| Skill name and description listing | Startup, budgeted at 1 percent of the window | Yes, prune skills |
| MCP tool names | Startup, schemas deferred until used | Yes, disable unused servers |
| File contents the agent read | Per read, 1k to 20k a file | Yes, name the files |
| Command and test output | Per run, 200 to 10,000+ | Yes, scope commands |
| The conversation itself | Grows every turn | Yes, compact or clear |
/context # live breakdown by category, with suggestions
/usage # token counts and cost for this session
/doctor # includes the skill listing cost and its biggest contributors
Compact, clear, rewind, or ask on the side
People treat these as one control with different names. They are four different operations with different costs.
| Keeps decisions | Frees | Right when | |
|---|---|---|---|
/compact | Yes, summarised | Most of the history | Mid-task, still going |
/clear | No | Everything | The task is finished |
/rewind | Up to a checkpoint | Everything after it | A turn went wrong |
/btw | Not applicable | Nothing, and adds nothing | A side question |
Compact at a boundary, not at the ceiling
Auto-compaction fires as the window approaches the model limit, which is the worst possible moment: the summariser has the most material to compress and the least room to do it in. Running /compact deliberately when a subtask finishes gives it something coherent, and the summary carries decisions rather than a smear of everything.
/compact Keep the decision to use optimistic locking and the reason.
Drop the exploration of the alternatives.
Clear more often than feels natural
A long session feels like accumulated understanding. Past a point it is accumulated noise, and the agent is paying attention to a bug you fixed forty minutes ago. /clear between unrelated tasks costs nothing, takes no time, and usually improves the next answer as well as its price. Name the session with /rename first if you want to find it again with /resume.
What survives a compaction
This is the part almost nobody knows, and it explains the classic complaint that an agent "forgot the rules" halfway through a long session. Whether an instruction survives depends entirely on how it was loaded.
Per Anthropic documentation, checked August 2026.
| Mechanism | After compaction |
|---|---|
| System prompt and output style | Unchanged; never part of message history |
Project-root CLAUDE.md and unscoped rules | Re-injected from disk |
| Auto memory | Re-injected from disk |
Rules with paths: frontmatter | Lost until a matching file is read again |
Nested CLAUDE.md in a subdirectory | Lost until a file there is read again |
| Invoked skill bodies | Re-injected, capped per skill and in total |
| Hooks | Not applicable; hooks are code, not context |
The practical rule: if a rule must hold across a long session, it belongs in the project-root CLAUDE.md or a hook, not in a path-scoped rule and not in a skill you invoked once at the start.
Moving the auto-compact threshold
The auto-compact window is how full the context can get before Claude Code summarises. It is configurable in three places, and they do not have equal standing.
Set it for this session and future ones
/autocompact 500k # accepts 100K to 1M
/autocompact 200000 # a plain count works too
/autocompact auto # back to the window tuned for your model
This writes autoCompactWindow to your user settings. A higher-priority settings scope, such as managed enterprise settings, still wins for the running session and the command says so.
Override for one launch
claude --autocompact 300k
claude --autocompact auto # ignore your saved setting for this run
Unlike the slash command, the flag is not preempted by a higher-priority settings scope.
Force it in scripts and cloud environments
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=400000 # plain token count only
The environment variable outranks the command, the flag, and the setting. While it is set, /autocompact reports the override instead of changing anything.
How big the window actually is
Claude API context windows, checked against Anthropic documentation in August 2026.
| Model | Context window | Max output |
|---|---|---|
| Claude Opus 5 | 1M tokens | 128k |
| Claude Sonnet 5 | 1M tokens | 128k |
| Claude Fable 5 | 1M tokens | 128k |
| Claude Haiku 4.5 | 200k tokens | 64k |
- Sonnet 5 runs at 1M on the Claude API with no
[1m]variant to pick and no usage credits required, and auto-compacts at roughly 967K by default. - Behind an LLM gateway Claude Code cannot verify 1M support, so pick the 1M entry in the model picker, which maps to
sonnet[1m]. CLAUDE_CODE_DISABLE_1M_CONTEXT=1budgets Sonnet 5 sessions at 200K, for deployments that need the cap.- On Amazon Bedrock, Google Cloud, and Microsoft Foundry, Opus can run with a 200K window and compacts at that boundary instead.
Why size costs you twice
Context is re-sent on every turn, so it is charged repeatedly. Prompt caching softens this a great deal but does not remove it: a cache hit is billed at 10 percent of the base input rate, and the cache expires after one hour on a subscription, or five minutes on an API key or once you are drawing on usage credits.
Twenty turns at three context sizes on Sonnet 5, at the introductory $2 per million input rate in effect through 31 August 2026, assuming most input arrives as cache reads.
| Context held | Cumulative input | Approximate input cost |
|---|---|---|
| 20k, kept tight | ~400k tokens | about $0.08 |
| 80k, allowed to grow | ~1.6M tokens | about $0.32 |
| 180k, never cleared | ~3.6M tokens | about $0.72 |
The other half of the bill is the cache miss. Your first message after a break longer than the cache lifetime reprocesses the entire context at full input price. A session left open all day and touched every few hours pays that repeatedly, which is why an idle session is not a free session.
Questions people ask
The amount of conversation the model can hold at once. It includes the system prompt, project memory, the skill listing, every file read, all command output, and the conversation itself. On the Claude API in August 2026 that is 1M tokens for Sonnet 5 and Opus 5, and 200k for Haiku 4.5.
Compact summarises the conversation so far and keeps the decisions, at the cost of a large request. Clear discards everything instantly and costs nothing. Compact mid-task, clear between unrelated tasks.
Run /context inside the session for a live breakdown by category with optimisation suggestions, including which CLAUDE.md and memory files loaded. Run /doctor for the cost of the skill listing specifically.
Yes. Run /autocompact with a value between 100K and 1M, such as /autocompact 500k, which saves to your settings as autoCompactWindow. Use the --autocompact flag for one launch, or CLAUDE_CODE_AUTO_COMPACT_WINDOW in scripts, which overrides both.
Compaction dropped them. Project-root CLAUDE.md and auto memory are re-injected from disk, but path-scoped rules and nested CLAUDE.md files are lost until a matching file is read again, and invoked skills are re-attached only within a 25,000 token budget.
Yes, repeatedly, because the window is re-sent on every turn. Cache reads bill at 10 percent of the base input rate, so the damage is smaller than list price suggests, but a session that fills 180k can still cost several times one kept at 20k for the same number of turns.
No. Model accuracy degrades as the window fills whatever the ceiling is, and every token stays billable on each turn. The larger window is for a genuinely large read, not a substitute for /clear.
It restores the conversation and code to a previous checkpoint, so everything after that point leaves the window. It is the right tool when a specific turn went wrong, rather than when the session as a whole has grown too large.
Sources
Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.