Domain 5 · Context Management & Reliability

The context window

Everything Claude "knows" in a single request — the system prompt, tools, the whole conversation, retrieved documents, and the answer it's about to write — has to fit in one finite budget of tokens: the context window. Fill the window below and watch what gets squeezed, why quality drops near the edge, and where the answer goes when there's no room left.

tokenstoken budget system + tools + historyoutput reservation context rot
Explain like I'm 10
Imagine Claude has a desk of a fixed size. Everything it needs to do the job has to fit on the desk at once: the instructions, the books it's reading, the whole chat so far — and empty space to write the answer. If you pile too many books on, there's no room to write, and things start sliding off the edges. A good architect keeps the desk tidy: only the books you need, summaries instead of whole chapters.

Pack the window

A token is roughly ¾ of a word. Slide each part of the request and watch the budget. Two things to notice: the output needs reserved space (if input eats it all, the answer gets truncated), and as you approach the limit, models get slower and more error-prone — recall in the "muddy middle" of a stuffed window degrades (sometimes called context rot).

What lives in the window

SegmentNotes
System promptRole + standing instructions. Fixed cost every turn.
Tool definitionsEvery tool's name/description/schema is tokens, every turn. Too many tools = bloat + worse selection.
Conversation historyGrows every turn in an agent loop — the main thing that fills long runs.
Retrieved context (RAG)Documents you inject. Retrieve relevant chunks, not everything.
Output reservationmax_tokens for the reply. Must fit alongside the input.
Exam trap: "just use the biggest context window" is not the architect's answer. Bigger windows cost more, run slower, and still suffer recall loss when stuffed. The discipline is context engineering — put in only what's needed (relevant retrieval, summaries, scoped tools), reserve output space, and compact long histories (next explainer) rather than letting them grow unbounded.
Takeaways: the context window is a fixed token budget shared by system prompt, tools, history, retrieved docs, and the reserved output. Stuffing it costs money, adds latency, and degrades recall (context rot). Engineer context deliberately: relevant-only retrieval, scoped tools, reserved max_tokens, and compaction for long runs.

Curated companion: Anthropic — Effective context engineering for AI agents.