Before you start
You need nothing installed for most of this lesson, only a chat you can keep adding to. If you use Claude Code, you can also run its /context command along the way. Every number below is in tokens.
Work inside the window in five moves
The five moves follow what the vendors' pages say about how a window fills and where quality slips. The two commands are Claude Code's, which its docs describe.
/context
/compact focus on the API changes- List what you send every turn. Instructions, the conversation so far, any files or tool results and your next message all count. In Claude Code,
/contextshows what is using space. - Start a fresh chat for each new task. Claude Code's docs say every new session starts with a fresh context window, without the history of earlier sessions.
- Put long documents first and the question last. Anthropic's guide says to place long-form data near the top, above your query, and Google's long context page says to put the question at the end.
- Ask for quotes before conclusions. For long documents, Anthropic suggests asking the model to quote the relevant parts first, which helps it focus on them and ignore the rest.
- Summarize before the window fills. Ask a long chat for its decisions and open questions, then paste that into a new chat. This is the manual version of compaction, and
/compact focus on the API changesdoes it in Claude Code with a focus you choose.
What fills the window, turn by turn
Anthropic's context windows page says everything in the request counts: the system prompt, every message including tool results, images and documents, and your tool definitions. The model's reply counts too, with any thinking. Each turn's input holds all earlier turns plus the new message, and the reply becomes part of the next input.
Claude Code's window holds more than the chat. Its docs list conversation history, file contents, command outputs, CLAUDE.md, auto memory, loaded skills and system instructions.
Turn 1
The system prompt, any tool definitions and your first message go in. The reply comes out.
Turn 2
Everything from turn 1, the reply included, goes in again with your new message.
Later turns
Attached files and tool results sit in the history too, and the pile grows with each reply.
Near the limit
The product has to cut, summarize or stop, which the table below shows.
How big windows are
Sizes change with each model, so read these as the vendors' pages stated them on 4 November 2026.
The Gemini figure is shared, so a long reply leaves less room for input. Google's page says earlier Gemini 3 and 2.5 models keep separate budgets of 1M input tokens and 64K output tokens.
1M
tokens in the window of Claude Fable 5.1, Opus 5.5, Sonnet 5.5, Haiku 5.5 and the other models that page lists
Source: Anthropic: Context windows (read November 4, 2026)
200k
tokens in the window of Anthropic's other models, including the deprecated Claude Sonnet 4.5
Source: Anthropic: Context windows (read November 4, 2026)
128k
output tokens one request to a 1M-token Claude model can generate at most
Source: Anthropic: Context windows (read November 4, 2026)
1,048,576
tokens in Gemini 4's window, shared by input, thinking and output
Source: Google AI Studio: Long context (read November 4, 2026)
What happens when it is full
The same limit shows up differently in an API, a chat app and a coding agent.
| Where | What happens | Source |
|---|---|---|
| Claude API, input alone over the window | The API returns a 400 invalid_request_error, "prompt is too long". | Anthropic: Context windows |
Claude API, input plus max_tokens over the window | On Claude 4.5 and newer the request is accepted, and generation stops with stop_reason: "model_context_window_exceeded" when it hits the limit. Earlier models return a validation error. | Anthropic: Context windows |
| Chat apps such as claude.ai | They can manage the window on a rolling first in, first out basis, so the oldest turns drop out. | Anthropic: Context windows |
| Claude Code | It compacts the conversation into a summary that keeps your requests and key code snippets. Detailed instructions from early on may be lost. | Claude Code docs: How Claude Code works |
| Gemini 4 API | If input plus max_output_tokens exceed 1,048,576, the API caps the output to the space that remains. | Google AI Studio: Long context |
Why a bigger window is not automatically better
Anthropic's engineering article explains it with an attention budget. Every new token uses up part of what the model can attend to, and each token can relate to every other one, so a long context stretches it thin. Google's long context page sees the same pattern. Accuracy drops when a prompt holds many facts to retrieve rather than one, and longer inputs generally increase the time to the first token.
The aim is therefore to curate. Anthropic's article puts it as finding the smallest possible set of high-signal tokens that maximize the likelihood of the outcome you want.
more context isn't automatically better. As token count grows, accuracy and recall degrade, a phenomenon known as context rot.
How agents get past the limit
- Compaction. The conversation is summarized and a new window starts from the summary. Anthropic offers server-side compaction in beta for Claude 4.6 and later models.
- Notes outside the window. The agent writes progress to a file such as NOTES.md and reads it back later, as the engineering article describes.
- Sub-agents. A specialized sub-agent works in its own clean window and hands back a summary, often 1,000 to 2,000 tokens in Anthropic's article. Claude Code subagents works this way.
- Loading on demand. Claude Code shows a skill's description at the start of a session and loads its full content only when the skill is used.
Andrej Karpathy on context engineering, and Summer Yue on an instruction lost to compaction
People who build with these models now call the skill context engineering. On 19 June 2025 Tobi Lütke, Shopify's chief executive, wrote that he preferred the term to prompt engineering, because it names the art of giving the model all the context a task needs. Andrej Karpathy, an AI researcher and educator and a founding member of OpenAI, agreed on 25 June 2025. In real apps, he wrote, the work is putting exactly what the next step needs into the window. Too little and the model lacks what it needs, while too much can raise costs and lower quality.
Summer Yue, who works on safety and alignment at Meta Superintelligence, posted on 23 February 2026 about a window that filled mid-task. She had told an agent to suggest what to archive or delete in her inbox and to act only when she said so. That worked on a small test inbox, but her real inbox was big enough to trigger compaction, and her original instruction was lost.
That is the risk in the Claude Code row of the table above. A rule that must survive belongs outside the chat. In Claude Code, put it in CLAUDE.md, where the docs also let you add a Compact Instructions section that says what to keep. For an agent that can delete things, keep the "ask me first" rule in its standing instructions, not in an early message.
context engineering is the delicate art and science of filling the context window with just the right information for the next step.
Screenshots of X's own embeds of the posts, taken on 5 November 2026, with the time in UTC. X cuts Karpathy's post short with Show more. Select one to open the post on X.
Common mistakes
- Pasting everything because the window is big. More tokens is not the same as more help.
- Keeping one chat running for every task, so old material keeps taking space.
- Trusting an early instruction deep into a long chat. Claude Code's docs say detailed instructions from early on may be lost when it compacts, and they suggest putting persistent rules in CLAUDE.md.
Try it yourself
- In Claude Code, run
/contextwhen a session begins and again after a long task, and note what grew. - Ask a long chat for a summary of its decisions and open questions, paste it into a new chat and check whether the first answer still has what it needs.
- Put a long document above your question, ask for relevant quotes first and see whether the answer stays closer to the text.
Next: AI agents
A context window is the room an agent works in, which is why agents need ways to cut, summarize and move things out. The last lesson, what an AI agent is, shows the loop that fills it.
Tokens are the unit throughout. What is a token in AI covers the counting, and its chart shows how much one request can hold.
Check yourself
Which of these count toward the context window in one request?
Show answer
D. The system prompt, every message, tool results, files and the reply Anthropic's page says everything in the request counts, and the model's reply counts too, so each turn's input holds all earlier turns.
You are asking a question about a long document. Where should each part go?
Show answer
A. The document above, with the question last Anthropic says to place long-form data near the top, above your query, and Google says to put the question at the end.
Claude Code compacts a long session. What can be lost, and where should lasting rules live?
Show answer
C. Early detailed instructions can be lost, so keep persistent rules in CLAUDE.md Claude Code's docs say detailed instructions from early on may be lost when it compacts, and they suggest putting persistent rules in CLAUDE.md.
Does a bigger window always give a better answer?
Show answer
B. No, accuracy and recall can degrade as the token count grows Anthropic calls the drop in accuracy and recall as the token count grows context rot, so the aim is to curate what goes in.
Frequently asked questions
Is a context window the same as memory?
No. Anthropic calls the window a working memory for the current conversation, separate from the data the model was trained on. What survives between sessions lives elsewhere, such as Claude Code's CLAUDE.md file and auto memory.
Is the context window measured in words or tokens?
Tokens. OpenAI's guide defines the window in tokens, the chunks of data you pass in, from text to images. Our guide to what a token is shows how a count differs from a word count.
Why does the model forget what I said earlier?
Two causes are common. The product may have dropped or summarized older turns once the window filled, and recall degrades as a long context grows. Claude Code's docs advise putting persistent rules in CLAUDE.md.
Does prompt caching make the window bigger?
No. Anthropic says cached prompt prefixes still occupy the window. Caching changes what you pay for those tokens, not whether they count.
How do I see how many tokens a request will use?
In the Claude API, each response reports what the request consumed in its usage field, and a token counting API estimates a request before you send it. In a Claude Code session, /context shows where the room is going.
Which model has the biggest context window?
Check the vendor's model table, because the numbers change with each release. Anthropic points to its model comparison table for sizes by model, and the figures in this lesson were read on 4 November 2026.
Sources
- Anthropic: Context windows https://platform.claude.com/docs/en/build-with-claude/context-windows
- Anthropic Engineering: Effective context engineering for AI agents https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
- Anthropic: Prompting best practices https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices
- Google AI Studio: Long context https://aistudio.google.com/docs/long-context
- OpenAI: Prompt engineering https://developers.openai.com/api/docs/guides/prompt-engineering
- Claude Code docs: How Claude Code works https://code.claude.com/docs/en/how-claude-code-works
- Tobi Lütke on X, 19 June 2025 https://x.com/tobi/status/1935533422589399127
- Andrej Karpathy on X, 25 June 2025 https://x.com/karpathy/status/1937902205765607626
- Summer Yue on X, 23 February 2026 https://x.com/summeryue0/status/2025836517831405980


