Skip to content
mentoor

Topic 1 of 5 · 4 min read

Everything that fills the context window

Goal: Add up the parts of a real conversation's context and tell whether a new file fits with room left for the answer.

The context window is one shared budget of tokens, and everything the model reads plus everything it writes has to fit inside it. A token is a small piece of text, roughly a short word or part of a word. The window is the most tokens a model can handle in a single call.

Check yourself · 1 of 3

Which of these uses up space in the context window?

Choose one answer

Why it matters

People think the window is "the size of my message". It is not. Your message is often the smallest part. When a chat gets slow, forgetful or starts failing with a "too long" error, something else has usually filled the space.

What fills the window

  1. The system prompt. Instructions from the app or developer that you may never see. Coding tools and company assistants can make these long.
  2. The chat history. Every earlier message, yours and the model's. The model remembers nothing between calls, so the app sends the whole conversation again each turn.
  3. Attached files and pasted text. A PDF, a spreadsheet or a code file counts in full.
  4. Tool results. Search results, file reads and command output all land in the window, and they can be huge.
  5. Room for the answer. The reply is counted against the same budget. A window that is full of input leaves no space to write.

Add these up: system prompt + history + files + tool results + the space you want for the reply must be at or under the window size. Providers list each model's window in their docs, for example the OpenAI models page and the Claude context windows page.

Before and after

Before: "The window is 200,000 tokens and my report is 60,000, so there is plenty of room."

After: Make a small table first.

Part Tokens
System prompt 3,000
Chat so far 45,000
Tool results from earlier searches 70,000
New report 60,000
Reply you want 8,000
Total 186,000

It fits, but only just. One more search result and the window overflows. The real question is never "does the file fit alone?" but "does everything fit together?"

If you build apps, you can count before you send:

budget = 200_000
used = system + history + files + tool_results
room_for_reply = budget - used
assert room_for_reply >= 8_000, "trim before sending"

What goes wrong

  • Forgetting the hidden parts. The system prompt and tool output are invisible but counted.
  • Forgetting the reply. A full window means a short or cut-off answer.
  • Assuming a bigger window is free. Fitting is not the same as working well, which later topics cover.

Examples

Budget before you paste

You are 40 turns into a chat and want to add a long contract. Before pasting, list the parts: system prompt, history, earlier attachments, the contract and the reply you want. If the total is close to the window size, start a fresh chat and paste only the contract plus a short summary of what you decided.

The invisible fill-up

A coding assistant reads ten files and runs a test suite. None of that was typed by you, yet the file contents and the test log sit in the window. That is why the same chat can work at turn 5 and fail at turn 30.

Key points

  • The context window is one token budget shared by the system prompt, chat history, files, tool results and the reply.
  • The whole conversation is resent on every turn, so a long chat keeps using more of the window.
  • Tool results and attached files are often the largest parts, and they count in full.
  • Always leave room for the answer: input plus reply must fit together.
  • To check a new file, add up everything already in the window, not just the file.

Common mistakes

  • Comparing the file size alone to the window size.
  • Ignoring tool output, which can be larger than everything you typed.
  • Filling the window with input and expecting a long answer.
  • Thinking a new message starts clean, when the whole history is sent again.

Check yourself · 2 of 3

A chat has used 150,000 of a 200,000-token window. You attach a 60,000-token file and want a long summary. What is the problem?

Choose one answer

Check yourself · 3 of 3

Why can a chat that worked fine at turn 5 start failing at turn 30?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic