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.

When to use it, and when not

Use it while designing the budget of an agent or chat product: how big the system prompt and tool list may grow, how much history to keep before compacting, how large a retrieval budget to allow, and which window the product needs. It turns those choices into one picture before any code exists, and the bands show at a glance which tenant to negotiate with.

Once traffic exists, measure instead: log the input token count every response reports and look at the distribution across requests, not one snapshot. And when the question is quality rather than fit, whether the model still finds the instruction or fact it needs deep in a long context, no budget picture answers it; run an evaluation at your real lengths.

Trade-offs and limits

The tool assumesIn a running agentConsequence
One snapshotHistory grows every turnThe default request in 32K turns Tight 13 turns later and overflows on the 17th, at 1,200 tokens a turn
A summary costs nothingA summary is itself tokensRecover the overage plus the summary’s length
Bands change only when you edit themOne tool call can return thousands of tokens mid-turnA 20,000-token file read takes the 32K default to 33,200, over the 32,768 edge
The reserve is the answerModels that reason before answering spend those tokens from the same output allowanceSize the reserve for thinking plus answer

The status thresholds are fixed rules, not physics. 85% is a sensible early warning for a chat turn, but an agent whose tool results vary by tens of thousands of tokens needs its alarm lower, set by its largest likely tool result rather than by a percentage.

Common mistakes

  • Compacting to exactly the edge. The plan recovers the overage and no more. On the defaults history drops to 992 tokens and the request lands on 8,192 of 8,192: it fits, but it is still Tight with nothing free, so the next turn overflows again.
  • Summaries that drop identifiers. “Read the config and fixed the bug” loses the file path, the line and the error text, so the agent reads the file again and spends the tokens a second time. Keep IDs, paths, numbers and decisions verbatim; compress the prose around them.
  • Sizing the reserve to the average answer. A reply that hits the limit is cut off mid-sentence, or mid-JSON, which breaks any parser downstream. Size for the longest answer the task legitimately needs.
  • Filling the window because it is there. Raising retrieval to fill 128K costs $0.384 of input on every call at $3 per million tokens, and buries the one relevant chunk among many irrelevant ones.
  • Letting raw tool output in. A whole log file or unfiltered search result lands in history and is re-sent on every later turn. Cap and trim tool results where they are produced.

Check yourself

The default request runs in the 32K window, and each turn adds 1,200 tokens of history. When does it turn Tight, and when does it overflow?

Tight starts above 0.85 × 32,768 = 27,852.8: (27,852.8 − 13,200) / 1,200 = 12.2, so on the 13th turn. Overflow starts above 32,768: (32,768 − 13,200) / 1,200 = 16.3, so on the 17th. A 32K window buys about 16 more turns of this conversation, not unlimited room.

Back in the 8K window, how much must be removed to reach OK rather than just fit, and from where?

OK needs committed at or below 0.85 × 8,192 = 6,963.2, so remove 13,200 − 6,963.2 = 6,236.8, about 6,237 tokens. That is more than all 6,000 tokens of history, so 237 must also come from retrieved context. The tool’s own plan aims only at the edge and takes 5,008.

In a 200K window, the input is 150,000 tokens with the maximum 16,000 reserve. What is the status, and what does one 10,000-token tool result do?

Committed is 166,000, which is 83% of 200,000: OK. Adding 10,000 makes it 176,000, or 88%: Tight. A turn that is comfortably OK can cross the warning line on a single tool call, which is why large windows still need a trimming policy.

8K window edge: 8,192 before: 13,200 committeduser 200 sys tools RAG 3.0k history 6.0k out 2.0k over by 5,00885% after summarizing 5,008 sys tools RAG 3.0k 992 out 2.0k 100% used, status Tight
The default request drawn to scale: 13,200 committed tokens against an 8,192-token window, with ticks at the window edge and the 85% Tight line. Summarizing 5,008 tokens of history brings it exactly to the edge, which fits but leaves nothing spare.

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.