An LLM context window is the maximum number of tokens a language model can read and generate inside a single request—its entire working memory for that turn.
Every piece of text the model sees shares that same budget: your system instructions, JSON tool schemas, conversation history, retrieved documents, tool outputs, internal reasoning (“thinking”) tokens, and the model’s final reply. When you cross the limit, the API either returns an error or silently truncates earlier turns so the model forgets instructions you gave it ten minutes ago.
Here is how a context window actually fills up in real applications, why advertised 200K–1M token windows still degrade long before they are full, and five concrete budgeting habits that keep latency, cost, and accuracy under control.
What actually shares your context window
Engineers often estimate context size by counting only the user’s message. In a real agent or RAG app, the user’s message is usually the smallest slice:
┌──────────────────────────────────────────────────────────────────────┐
│ Total Context Window (e.g. 32K / 128K / 200K / 1M tokens) │
├────────────┬──────────────┬─────────────────┬────────────┬───────────┤
│ System │ Tool schemas │ History + tool │ Reasoning │ Visible │
│ prompt │ (JSON defs) │ outputs / RAG │ (thinking) │ output │
└────────────┴──────────────┴─────────────────┴────────────┴───────────┘
◄────────────────── Input tokens ───────────────────► ◄── Output ────►
Remember two fundamentals:
- Models count tokens, not characters or words. In English prose, 1 token is roughly 3.5–4 characters (about 0.75 words), but JSON punctuation, UUIDs, indentation, and non-English scripts burn far more tokens per word (see why LLMs see tokens instead of letters).
- Every turn resends the conversation. LLMs are stateless across HTTP requests. Turn 10 of a chat resends turns 1 through 9 plus every tool output from those turns unless you compact or trim history.
Why 200K–1M token context windows still fail in practice
Headline context limits (200K, 1M, even 10M tokens) are maximum capacity, not peak accuracy. Filling a huge window causes four real problems:
| Failure mode | What happens as context grows | Real-world impact |
|---|---|---|
| Attention dilution (“context rot”) | Important constraints buried in the middle of 100K tokens get ignored in favor of the start and end | The agent quietly violates a rule from AGENTS.md or misses a detail inside a long log |
| KV-cache RAM explosion | Every token stores Key/Value vectors across every transformer layer | On an 8B local model, 32K tokens takes ~4.2 GB of KV cache—almost as big as the quantized model weights themselves (KV cache explained) |
| Prefill latency spikes | Processing all input tokens before printing the first character scales heavily with prompt length | Users wait several seconds for time-to-first-token on every uncached turn |
| Runaway token cost | Unbounded tool outputs stay in history and get re-billed on every subsequent turn | One un-truncated 85 KB file read turns a $0.01 agent run into a $0.30 loop |
In our own MCP dogfooding (bugs from day one), a naive full-document edit tool forced the agent to read and regenerate an 85,000-character post just to fix one typo. Switching to a targeted edit_entry patch tool eliminated both the token burn and accidental mid-document edits.
Five practical rules for budgeting a context window
1. Cap tool output bytes in the harness
Never let a database query, file read, or HTTP fetch dump unbounded text into the message array. Enforce a hard ceiling (for example 4,000–8,000 bytes) and return truncated: true so the model asks for a narrower query or line range (how to build an AI agent without a framework).
2. Keep the static prefix identical at the top (for prompt caching)
Provider and local prompt caching reuse the computed KV cache only from token 0 up to the first changed byte. Put static system instructions and deterministically sorted tool schemas at the top, and place dynamic timestamps, user IDs, and new messages at the end.
3. Keep tool catalogs small and instruction files short
Every extra tool schema is billed on every turn even when unused. Expose 5–10 focused tools instead of 60 overlapping ones, and keep CLAUDE.md / AGENTS.md under ~60 lines (CLAUDE.md and AGENTS.md guide).
4. Use retrieval (RAG/search) instead of pasting entire corpora
Even when a 1M-token window can technically fit 400 documentation pages, running fast full-text or hybrid search to inject only the 3–5 relevant sections produces sharper answers at a fraction of the latency and cost (MCP vs API vs RAG).
5. Compact old tool outputs after they are used
In multi-step agent loops, raw tool payloads from 10 turns ago rarely need to stay verbatim. Once a step completes, summarize or replace bulky raw outputs with compact references (file path, digest, line range) while keeping the structured execution ledger intact outside the prompt.
Frequently asked questions
How many words fit in a 128K or 200K context window? Roughly 95,000 words in 128K tokens or 150,000 words in 200K tokens of plain English prose—less for source code, JSON, and logs, where symbols and whitespace increase the token-to-word ratio. Remember that system prompts, tool schemas, reasoning tokens, and the reply all count toward that same total.
Does a larger context window make an LLM smarter? No. A larger context window increases capacity, not reasoning quality. In practice, models stay sharpest when you feed them the smallest clean set of relevant facts rather than dumping an entire repository or knowledge base into the prompt.
What happens when you exceed an LLM’s context window?
Most cloud APIs reject the request with a 400 context-length error. Local runners like Ollama may silently drop older tokens from the beginning of the conversation once num_ctx is exceeded—which can silently erase your system prompt unless you monitor token counts explicitly.