Context window planner: tokens and cost of an agent loop

Set tools, system prompt, turns and tool results. See tokens per turn, the turn the window fills, and cost with and without prompt caching.

How it works

  1. Pick a model and type the size of your tools and system prompt
  2. Type turns, tool calls per turn and the average tool result
  3. Read tokens per turn, the fill turn and the cost with and without caching

How the simulation works

The context window of an agent fills when the tools, the system prompt and every earlier message, reply and tool result add up to more than the model allows, and this page finds that turn by adding them up one request at a time. Each turn is one call to the model. Its input is the tool definitions, the system prompt, the history so far and the new user text. After the reply, the assistant text and the tool results (tool calls per turn times the average result) join the history for the next call. Worked example with the numbers on the page when it opens: 6,000 tool tokens plus 3,000 system tokens is 9,000, plus 150 user tokens makes a first request of 9,150 tokens. Every turn adds 400 + 2 x 1,500 + 150 = 3,550 tokens, so turn 40 sends 147,600 tokens, and 79% of that is tool results. A turn that would not fit in the window together with its reply stops the run, and the page names that turn.

Prompt caching in the model

Anthropic and OpenAI both cache a prefix of the request, so the order is tools, then system, then messages, and a change early in the prefix invalidates what follows. With Tools and system only, one breakpoint sits after the fixed prompt: that part is written once and read on later turns, and the growing conversation is billed at the normal input price. With Whole conversation, the breakpoint moves to the end of every request, so each turn reads the previous request from the cache and writes only the newest tokens. Writes cost more than normal input (1.25 times on the Claude and GPT presets) and reads cost a fraction (0.025 to 0.1 times across the presets). In the default run the three strategies cost 6.43 with no caching, 5.77 with tools and system only, and 0.83 with the whole conversation, in USD. A prefix shorter than the vendor's minimum, 512 tokens for the Claude presets and 1,024 for the GPT presets, is not cached at all.

Compaction and the suggestions

Type a percentage in Compact when context passes and the page replaces the history with a summary of the size you give whenever the next request would pass that share of the window. The compaction call is priced as reading the context (cached part at the read price) plus writing the summary at the output price, and the cached conversation is dropped, so the next request writes it again. The suggestions list is computed from your numbers, not written in advance: it reports the share of tool results in the final request, the share of the fixed prompt, a cheaper caching strategy when one saves at least 10%, the fill turn, the number of compactions and their cost, and the output share of the bill.

What this does not model

All figures are estimates from the numbers you type. Prices for the presets are the vendors' published list prices in USD per million tokens, fetched on 15 October 2026 from platform.claude.com/docs/en/about-claude/pricing and developers.openai.com/api/docs/pricing; check those pages because prices change. The page assumes each request arrives inside the cache lifetime, which is 5 minutes for the Claude 5-minute write and 30 minutes for GPT-5.6 and later, so slow agents that wait longer pay for more writes. OpenAI bills long-context rates when one request has more than 272,000 input tokens (input and cached input twice the short rate, output 1.5 times); the page applies that tier request by request for the GPT presets. Each preset also rejects a reply size above its 128,000-token maximum output. It ignores batch discounts, extended thinking tokens you are not told about, images, parallel agents, the 20-block cache lookback and hidden provider tokens. Real token counts differ by model family, so measure a real transcript with the Token counter and feed those numbers in.

Frequently asked questions

How do I know when an agent will fill its context window?

Add up tools, system prompt and every earlier message, reply and tool result. In the opening example each turn adds 3,550 tokens to a 9,000-token fixed prompt, so a 200,000-token window fills at turn 55. Pick Custom prices, set the window, and the page names the exact turn.

How much does prompt caching save in an agent loop?

It depends on how much of each request repeats. In the default 40-turn run on Claude Sonnet 5.5, caching only tools and system saves about 10% (5.77 against 6.43 USD), and caching the whole conversation saves about 87% (0.83 USD). The page shows all three side by side for your numbers.

What is the difference between caching tools and system only and the whole conversation?

Tools and system only puts one breakpoint after the fixed prompt, so history is billed at the normal input price every turn. Whole conversation moves the breakpoint to the end of each request, so earlier turns are read from the cache and only the newest tokens are written, at the higher write price.

What compaction threshold should I use?

A common starting point is 80% of the window, which leaves room for the reply and the next tool results. Type it in and compare: the page shows how many compactions run, the turn of the first one and what they cost. Each compaction drops the cached conversation, so the next request writes it again.

Why is my real bill different from this estimate?

The page assumes the token counts you typed, requests inside the cache lifetime, and list prices without discounts. Real runs vary in result size, thinking tokens and timing, and the cache can expire between slow turns. Compare against the usage fields of a real run, such as cache_read_input_tokens.

Are my numbers uploaded or saved?

No. The numbers are processed in your browser and not uploaded. Nothing you type is saved on this device either.