What Is a Context Window in an LLM?

A context window is the maximum number of tokens a language model can process in one request, counting the system prompt, history, tool definitions, retrieved documents, the message, and the model's output. Anything outside it is invisible to the model. Larger windows hold more, but cost more and are not always used well.

What fills the window

Every request to a model is assembled from parts, and all of them consume the same budget.

System prompt and instructions. Rules, persona, formatting requirements, and agent instruction files.

Tool definitions. For agents, the name, description, and parameter schema of every available tool. Agents connected to many MCP servers can spend a large share of the window on tool definitions alone.

Conversation history. Previous user messages and model replies, including tool calls and their results.

Retrieved or attached content. Documents, code files, search results, and chunks from a knowledge base.

The current message. The user's question or task.

The output. The model's response also counts. A request near the limit leaves little room for the answer.

Tokens are pieces of words. The number of tokens for a given text depends on the model's tokenizer and the language: code, non-English text, and unusual formatting often use more tokens than plain English prose of the same length.

The model does not remember

Language models are stateless between requests. What feels like memory in a chat application is the application resending prior messages inside the context window. When history grows beyond the window, something has to be dropped, summarised, or retrieved selectively.

Why context windows are limited

Compute. In standard transformer attention, every token attends to every other token, so the work grows rapidly as input length increases. Efficient attention techniques reduce this, but long inputs still take more computation and memory.

Memory. Serving long contexts requires storing intermediate state for every token during generation, which limits how many long requests a server can handle at once.

Training. A model must be trained, or adapted, to handle long sequences well. A window advertised as large is the maximum the model accepts, not a guarantee of uniform quality across it.

Quality over long inputs. Research on long-context models has found that information placed in the middle of a long input can be used less reliably than information near the beginning or end, a pattern often described as lost in the middle. Irrelevant material also competes with relevant material for the model's attention.

Cost. Providers bill input tokens. A request that sends a large context pays for all of it every time, and latency to the first output token rises with input length.

Advertised versus effective context

A model's maximum context is the most it will accept. The amount it uses well for a given task can be smaller, and varies with the kind of information and where it sits in the prompt. Test long-context behaviour on your own tasks before designing around the maximum.

Managing the context window

Send what the task needs, not everything available. The most effective context is short and relevant.

Retrieve instead of attaching. Search a knowledge base and send the few chunks that answer the question, rather than whole documents.

Trim tool definitions. Load tools progressively or scope them to the task, so an agent does not carry dozens of schemas it will not use.

Summarise long history. Replace old turns with a compact summary, keeping recent turns verbatim.

Put critical information where it is used best. Instructions and key facts near the start or end of the prompt are generally used more reliably than facts buried in the middle.

Cache stable prefixes. Prompt caching lets providers reuse processing for a repeated prefix, such as a long system prompt, reducing cost and latency for requests that share it.

Start fresh when a task changes. Long agent sessions accumulate stale context that affects later behaviour. A clean context with a written summary of state is often more reliable.

RDK approaches this from the retrieval side: agents search indexed private chunks before calling a model, so repeated and reference-heavy questions are answered from retrieved material rather than by sending large context or regenerating the answer.

Measure what fills it

Log token counts per request by component: system prompt, tools, history, retrieved content, and output. Most teams discover one component, often tool definitions or accumulated history, dominates, and that is the first place to cut.

Frequently asked questions

What is a context window in an LLM?
The maximum number of tokens a language model can process in one request, counting the system prompt, tool definitions, conversation history, attached or retrieved content, the user's message, and the model's output together. Information outside the window is not visible to the model for that request.
Why is the context window limited?
Longer inputs require more computation and memory, because attention relates tokens to each other and serving must store state for every token. Models also need training to use long sequences well, and quality and cost both suffer as inputs grow, even within the advertised maximum.
What is the context window in Claude?
It is the token limit for a single request to a Claude model, covering system prompt, tools, history, attached content, and output. Limits differ between models and change over time, so check Anthropic's current model documentation rather than relying on a fixed figure.
What happens when a conversation exceeds the context window?
The application must remove, summarise, or selectively retrieve earlier content, because the model cannot see tokens beyond the limit. Chat tools and agents typically truncate or compact older turns, which is why long sessions can lose track of details mentioned early on.