Mindket

What is a context window? What fills it and what to do when it is full

A black banner titled "Prompt engineering" over the line "Prompts, system prompts, context windows and AI agents."

A context window is all the text a language model can refer to while it writes a response, the response included. It works like the model's working memory and is measured in tokens. Your messages, the system prompt, files and tool results all take space. When it is full, a product returns an error, stops mid-reply or summarizes the older part.

In this lesson

  • The system prompt, the whole chat so far, files, tool results and the reply all share one window.
  • A bigger window is not automatically better, because quality can slip as the token count grows.
  • Put long documents first and your question last, and start a fresh chat for a new task.
  • Claude Code has two commands for the window: /context to look and /compact to summarize.
All courses
On this page
  1. Before you start
  2. Work inside the window in five moves
  3. What fills the window, turn by turn
  4. How big windows are
  5. What happens when it is full
  6. Why a bigger window is not automatically better
  7. How agents get past the limit
  8. Andrej Karpathy on context engineering, and Summer Yue on an instruction lost to compaction
  9. Common mistakes
  10. Try it yourself
  11. Next: AI agents
  12. Check yourself
  13. Frequently asked questions
  14. Sources

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
  1. 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, /context shows what is using space.
  2. 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.
  3. 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.
  4. 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.
  5. 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 changes does 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.

How one chat grows
  1. Turn 1

    The system prompt, any tool definitions and your first message go in. The reply comes out.

  2. Turn 2

    Everything from turn 1, the reply included, goes in again with your new message.

  3. Later turns

    Attached files and tool results sit in the history too, and the pile grows with each reply.

  4. 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.

Context window figures as the vendors state them

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.

WhereWhat happensSource
Claude API, input alone over the windowThe API returns a 400 invalid_request_error, "prompt is too long".Anthropic: Context windows
Claude API, input plus max_tokens over the windowOn 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.aiThey can manage the window on a rolling first in, first out basis, so the oldest turns drop out.Anthropic: Context windows
Claude CodeIt 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 APIIf 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.

Anthropic, Claude API documentation · Anthropic: Context windows (read November 4, 2026)

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.

Andrej Karpathy, AI researcher and educator, a founding member of OpenAI · X (read November 5, 2026)
Andrej Karpathy (@karpathy) on X, 25 June 2025, quoting a post by Tobi Lütke. +1 for "context engineering" over "prompt engineering".
Andrej Karpathy on X, 25 June 2025
Summer Yue (@summeryue0) on X, 23 February 2026, replying to @petergyang. This has been working well for my toy inbox, but my real inbox was too huge and triggered compaction. During the compaction, it lost my original instruction.
Summer Yue on X, 23 February 2026

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 /context when 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

  1. 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.

  2. 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.

  3. 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.

  4. 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

  1. Anthropic: Context windows (read November 5, 2026)https://platform.claude.com/docs/en/build-with-claude/context-windows
  2. Anthropic Engineering: Effective context engineering for AI agents (read November 4, 2026)https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents
  3. Anthropic: Prompting best practices (read November 5, 2026)https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices
  4. Google AI Studio: Long context (read November 4, 2026)https://aistudio.google.com/docs/long-context
  5. OpenAI: Prompt engineering (read November 4, 2026)https://developers.openai.com/api/docs/guides/prompt-engineering
  6. Claude Code docs: How Claude Code works (read November 5, 2026)https://code.claude.com/docs/en/how-claude-code-works
  7. Tobi Lütke on X, 19 June 2025 (read November 5, 2026)https://x.com/tobi/status/1935533422589399127
  8. Andrej Karpathy on X, 25 June 2025 (read November 5, 2026)https://x.com/karpathy/status/1937902205765607626
  9. Summer Yue on X, 23 February 2026 (read November 5, 2026)https://x.com/summeryue0/status/2025836517831405980

Share this lesson

Count what is in your window

Our token guide shows how text and images turn into counts, and how much one request can hold.

Read the token guide

This lesson as Markdown · Prompt engineering course for beginners · All courses