AI & Agents

Claude Context Window: Sizes, Limits, and How to Maximize It

Claude's context window determines how much text fits in a single conversation, and it varies more than most developers realize. Depending on the model, plan, and surface, you get anywhere from 200K to 1M tokens. Tokenizer differences mean the same 1M-token limit holds roughly 555,000 words on Opus 4.8 and 750,000 words on Sonnet 4.6, and features like compaction and automatic summarization extend conversations well past those native limits.

Fast.io Editorial Team 9 min read
Neural network visualization representing context processing and token management

What Claude's Context Window Actually Means

Anthropic's model documentation reveals that Claude's 1M-token context window covers roughly 555,000 words on Opus 4.8 but approximately 750,000 words on Sonnet 4.6. That 35% gap stems from a tokenizer change introduced with Opus 4.7, where the same English text produces roughly 30% more tokens than with earlier models. Raw token counts tell an incomplete story about how much content Claude can actually handle.

A token is a chunk of text, typically a word or word fragment, that the model processes as a single unit. Claude's context window is the total number of these tokens the model can hold in working memory during a single request or conversation. This includes everything: your system prompt, the full conversation history, tool definitions, any uploaded files, and the response Claude is generating. If the model needs to reason about something, it must fit inside this window.

Larger context windows let you work with longer documents, maintain deeper conversation histories, and run complex multi-step agent workflows without losing earlier context. But more capacity doesn't automatically mean better results. Anthropic's own documentation warns of "context rot," where accuracy and recall degrade as token count grows. Claude posts strong results on long-context retrieval benchmarks like MRCR and GraphWalks, but those scores depend on curating what's in context, not just fitting as much as possible.

The subtlety most developers miss is that context window size varies by surface. The same model offers different effective context depending on whether you're using claude.ai chat, Claude Code, or the API. Opus 4.8 gives you 500K tokens in chat but 1M in Claude Code and through the API. That means code written against the API won't always match the behavior you see in the chat interface, and understanding these differences saves real debugging time.

Context Window Sizes Across Models and Surfaces

The table below shows the context window for each current Claude model across the three main surfaces. All numbers come from Anthropic's official support documentation and model overview pages, verified as of June 2026.

Model Chat (claude.ai) Claude Code API Max Output
Opus 4.8 500K tokens 1M tokens 1M tokens 128K tokens
Opus 4.7 500K tokens 1M tokens 1M tokens 128K tokens
Opus 4.6 500K tokens 1M tokens 1M tokens 128K tokens
Sonnet 4.6 500K tokens 1M tokens 1M tokens 64K tokens
Haiku 4.5 200K tokens 200K tokens 200K tokens 64K tokens

Claude Fable 5, released in June 2026, supports 1M tokens on the API and in Claude Code with up to 128K output tokens per request. It is Anthropic's most capable widely released model.

Several caveats affect how these numbers play out in practice.

Tokenizer differences change real-world capacity. Models from Opus 4.7 onward (including Opus 4.8 and Fable 5) use a newer tokenizer that produces roughly 30% more tokens for the same text. In practical terms, 1M tokens on Opus 4.8 holds about 555,000 words (roughly 2.5 million Unicode characters), while 1M tokens on Sonnet 4.6 holds about 750,000 words (roughly 3.4 million characters). If you're migrating between model generations, expect the same document to consume more context on newer models.

Pro users need usage credits for 1M in Claude Code. The extended 1M-token context window in Claude Code requires Pro users to enable usage credits for Opus models. Sonnet 4.6 also requires usage credits for its 1M Code window, except on Enterprise usage-based plans. Without credits enabled, you'll work within the standard chat-tier context.

Max output is separate from context. The maximum tokens Claude can generate in a single response ranges from 64K (Sonnet 4.6, Haiku 4.5) to 128K (Opus models, Fable 5). On the Batch API, Opus 4.8, 4.7, 4.6, and Sonnet 4.6 support up to 300K output tokens using the output-300k-2026-03-24 beta header. Output tokens count against the context window, so a 128K response in a 1M window leaves 872K for input.

Microsoft Foundry is an exception. Claude Opus 4.8 on Microsoft Foundry has a 200K-token context window instead of the standard 1M available on other platforms.

AI-powered document processing showing smart summaries and context analysis

How Extended Thinking Interacts with Context

Extended thinking lets Claude reason step-by-step before responding, generating internal "thinking tokens" that improve output quality on complex tasks. These tokens have specific implications for context window management that are worth understanding before you rely on them in production.

During the turn they're generated, thinking tokens count toward the context window limit and are billed as output tokens. But on subsequent turns, Anthropic's API automatically strips thinking tokens from previous messages. You don't need to remove them yourself. This means thinking tokens don't accumulate across a multi-turn conversation.

If Claude uses 80K thinking tokens in turn one, those tokens don't carry forward to turn two. The effective formula for context usage on any given turn is: context window minus input tokens from all previous turns (with their thinking stripped) minus current turn output (including both thinking and the visible response). This design lets Claude think extensively without permanently consuming context capacity.

One important exception applies during tool use. When Claude makes a tool call with extended thinking enabled, you must preserve the complete, unmodified thinking block when posting tool results back. The API verifies thinking blocks with cryptographic signatures, and modifying or dropping them during a tool use cycle causes an error. Once the tool cycle completes and a new user message arrives, the thinking blocks can be safely dropped (or the API strips them automatically).

Context awareness is a related feature available on Sonnet 4.6, Sonnet 4.5, and Haiku 4.5. These models receive explicit information about their remaining token budget throughout a conversation. At the start, Claude sees its total context window. After each tool call, it gets an update showing tokens used and tokens remaining. This helps Claude manage long-running agent sessions more effectively by deciding whether to continue a task or wrap up before hitting the limit, rather than guessing how much space is left.

Working Beyond Native Context Limits

Even 1M tokens has boundaries. Long agent sessions, multi-document analysis, and extended code reviews can push past what a single context window holds. Several built-in strategies and external approaches help you work past these limits.

Automatic Summarization in Chat

On paid claude.ai plans with code execution enabled, Claude automatically manages conversation context. When a conversation approaches the window limit, earlier messages are condensed into summaries to make room for new content. This summarization happens transparently, doesn't count toward your usage limit, and keeps the full chat history accessible. You can keep talking without manually managing what stays in context.

Server-Side Compaction for API Users

Compaction is a beta feature that provides server-side summarization for API conversations. When input tokens exceed a configurable trigger threshold (default: 150,000 tokens, minimum: 50,000), Claude generates a summary of the conversation and replaces older messages with that summary. It's available for Fable 5, Opus 4.8, 4.7, 4.6, and Sonnet 4.6.

To enable compaction, add the compact-2026-01-12 beta header and a context_management parameter:

response = client.beta.messages.create(
    betas=["compact-2026-01-12"],
    model="claude-opus-4-8",
    max_tokens=4096,
    messages=messages,
    context_management={
        "edits": [{"type": "compact_20260112"}]
    },
)

You can customize the trigger threshold, provide custom summarization instructions to focus on preserving specific types of information (code snippets, decisions, variable names), and pause after compaction for manual review. Compaction integrates with prompt caching, so adding a cache breakpoint on your system prompt keeps it cached across compaction events.

Retrieval-Augmented Generation Instead of stuffing everything into context, a retrieval-based approach stores documents externally and fetches only the relevant sections when needed. This keeps your context window focused on the material Claude needs for the current task and avoids context rot from loading irrelevant background content.

You can build RAG pipelines with vector databases like Pinecone, Weaviate, or pgvector, connecting them to Claude through tool use. Alternatively, platforms that handle indexing automatically can remove the infrastructure overhead. Fast.io Intelligence Mode, for instance, auto-indexes uploaded files for semantic search and citation-backed AI chat. Upload documents to a workspace, enable Intelligence, and query them without consuming context tokens. Agents can access the same workspace through the Fast.io MCP server, so retrieval queries integrate directly into agentic workflows with the free agent plan (50GB storage, 5,000 credits/month, no credit card).

RAG is especially valuable when working with document collections that exceed even the 1M-token limit, or when you want to keep the active context window focused on the current task rather than filled with reference material the model may not need on every turn.

Context Editing

For more granular control, Anthropic offers context editing strategies through the API. You can clear old tool results in agentic workflows when earlier outputs are no longer relevant, and separately manage thinking blocks from extended thinking sessions. These let you selectively remove specific parts of the conversation history without summarizing the entire thread.

AI chat interface showing a contextual response with document-backed citations
Fastio features

Stop cramming documents into your context window

Fast.io Intelligence Mode auto-indexes files for semantic search and AI chat with citations. 50GB free storage, no credit card, and an MCP endpoint ready for agent integration.

Best Practices for Context Window Management

Picking the right model and curating what goes into context matters more than maximizing the raw window size. These guidelines draw from Anthropic's documentation and common development patterns.

Match the model to the workload. Processing a 200-page contract or running a day-long agent session calls for a 1M-token model like Opus 4.8. Answering short customer questions works better with Haiku 4.5 at 200K tokens, which responds faster and costs one-fifth the price ($1/$5 per million tokens for input/output versus $5/$25 for Opus 4.8).

Count tokens before sending. Anthropic provides a token counting API that estimates usage before you make a request. Use it to prevent hitting context limits mid-conversation, especially in agentic workflows where tool results and thinking tokens add up unpredictably. The token counting endpoint also applies existing compaction blocks, so you can check the post-compaction token count before sending a message.

Enable prompt caching for repeated content. If your system prompt, tool definitions, or reference documents appear in every API request, prompt caching reduces input costs by charging lower rates for cache hits. Cached content still occupies context window space, but you avoid re-processing it on every turn. Place a cache_control breakpoint at the end of your system prompt for the best results.

Handle overflow gracefully. On Claude 4.5 models and newer, if input tokens plus max_tokens exceeds the context window, the API accepts the request and processes what it can. When generation reaches the limit, it stops with stop_reason: "model_context_window_exceeded" instead of returning an upfront validation error. Check for this stop reason in your response handling code and implement fallback logic, whether that means compacting the conversation, splitting the request, or escalating to a human.

Account for tokenizer changes when migrating. Moving from Opus 4.6 to Opus 4.8 means your existing prompts and documents will consume roughly 30% more tokens due to the newer tokenizer. Test your workflows against the new model's token consumption before switching in production, and adjust your trigger thresholds and token budgets accordingly.

Curate context aggressively. Anthropic's documentation is explicit: context quality matters more than quantity. Strip irrelevant conversation history, clear stale tool results, and use compaction or external retrieval to avoid filling the window with information Claude doesn't need for the current task. A focused 200K-token context often outperforms a cluttered 1M-token context on accuracy and recall.

Frequently Asked Questions

What is Claude's context window?

Claude's context window is the total amount of text, measured in tokens, that can be included in a single conversation or API request. It functions as working memory and includes the system prompt, conversation history, tool definitions, uploaded files, and the response being generated. Depending on the model and surface, it ranges from 200K tokens (Haiku 4.5) to 1M tokens (Opus 4.8, Sonnet 4.6, Fable 5 on the API).

How many tokens can Claude handle?

Claude's token capacity depends on the model and where you use it. Opus 4.8, Opus 4.7, Opus 4.6, and Sonnet 4.6 support up to 1M tokens on the API and in Claude Code, and 500K tokens in claude.ai chat. Haiku 4.5 supports 200K tokens across all surfaces. Fable 5 supports 1M tokens on the API and in Claude Code. The newer tokenizer on Opus 4.7 and later models means 1M tokens covers about 555,000 words, compared to 750,000 words on models with the older tokenizer.

Does Claude have a 1 million token context window?

Yes. Claude Opus 4.8, Opus 4.7, Opus 4.6, Sonnet 4.6, and Fable 5 all support 1M-token context windows on the API and in Claude Code. In claude.ai chat, Opus and Sonnet 4.6 models offer 500K tokens. The 1M context window in Claude Code requires Pro users to enable usage credits for Opus models.

How do I use Claude with very long documents?

For documents that fit within the context window, upload them directly as attachments or paste them into a message. For larger collections, use retrieval-augmented generation (RAG) to store documents externally and fetch relevant sections on demand. Fast.io Intelligence Mode, vector databases like Pinecone, or custom embeddings pipelines all work for this purpose. The API's compaction beta can also summarize older conversation content to free up context space during extended sessions.

What is the difference between context window and max output tokens?

The context window is the total capacity for all input and output combined. Max output tokens is the limit on how much Claude can generate in a single response. For example, Opus 4.8 has a 1M-token context window but a 128K max output. A request needs enough room in the context window for both the input and the generated output.

Related Resources

Fastio features

Stop cramming documents into your context window

Fast.io Intelligence Mode auto-indexes files for semantic search and AI chat with citations. 50GB free storage, no credit card, and an MCP endpoint ready for agent integration.