Context window
The maximum number of tokens a model can consider at once - its entire working memory, including your prompt, the history, and its answer.
In plain terms
Picture a whiteboard of fixed size. Everything the model 'knows' about your conversation must fit on that whiteboard; the model has no memory besides it. When the board fills, something must be erased - that's why long chats 'forget' the beginning.
Why it matters
Attention (the mechanism inside transformers) compares every token with every other token - costs grow steeply with length, so a hard limit exists. The context window is the boundary you engineer around; RAG, summarization and memory systems all exist because of it.
How it works
Modern windows: ~128k tokens (GPT-4o), 200k (Claude), 1M+ (Gemini). Sounds huge, but a 300-page book is ~150k tokens and long agent sessions burn context fast. Also: models attend unevenly - information buried in the middle of a huge context is recalled worse ('lost in the middle'), and every token in context is paid for on every single call.
When you use it
Every design decision about 'how much do I show the model': conversation history, retrieved documents, tool results, code files.
Common mistakes
- Stuffing everything into context because it fits - cost and accuracy both degrade; relevance beats volume.
- Letting chat history grow unbounded until requests crawl and bills explode.
- Assuming the model weighs all context equally - put critical instructions at the start and end.
Best practices
- Send the least sufficient context: retrieve relevant pieces (-> RAG) instead of dumping raw files.
- Summarize or trim old conversation turns past a threshold.
- Track context size per request in logs; it's your main cost lever.
Try it yourself
Paste a long article into a chatbot and ask about a detail from the middle paragraph. Then ask again with only that paragraph. Compare precision - you've just discovered why RAG exists.
Resources
- Anthropic - Context windows explained Clear vendor docs on how context is counted and managed.