The context window limits what a model can work with during a response. It includes more than the user’s latest message: instructions, conversation history, tool definitions, and tool results also consume space. Generated output needs room too.
Exceeding the budget does not always silently drop the oldest text. Behavior depends on the API, model, and application. A request may be rejected, generation may stop at the limit, or the application may shorten the input through truncation or compaction. Compaction changes the information the next request receives; it does not enlarge the model’s window.
Anthropic’s context-window documentation explains its input/output accounting and model-dependent overflow behavior. Check the documentation for the particular model you deploy.
For builders, the useful check is whether the request preserves the instructions and evidence needed for the task while leaving room for the answer. A larger budget gives you more space, but does not tell you which information belongs there.
See AI vocabulary in plain English for this term alongside the other language of models, data, agents, and infrastructure.
Try the token-budget exercise below: compare a request whose input fits but leaves no room for output with one that keeps some headroom.
Leave room for the answer
Try an invented 16,000-token window. Instructions, the current request and tool definitions use 2,000 fixed tokens. Change the other allowances and check what remains for output.
These assigned counts teach the arithmetic; they are not estimates or recommended settings for a real model. Output allowance covers the visible answer and any reasoning tokens together. Actual model and API accounting still needs checking.
The worked example below is exactly full. Enable JavaScript to adjust it; the two contrasting examples and explanations also work without JavaScript.
- Input
- 14,000 tokens
- Output allowance
- 2,000 tokens
- Planned total
- 16,000 / 16,000
Exactly full, with no headroom. 14,000 input + 2,000 output allowance = 16,000 tokens.
The bar stops at the window’s capacity; any excess is counted in the text. Nothing here removes tokens or simulates how an API handles overflow. A budget that fits does not establish that the evidence is relevant or the answer correct.
Compare two worked budgets
Input fits; output doesn’t: Over budget by 2,000 tokens. 16,000 input + 2,000 output allowance = 18,000 tokens. The input alone fills the window. It leaves no room for the planned output.
Leave headroom: 2,000 tokens of headroom. 10,000 input + 4,000 output allowance = 14,000 tokens. This request uses a smaller input and reserves more for output. Choosing what to omit still requires checking what the task needs.
Does prompt caching free space in the window?
No. Cached input still occupies context. Caching can change the processing or price of reused input; it does not make that input disappear. Shortening or compacting the input changes what the next request receives and needs a separate check that important information survives.
Primary references: Anthropic’s context-window accounting and OpenAI’s reasoning-token accounting.
Hear it from the guest
“The math is never gonna change. You want to deliver to the context window exactly what the model needs, nothing more as efficiently as possible”
“So working memory is your context window. It's short term, it's limited.”
Quotes lightly edited to remove filler words.
Sources
- Claude Docs: Context windows — Explains input and output token accounting and model-dependent behavior when a request exceeds the window.
Go deeper
- What is a context window in AI, and why does it fill up? AI, decoded · What a Context Window Is, and Why It Fills Up
- What is context in an AI agent? AI, decoded · The 5 Sources of Context an AI Agent Needs
- What is context poisoning, and how do you stop it? AI, decoded · Context Poisoning: Why Good Models Still Fail
- Can an AI agent actually run your workday? AI, decoded · Can an AI Agent Run Your Workday?
- Anthropic: Effective context engineering for AI agents article
Compare just-in-time retrieval, compaction and persistent notes when a long task needs more information than one useful request can retain.
From the conversation
-
Context Poisoning is Killing Your AI Agents: How to Stop it | Michel Tricot, Airbyte -
Got Agents? Agentic Workflows & Architecture | Weaviate, Unstructured & CrewAI -
Agent Memory: The Last Battleground in the AI Stack | Richmond Alake, Oracle -
How Cisco Secures Personal AI Assistants for 90,000 Employees | DJ Sampath -
Why Context Alone Isn't Enough for Enterprise AI Agents | WisdomAI CPO Kapil Chhabra -
The Enterprise AI Deployment Playbook | ServiceTitan, Indeed & Twilio -
Slack Wants to Be the Context Harness for Code | CPO Jaime DeLanghe -
The AI Framework Era Is Over: Why Context Is the Moat | Jerry Liu of LlamaIndex