# What Is a Context Window?

> How much text an AI model can see at once, what fills it, why a bigger window is not the fix, and how to work inside it, for your AI interview.

**In short:** A context window is the amount of text a language model can look at when it writes a reply, counting the reply itself. A request that is too long is refused, and on newer models a reply that runs into the limit is cut off, so long inputs must be trimmed, summarised or fetched in parts.

AI and LLM interview question Q008, LLM fundamentals. Beginner, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-a-context-window

## Say it in 30 seconds

A context window is how much text an AI model can look at in one go. That includes my instructions, the chat so far, any documents or tool results, and the reply it is writing. Too much text and the request is refused, so I keep it under the limit. So when I build an assistant, I count the tokens, send only the text that matters, and keep room for the answer. A bigger window helps, but it does not fix bad context on its own.

## Say it in 2 minutes

Think of a claims handler's desk. Only the files on the desk can be looked at while the handler answers a call. The archive room holds far more, but nothing in it can be read until someone brings a file to the desk. A language model's context window is that desk: the text it can refer to while it writes, measured in tokens, the small pieces of text a model reads and writes.

Everything in the request sits on that desk. The system prompt, the chat history, the tool results and the tool definitions all take space, and so does the reply, including any thinking the model does before it answers. The training data is not on the desk. The model only uses what is in the window for that request.

A bigger window is not a free fix. Anthropic says that as the number of tokens grows, recall gets worse, a problem it calls context rot. So for a claims assistant reading a long policy and forty emails, I send only the clauses that match the claim, count the tokens in code before each call, and summarise older turns once the chat gets long.

When someone asks how I would design it, I start with the budget. I decide how much room the reply needs, give each part a share, and test with real long claim files. A window only sets a limit. You still have to test that the answers are good.

## What is a context window, in plain words?

An AI model can only look at so much text at one time. The most it can look at in one request is its context window. That covers your instructions, the chat so far, any documents or tool results you send, and the reply the model is writing.

Picture a claims handler's desk. Only the files on the desk can be looked at while the handler answers a call. The archive room holds far more, but a file there is no use until someone brings it to the desk. The context window is that desk. A claims assistant works the same way: the policy wording and the claim emails must fit on the desk, with room left to answer.

The window is not the training data. Anthropic's docs describe it as a working memory for the model, separate from what the model learned in training.

- **Context window:** The most text a model can look at in one request, reply included.
- **Token:** A small piece of text the model reads and writes: a word, part of a word, or a character.
- **System prompt:** Your instructions at the top of a request, often hidden from the user.
- **Tool result:** What a tool, such as a database search, sends back to the model.

## How is the window measured, and what fills it?

The window is measured in tokens, not words. Google's machine learning glossary defines the context window with that unit:

> "The number of tokens a model can process in a given prompt." (Google's machine learning glossary)

A token can be a whole word, part of one, or a single character. Anthropic's glossary says earlier Claude models count about 3.5 English characters to a token. Claude 4.7 and later use a newer tokenizer that makes about 30 percent more tokens for the same text, so on an earlier model a 3,500-character email is about 1,000 tokens.

Everything in the request counts. The system prompt, the chat history, documents, tool results and the tool definitions all take space. So does the reply the model writes, including any thinking it does before answering.

*Diagram, What fills one request: Everything you send, plus the reply, has to fit in the window. A request that is too big is refused.*
1. Your system prompt is sent with every request.
2. Earlier messages go in again, since each request carries the history.
3. Tool results, such as a database lookup, take their share too.
4. The reply is written inside the same window, so it needs room.

## Why isn't a bigger window the fix?

A bigger window helps with longer prompts, but more context isn't automatically better. Anthropic's docs say that accuracy and recall fall as the window fills, which they call context rot:

> "As token count grows, accuracy and recall degrade, a phenomenon known as context rot." (Anthropic, Claude docs)
>
> "Context, therefore, must be treated as a finite resource with diminishing marginal returns." (Anthropic, engineering)

Researchers saw the same pattern inside long inputs. The 2023 paper "Lost in the Middle" found that answers were often best when the key text sat at the start or end of a long input, and that they degraded in the middle, even for models built for long contexts.

Anthropic's engineering team says it is likely that, for the foreseeable future, windows of any size will face context pollution and relevance problems, at least where the strongest agent performance is wanted. So a bigger window is not a complete plan.

> **Tip:** Asked whether a bigger window fixes it? Say no, and say what you would do: send less, fetch the right part, or summarise older turns.

## How do you fit a real claim file into the window?

Say an insurer's claims assistant must answer questions about one claim. The file holds 40 emails and notes, and the policy wording runs to 600,000 characters. Using a rough 3.5 characters a token, the policy alone is about 171,000 tokens. Pretend the window is 200,000 tokens, as on some Claude models. The policy and the claim file together are already over that, before the system prompt and the reply are added.

The script below works the budget with those made-up numbers. It counts two plans in standard library Python: send everything, then send only the clauses a claim cites.

```python
# A claims assistant's token budget. Made-up numbers for a mid-size insurer.
WINDOW = 200_000  # tokens the model can look at in one request
RESERVE = 8_000  # kept free for the reply, thinking included
CHARS_PER_TOKEN = 3.5

def tokens_for(chars):
    return round(chars / CHARS_PER_TOKEN)

def check(name, parts):
    used = sum(n for _, n in parts) + RESERVE
    for label, n in parts:
        print(f"{label:<38}{n:>9,}")
    left = WINDOW - used
    if left >= 0:
        print(f"{name}: {used:,} of {WINDOW:,}, fits")
    else:
        print(f"{name}: {used:,} of {WINDOW:,}, over by {-left:,}")

check("Send everything", [
    ("System prompt and tool list", 6_000),
    ("Full policy wording (600,000 chars)", tokens_for(600_000)),
    ("Claim file: 40 emails and notes", 60_000),
])
check("Send matching clauses", [
    ("System prompt and tool list", 6_000),
    ("Policy clauses the claim cites", tokens_for(42_000)),
    ("Claim file: 40 emails and notes", 60_000),
])
```

Output:

```text
System prompt and tool list               6,000
Full policy wording (600,000 chars)     171,429
Claim file: 40 emails and notes          60,000
Send everything: 245,429 of 200,000, over by 45,429
System prompt and tool list               6,000
Policy clauses the claim cites           12,000
Claim file: 40 emails and notes          60,000
Send matching clauses: 86,000 of 200,000, fits
```

The first plan is 45,429 tokens over the limit, so it has to be cut before it can be sent. The second fits with room to reply, because the assistant fetches only the clauses the claim cites.

*Diagram, Making a long claim fit: The 300-page policy and the 40-email claim file cannot both go in whole. The assistant picks matching clauses, compacts old turns and counts tokens before each call, then sends a request that fits with room to reply.*
1. The policy and claim file go through three moves first.
2. Three moves shrink what is sent, and the room for the reply is kept.

Two tools help here. Anthropic's docs suggest a token counting API to check a request before sending it. For long chats and agent loops, Anthropic's docs name server-side compaction as the main way to manage context, in beta on Claude 4.6 and later.

### How would you design the assistant so it never overflows?

Start with the budget, not the prompt. Fix the room for the reply, give each part a share (rules, retrieved clauses, the claim file, the chat history), then count in code before each call. When a part grows past its share, summarise it or fetch less.

- **Without a budget: It breaks on big claims.** Every file is pasted in. A large claim fills the window, the reply has no room, and the request fails.
- **With a budget: Checked before each send.** Each part has a share. Long history is summarised, the reply keeps its room, and the model reads the whole request.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: the most text a model can look at in one request, reply included.
- [ ] What counts: the system prompt, the chat history, tool results, documents and the reply.
- [ ] Tokens, not words, are the unit the window is measured in.
- [ ] A bigger window is not automatically better: context rot and the lost-in-the-middle effect.
- [ ] Fixes: send less, fetch the right part, summarise old turns, count tokens first.
- [ ] The window is working memory for one request, not the training data.

**Common traps**

- Trap: "The model remembers everything we've ever said to it." Better: It only sees what the current request carries. Earlier turns must be sent again, or summarised, to count.
- Trap: "A million-token window means we can paste everything." Better: A size limit says nothing about answer quality. Context rot means recall drops as the window fills, so send only what matters.
- Trap: "Tokens are just words." Better: A token is a word piece, a character or a byte. For exact numbers, use token counting with the model you plan to use.

## Can you spot the problem?

**Spot the problem:** Your claims assistant must answer from a 300-page policy and a 40-email claim file. Which plan will overflow the window?

A. Load a short policy index first, then fetch only the clauses the claim cites.
B. Keep the last 10 turns in full and replace older turns with a summary.
C. Paste the full 300-page policy and all 40 emails into every request, then ask for the clause that applies.
D. Count tokens in code before each send, and stop with a clear message if the request is too big.

**Answer:** C. Pasting everything overflows the window, so the request is refused. Fetch only the clauses a claim cites, and keep room for the reply.

**Quick check:** A claims chat gets worse the longer it runs. What is the most likely cause?

A. The model has forgotten its training
B. Context rot: as tokens pile up, recall gets worse
C. The temperature is set too high
D. The billing plan has run out of credit

**Answer:** B. Anthropic calls this context rot: as the token count grows, recall gets worse. Temperature only changes how random the model's picks are.

## Can you answer these from memory?

**Flash cards**

- **What is a context window?** The most text a model can look at in one request, reply included.
- **What counts toward it?** System prompt, chat history, tool results, documents, tool definitions and the reply.
- **What unit is it measured in?** Tokens: small pieces of text, often part of a word.
- **Is it the training data?** No. It is working memory for one request.
- **Is a bigger window always better?** No. Context rot: recall drops as tokens pile up.
- **What do you do when it is full?** Send less, fetch the right part, or summarise older turns.

## Likely follow-up questions

- Q009 What happens when input is longer than the window? https://designervenkat.online/interview/ai/what-happens-when-input-is-longer-than-the-window
- Q040 How do you estimate the token count of a text? https://designervenkat.online/interview/ai/how-do-you-estimate-the-token-count-of-a-text
- Q083 What is "context rot"? https://designervenkat.online/interview/ai/what-is-context-rot
- Q084 What is "lost in the middle"? https://designervenkat.online/interview/ai/what-is-lost-in-the-middle
- Q096 What is compaction (summarising history)? https://designervenkat.online/interview/ai/what-is-compaction-summarising-history
- Q138 RAG vs long context: which to use? https://designervenkat.online/interview/ai/rag-vs-long-context

## Learn it in depth

- [Context Window](https://designervenkat.online/learn/ai-engineering/context-window)
- [Context Compaction](https://designervenkat.online/learn/ai-engineering/context-compaction)
- [Long-Context Processing](https://designervenkat.online/learn/ai-engineering/long-context-processing)
