docsfoundations7 min read

Claude Code Context Window: Size, /context and /compact

Opus 5.5, Sonnet 5.5 and Haiku 5.5 all hold 1M tokens. What fills the window, how to read the breakdown with /context, and when /compact is the wrong fix.

What Is the Context Window?

Think of it like working memory. Everything in your current session (your messages, Claude's responses, file contents it has read, command outputs) occupies space in this window. When it gets close to full, Claude Code compacts automatically: it clears old tool output first, then summarizes the conversation. Your session keeps going, but the summary is lossy, so details you said early on can get dropped.

How Big Is It?

Depends which model you are on, and the difference is larger than most people expect:

ModelContext windowRoughly
Claude Opus 5.51,000,000 tokens~555,000 words
Claude Sonnet 5.51,000,000 tokens~555,000 words
Claude Haiku 5.51,000,000 tokens~555,000 words

All three current models hold the same million tokens, so you no longer pick a model for size. Haiku 5.5 has one catch: a prompt over 100,000 tokens costs 5x more per token ($0.50 / $0.10 = 5 on input). On Haiku, a lean context saves money long before the window is full. A million tokens sounds like more than you could ever fill. It still goes faster than you think in agentic work, where Claude reads files, runs commands, and feeds the output back into the loop.

The summary keeps file changes, decisions and the current task, and drops dead ends and verbose output.

A rough sense of scale:

ContentApproximate tokens
A typical source file (200-400 lines)500-2,000
A large source file (1,000 lines)3,000-5,000
Reading 50 files in a session~50,000 (25% of your window)
A long back-and-forth conversation (30+ exchanges)20,000-40,000
Command output from a failing test suite5,000-15,000
Delegating that 50-file read to a sub-agent instead~300-800 (a summary comes back, not the files)

A focused single task usually fits fine. A marathon session with multiple tasks, lots of file reading, and long debugging conversations will hit the wall.

Signs You Are Running Out

You'll notice these before any explicit warning:

  • Responses get less accurate. Claude Code "forgets" constraints you mentioned earlier or re-reads files it already looked at.
  • It loses track of decisions. You agreed on an approach 20 messages ago. Now it suggests something different.
  • Responses get shorter or cut off. The model is running out of room to generate.
  • You see context length warnings. Claude Code will tell you when things are getting large.

How Tokens Work

Roughly 4 characters equals 1 token. A word averages about 1.3 tokens. Code tends to be slightly more token-dense than prose because of syntax, indentation, and special characters.

Quick math: a 300-line TypeScript file is about 1,200 tokens. If Claude Code reads 40 files during a session, that's 48,000 tokens just from file content, before counting any conversation.

The /context Command

Before you decide whether to compact, look at what is actually filling the window. Run /context in Claude Code and it prints the current breakdown: how much the system prompt takes, how much your CLAUDE.md and other memory files take, how much the tool definitions take, and how much is left for the conversation itself.

This is the command most people never find, and it changes what you do next. A session sitting at 60% is not one problem, it is several possible problems, and they have different fixes:

  • Memory files are the biggest slice. Your CLAUDE.md is too long, or you are loading rule files you do not need for this task. Trim the file, do not compact the session.
  • Tool definitions are the biggest slice. You have too many MCP servers connected. Disconnect the ones this task does not need.
  • The conversation is the biggest slice. This is the case /compact actually fixes.

Checking first takes five seconds and stops you compacting a session whose real problem is a 2,000-line CLAUDE.md that will refill the window immediately.

The /compact Command

When context gets large, run /compact. This summarizes the conversation so far and continues from the summary. Think of it as taking notes from a meeting, then starting a new meeting with only the notes.

You can steer the summary. /compact focus on the auth bug fix keeps what you name, instead of what the automatic pass guesses is important. If you're switching to unrelated work, /clear is the better tool: it starts clean instead of carrying a summary you don't need.

When to use it:

  • After completing a task, before starting a new one
  • When you notice Claude Code forgetting earlier context
  • When you get a context length warning
  • Proactively, after any long debugging session

What it preserves: Key decisions, file modifications, current state of work.

What comes back automatically: your project-root CLAUDE.md, auto memory, and up to five of the files Claude read or edited, most recently modified first. A file over 5,000 tokens comes back as a path only.

What it loses: Exact file contents beyond those, detailed error messages, nuanced back-and-forth reasoning. Path-scoped rules and CLAUDE.md files in subfolders reload only when Claude works on a matching file again, so put anything that must survive compaction in the project-root CLAUDE.md.

Idle compaction can happen while you're away. In a terminal session on the one-hour prompt cache, a conversation of 200K tokens or more that sits idle for about 54 minutes gets compacted just before its cache expires, so your next message doesn't pay to reprocess all of it. CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS moves that 200K threshold (100,000 is the lowest it goes), and "idleCompaction": false in settings.json turns it off. Since v2.1.302 there's also an Idle compaction row in /config. If you come back to a shorter summary than you expected, this is why. See prompt caching for how the one-hour cache works.

Strategies to Stay Under the Limit

1. One session, one task

Don't let a single session accumulate context from five different tasks. Finish a task, start a new session for the next one. This is the single most effective strategy and most people never do it.

2. Use handoffs instead of marathon sessions

Instead of one 3-hour session, work in focused 30-60 minute blocks. End each block with a handoff (what was done, what's next). Start a fresh session that reads only the handoff. Fresh context every time.

See the session lifecycle guide for handoff protocols.

3. Point to files instead of pasting them

Let Claude Code read files on demand. Don't paste file contents into the chat. When you paste, that content stays in the conversation forever. When Claude Code reads a file with its tools, it's more efficient.

4. Use sub-agents for research

Sub-agents (via the Task tool) get their own context window. If you need Claude Code to explore a large codebase or research something, offload it to a sub-agent. The main conversation only gets the summary back. Concretely: the 50-file read in the table above costs ~50,000 tokens if it happens in the main thread; delegated to a sub-agent, the main thread only pays for the summary that comes back. This is one wall in a broader approach: see the subagent context-isolation pattern for how isolation scales across memory, agents, and cron state.

5. Be specific in your prompts

Vague prompts cause Claude Code to read more files searching for what you mean. "Fix the auth bug" makes it read every auth-related file. "Fix the token refresh logic in src/auth/refresh.ts where expired tokens are not being caught" sends it straight to the right file.

6. Use /compact between tasks

Even within one session, compact between distinct tasks. Finished adding tests? Compact. Now moving to a different feature? Clean slate, prior work summarized.

The Handoff Strategy

This is the power move for heavy users. Instead of fighting the context window, work with it:

  1. Work in a focused block (30-60 minutes, one task)
  2. End the session with a handoff: what was done, what's next, key decisions
  3. Start a new session. Load only the handoff and relevant CLAUDE.md
  4. Fresh 1M tokens, zero wasted context

You lose nothing because the handoff captures everything that matters. You gain a full context window for the next task. Over a full day of work, this approach is dramatically more effective than one long session that degrades as context fills up.

A Million Tokens Is a Lot. You Still Need Strategy.

Opus 5.5, Sonnet 5.5 and Haiku 5.5 give you a million tokens of working memory, which is enormous. The strategies above still matter, they just start biting later in a long session rather than sooner. Two things keep them relevant. Every token you carry is a token you pay for on the next turn, so a bloated session costs money on every message, not just once. And on Haiku 5.5, a prompt past 100,000 tokens moves to a price 5x higher per token.

Common questions

How big is the Claude Code context window?

Opus 5.5, Sonnet 5.5 and Haiku 5.5 all hold 1,000,000 tokens, roughly 555,000 words. On Haiku 5.5, a prompt over 100,000 tokens costs 5x more per token, so keep Haiku sessions lean.

What does the /context command do?

It shows you what is filling the window right now, broken down by system prompt, memory files, tool definitions and conversation. It changes nothing. Run it before compacting, because if your CLAUDE.md is the problem then compacting buys you about one turn.

How do I summarize the context?

/compact. It keeps decisions, file changes and current state, and drops the verbose middle.

What is the difference between /context and /compact?

/context is the diagnosis, /compact is the treatment. Checking first stops you treating the wrong thing.

Why does Claude Code forget things I said earlier?

The window filled and Claude Code compacted it, so early details now live only in a summary. You notice it as drifting accuracy before you ever see a warning.

Does a bigger window mean I can stop worrying?

No. You re-send and re-pay for the whole window on every turn, and accuracy starts sliding well before the window is actually full.

New guides, when they ship

One email, roughly weekly. CLAUDE.md templates, workflows I actually use, and the cut-for-length stuff that does not make the public guides. One-click unsubscribe.

Or read Product Field Notes, the Substack