esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

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.

11 min readBeginnerVery common · estimateFacts checked 26 November 2026

Say it out loud

Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.

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.

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.

Key words

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.

What fills one request

Sent each turn

System prompt

your rules and role

Chat history

every earlier message

Tool results

what search or a database returned

Context window

all of it must fit

Reply

and its thinking, counted too

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

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

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.

Making a long claim fit

Policy, 300 pages

too big beside the claim

Three moves

Pick matching clauses

search, then send only the hits

Compact old turns

a summary replaces full history

Count before sending

token count, checked in code

Fits, with room to reply

reply space kept free

  1. 1The policy and claim file go through three moves first.
  2. 2Three moves shrink what is sent, and the room for the reply is kept.
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.

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."

    BetterIt 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."

    BetterA 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."

    BetterA 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?

Quick check

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

Can you answer these from memory?

Flash cards · tap a card to flip it

1 / 6

What will they ask next?

  1. Q009What happens when input is longer than the window?12 min
  2. Q040How do you estimate the token count of a text?10 min
  3. Q083What is "context rot"?10 min
  4. Q084What is "lost in the middle"?11 min
  5. Q096What is compaction (summarising history)?11 min
  6. Q138RAG vs long context: which to use?12 min

Learn it in depth

Last updated on 26 November 2026

Building an assistant that reads long documents or claim files?

I design and build AI agents and the system behind them, including how much context each request gets and how it is trimmed. Book a short call and tell me what your documents look like.