Context window exceeded on a request you thought fit
Why "it should have fit" is the wrong test
A request gets built against a model's large context window, the input alone is measured and comes in comfortably under that ceiling, and the request still fails as exceeding the window. The mistake is treating the context window as a budget for input alone, when it actually has to cover input, the space reserved for the model's response, and — on a model where thinking runs by default — the tokens thinking itself consumes, all inside the same ceiling.
Where the missing tokens actually go
Two things eat into the same window that input-only measurement misses entirely. First, whatever
you've set as the maximum output length is reserved capacity, not a soft target — a large
max_tokens value claims that much of the window before generation even starts, regardless of how
much of it the response actually uses. Second, on a model where thinking is on by default or
always on, thinking consumes tokens from that same shared budget before the visible answer is
produced, and a request configured for a high effort level reserves more of it than a low one
does. Neither of these shows up if you only counted the literal input text.
Where this bites hardest
The riskiest combination is a request that's already using most of the window for input — a large
codebase, a long document set — paired with a high effort level and a generous max_tokens
ceiling "just in case." Each piece looks individually reasonable; added together, they can exceed
the window even though no single number looks obviously wrong on its own.
The fix
Budget for input, reserved output, and thinking overhead together, not input alone, and re-check
that combined total whenever you raise effort level or max_tokens on an already-large request —
either change alone can push a previously fine request over the edge. The
context-window planner accounts for all three pieces together
rather than input in isolation, which is exactly the gap that produces this error in hand-rolled
budgeting.
Verified 2026-08-08 against ClaudeHow facts module (src/data/facts/) — see /about/#accuracy.