What does a model's 'context window' mean and what does it include?
The context window is the maximum total tokens the model can process in one call, covering system prompt, user message, history, retrieved context, and the generated reply as one shared budget.
Imagine a whiteboard with a fixed number of inches of writing space. Everything for one conversation has to fit on that whiteboard at once. The system instructions go at the top, then the conversation so far, then any reference notes you pasted in, and at the very end the model writes its reply. If the whiteboard is six feet wide, all of that combined has to fit in six feet. If your system prompt and history already use five feet eleven inches, the model only has one inch left to answer. Buying a wider whiteboard helps, but you still cannot fill the entire whiteboard with input and expect room for the model to write. The model's reply shares the same whiteboard as everything else.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
6 min: define context window as total token budget, enumerate what counts against it, explain input plus output share the budget, describe truncation and lost-in-the-middle, name 2026 frontier window sizes.
Real products, models, and research that use this idea.
- Claude Opus 4.7, Gemini 3.1, and GPT-5.5 all ship around 1M-token API windows; older open-weight Llama variants offer 8K to 128K.
- Anthropic's prompt-caching docs explicitly note that cached system prompts still count against the context window; caching reduces cost, not budget.
- Lost-in-the-middle benchmarks (Liu et al. 2023, follow-ups in 2024-2025) show frontier models recall facts in the middle of a long context less reliably than at the start or end.
- Cursor and Cody both run conversation-history compaction once a chat session crosses a watermark in the window, rather than relying on SDK truncation.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat is the lost-in-the-middle effect, and how does it interact with the advertised context-window size?
QHow does prompt caching change the cost economics of a long context window?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating the context window as input-only and forgetting that the model's reply consumes the same budget, then getting truncated outputs when the system prompt and history already filled most of the window.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.