Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Context Window Visualizer

Set the tokens for your system prompt, tools, chat history, RAG context and output reserve, pick a model window (8K–1M), and watch a stacked bar fill it. The moment it overflows, the tool shows exactly how much compaction would have to trim from history and retrieved context to make the request fit.

Context window
08.2k tokens
⚠ Over budget by 5.0k tokens — this request won't fit.
11.2kInput tokens100% of window
13.2kInput + output reservemust fit in 8.2k
−5.0k Over budget
Overflow Status
To make it fit, compaction would:
  • Summarize 5.0k tokens of chat history

A model’s context window is one fixed budget of tokens, and everything in a request competes for it at once. The system prompt, every tool definition, the whole chat history, the retrieved documents, the user’s message and the space for the answer all have to fit together. This visualizer adds them up, draws each as a band in the window, and proposes what to cut when they do not fit.

What it computes

input     = system + tools + history + retrieved + user
committed = input + output reserve
over      = max(0, committed − window)
free      = max(0, window − committed)
status    = Overflow if over > 0
            Tight    if committed / window > 0.85
            OK       otherwise
  • Window is one of five presets: 8K (8,192 tokens), 32K (32,768), 128K (128,000), 200K (200,000) and 1M (1,000,000).
  • Output reserve is room held back for the reply. It counts against the window even though you do not send it.
  • The input tokens card shows input as a share of the window, capped at 100%.
  • On overflow, the compaction plan takes the overage from chat history first, up to all of it, then from retrieved context, and warns if both together are not enough.

Token counts are shown as thousands with one decimal, such as 11.2k, and whole thousands at 100,000 and above.

A worked example

The defaults describe a modest agent turn in an 8K window:

BandTokens
System prompt800
Tool definitions1,200
Retrieved context3,000
Chat history6,000
User message200
Input total11,200
Output reserve2,000
Committed13,200
  1. Input alone is 11,200 / 8,192 = 137% of the window, so the card shows 100%.
  2. Committed exceeds the window by 13,200 − 8,192 = 5,008 tokens, so the bar turns red and reads Over budget by 5.0k tokens.
  3. The plan takes all 5,008 from chat history, which has 6,000, so it reads Summarize 5.0k tokens of chat history and retrieved context is untouched.
  4. Switch to the 32K preset instead: the same request uses 13,200 / 32,768 = 40%, leaves 19.6k free, and the status is OK.

Note who the tenants are: the user’s actual question is 200 tokens, under 2% of the input, while re-sent history is more than half.

Assumptions and limits

  • You supply the counts. The tool does not tokenize text. Different models split the same text into different numbers of tokens, so measure with the target model’s tokenizer.
  • Compaction is idealized. The plan treats summarized history as removed entirely. A real summary still costs tokens, so recover somewhat more than the overage.
  • Fitting is not the same as using well. Models often attend less reliably to material buried in the middle of a long context, so a prompt that fits can still underperform.
  • One request. History grows every turn; the tool shows a single snapshot, not when you will hit the limit.
  • No price. Bigger windows cost more per call because every input token is billed. Pair this with a cost calculator before choosing a window.

How to use the result

  • Keep committed below 85%. Tight is a warning that one long tool result or retrieved document will tip the turn into overflow.
  • Attack the biggest band first. Summarize history on a schedule rather than at the brink, retrieve fewer and better chunks, and load tool definitions only when the task needs them.
  • Size the reserve to the task. Too small truncates answers; too large wastes window the input could use.
  • Move up a window only after trimming. A larger window raises the cost of every call and hides growth that will return.

How it works

  • Input = system + tools + history + RAG + user; output is reserved on top.
  • All of it shares one window; history and RAG grow the fastest.
  • Status turns Tight above 85% of the window and Overflow above 100%.
  • Compaction trims history first, then retrieved context; prompts and tools stay.

Frequently asked questions

What is a context window?

A context window is the maximum number of tokens a model can handle in a single request. Everything you send, including the system prompt, tool definitions, chat history, retrieved documents and the user’s message, plus the tokens the model writes in reply, must fit inside it. Window sizes are fixed per model, from a few thousand tokens on older models to a million or more on some current ones, and the limit applies to every call separately.

What happens when a prompt exceeds the context window?

Most model APIs reject the request with an error when the input plus the requested output length exceeds the window. Some frameworks avoid the error by silently dropping the oldest messages, which is worse: the model loses earlier instructions or facts without anyone noticing, and answers confidently from what is left. The safe pattern is to measure the budget before each call and compact deliberately, choosing what to summarize or drop.

What fills up the context window in an agent?

Usually not the user’s question. The bulk is the system prompt, the tool or function definitions, the chat history that is re-sent on every turn, and any retrieved documents, all sharing one budget with the output reserve on top. In the tool’s default example the user message is 200 of 11,200 input tokens, under 2%, while chat history alone is 6,000. Showing each contributor as its own band makes the crowding visible.

How many tokens should I reserve for the output?

Reserve at least the longest answer you expect, because the window is shared between what you send and what comes back. A short chat reply may need a few hundred tokens, a code edit or report a few thousand, and a model that writes out its reasoning can need far more. Set the API’s maximum output length to the same number so the reserve is enforced. This tool only calls a prompt a fit when the reserve fits too.

What does compaction trim first?

Typically the bulkiest content that can be shortened without losing the task: old chat history, folded into a running summary, and retrieved context, trimmed or re-retrieved more narrowly. The system prompt, tool schemas and current message usually stay intact because the model needs them to act. This tool’s plan takes the overflow from chat history first and then from retrieved context, and warns when even removing both completely would not be enough.