deep · 5 min
Context window
The most tokens a model can take in and put out in one call, and what happens near the limit.
updated 23 Sept 2026
Say we paste a 300-page contract into a request and ask for a summary. Will it fit? And if it fits, will the summary be any good? Those sound like one question. They're two, and the gap between them is most of what there is to know about the context window.
Will it fit?
The context window is all the text a model can look at in one call, counted in tokens. It's the model's working memory for this one request, and a separate thing from what it learned in training.
The part people miss: the answer goes in the same window. The model writes one token at a time, and each new token is read along with everything before it. So the window has to hold the contract, our question and the summary, all together. Fill it with input and there's no room left to reply.
And "input" is more than what we typed. On Claude, as of 2026-09, the
system prompt counts, every earlier message counts (tool results, images
and documents too), tool definitions count, and so does any thinking the
model does before it answers. Thinking is the easy one to forget. It comes
out of the same max_tokens budget as the answer and gets billed as
output.
What about prompt caching, doesn't that free up room? No. Caching changes what you pay for repeated tokens, not whether they count.
So how big is the window? It's grown fast. GPT-3 in 2020 had 2,048 tokens. Later models went to 8,000, then 32,000, then 128,000. As of 2026-09 many Gemini models take a million or more, and the newer Claude models take a million and can write up to 128,000 tokens in one reply. A million tokens is roughly eight average novels, or 50,000 lines of code. Our contract should fit on most current models.
Tokens aren't the only limit, though. A request stuffed with big files can hit the size limit on the request itself first.
What happens when it doesn't fit
On Claude there are two ways to go over, and they fail very differently.
If the input alone is too long, the request bounces with a 400 error, "prompt is too long". Nothing gets written. Annoying, but you notice.
If the input fits and the answer runs out of room partway, newer Claude
models accept the request and just stop writing when the window is full.
The reply comes back with stop_reason: "model_context_window_exceeded".
No error. If our code doesn't check the stop reason, it'll hand the user
half a summary as if it were the whole thing. Count tokens before
sending (providers have an endpoint for that) and always read why a
response stopped.
Conversations fill the window more slowly but they get there. Each turn sends the whole history again (see the chat API), so every exchange adds a bit. Apps deal with that by dropping the oldest turns, by summarising old turns and carrying on (called compaction, which some APIs now do for you), or by fetching only the pieces that matter.
Will it be any good?
Now the second question. Our contract fits. Does the model read all of it equally well?
You'd hope a model treats the 100,000th token as carefully as the 100th. It doesn't. As the input grows, accuracy and recall slip. People call this context rot, and Anthropic's own docs warn about it on the same page that sells the million-token window.
The test you'll see quoted most is the needle in a haystack: hide one fact in a pile of filler and ask for it. Models ace it, around 99% on a single fact. But it's close to a word lookup. Make the task even a little more like real work and the scores come apart:
- ask for several facts at once
- add a distractor, a passage that looks like the answer but isn't (even one hurts, four hurt more, and it gets worse with length)
- ask the model to trace or combine things across the text
In one benchmark, 17 models all claimed windows of 32,000 tokens or more, and only half of them still did well at 32,000. Another set of tests found results getting shakier with length even on dull tasks like copying out a list of repeated words with one odd word in it.
One result nobody has a neat story for: models did better when the filler was shuffled into nonsense than when it read as a proper document. So how the text is laid out matters too, not only how long it is.
Why longer gets harder
There are two likely reasons, both from how models are built.
Inside the model, attention lets every token look at every other token. With n tokens that's n² pairs, so double the input and there are four times as many relationships to keep track of. The model's attention gets spread thinner as the window fills.
And models learn to use context from their training data, where short texts are far more common than long ones. They've had less practice at the far end of their window.
Neither is a cliff. Models stay capable at long lengths, just less precise. Which flips how we should think about the window: the goal is to find the smallest set of useful tokens that gets the job done.
For our contract, that might mean asking about one section at a time, or pulling out the clauses that matter first (retrieval is the general version of that idea). It also saves money: the whole contract gets sent, and billed, on every call, and a longer input takes longer before the first token comes back.
Here's what we can't say yet. The benchmarks above tested models from 2024 and 2025. The direction (longer input, worse accuracy) shows up everywhere. How big the drop is on the models we use in 2026 is something none of these sources measured. Which means for our contract, the only honest answer to "will the summary be good?" is to try it at the length we'll really send, on a task that looks like ours, and check.
Further reading
- Context windows, Anthropic docs. The practical page: what counts, sizes per model, and the two ways overflow fails.
- Context Rot: How Increasing Input Tokens Impacts LLM Performance, Chroma, 2025. Read this before trusting a needle test. The shuffled haystack result is here.
- RULER: What's the Real Context Size of Your Long-Context Language Models?, Hsieh et al. (NVIDIA), 2024. Claimed window versus usable window, measured.
- Long context, Google Gemini API docs, 2026. How windows grew and what a million tokens holds, in plain terms.
- Effective context engineering for AI agents, Anthropic, 2025. The best short take on why long context degrades and what to do instead of filling the window.
- Transformers, the tech behind LLMs, 3Blue1Brown, 2024. A visual walk through GPT-3, if you want to see where its 2,048-token context sits in the model.