Context planning
How many chat turns fit? Plan conversation history before it overflows
Calculate a full-history conversation limit, test larger replies and tool results, and set a measured review trigger instead of guessing from turn count.
By Context Budget Planner editorial · Published
Original worked examples are hypothetical, not measured product results. Sources checked 2026-11-09.
A turn count is useful only with a size assumption
Ten short exchanges and ten exchanges containing pasted logs are different workloads. A chat-length estimate needs both a count of completed exchanges and the token growth contributed by each exchange. It also needs the fixed material that is present before the first message.
Context Budget Planner models a deliberately simple case: every prior user and assistant message is sent again, each exchange has the same assumed size, and no history is summarized or removed. It is a planning model, not a simulation of a hosted chat product. Providers and applications can manage conversation state differently.
Work a full-history example from the fixed terms outward
Use a synthetic 32,000-token capacity. Fixed instructions, starting context and fixed tools take 4,000 tokens. Each completed exchange contributes a 250-token user message plus a 750-token assistant answer, or 1,000 tokens. Reserve another 250 for the next user message, 2,000 for the next answer and 1,750 as a safety margin.
The fixed amount in the next request is 4,000 + 250 + 2,000 + 1,750 = 8,000 tokens. That leaves 24,000 for completed exchanges. Divide by 1,000 tokens per exchange: at most 24 completed exchanges fit under these assumptions.
At 24 completed exchanges, the next request reaches exactly 32,000 planned tokens. At 25 it reaches 33,000, an overflow of 1,000. “24 completed exchanges fit” does not mean the system can append unlimited further messages after the next answer. Recompute the ledger as the conversation advances.
A small change in reply length changes the runway
Now suppose assistant replies average 1,250 tokens instead of 750. Each completed exchange grows by 1,500 tokens. The same 24,000-token history allowance holds only 16 completed exchanges. Eight exchanges of apparent runway disappear without changing the model’s context window.
If the next answer needs a 4,000-token reserve instead of 2,000, the fixed amount rises to 10,000. With the original 1,000-token exchange size, only 22 completed exchanges fit. Output planning affects conversation length before the answer has been generated.
Averages are convenient for a scenario, but they conceal bursts. Keep a typical case and a deliberately larger case. A pasted error log can consume several ordinary exchanges at once. When actual counts are available, prefer them to a smooth estimate based on the conversation’s turn number.
Tool results are history too when they remain in the request
The simple formula assumes tools and other overhead do not grow. If every exchange adds a retained 600-token tool result, the original exchange growth becomes 1,600 tokens rather than 1,000. The 24,000-token history allowance then holds 15 completed exchanges.
This is an alternative scenario, not an automatic adjustment performed by the planner. Include retained tool text in your assumed growth or use the allocation planner with a measured history total. Do not count the same result in both fixed tools and growing history. Tool definitions can be fixed while tool outputs accumulate.
Choose a review trigger before the arithmetic limit
In the original example, 18 completed exchanges leave 6,000 tokens of planned headroom. A team might use that point to inspect what can be removed or summarized, allowing room for an unusually large request. Eighteen is an authored example, not a recommended universal threshold. The right trigger depends on measured message sizes and the application’s recovery behavior.
Compaction creates a new baseline. Suppose the retained history is replaced by a 3,000-token summary. Recount the actual new request, preserve unresolved requirements and essential source references, and test continuation quality. Do not simply reset the exchange counter to zero while leaving the same full history attached.
Privacy and permissions still apply to whatever summary is retained. Shorter text can preserve sensitive details. A context-management change should not quietly become a new persistent-memory feature.
Check the estimate against actual usage
Use the provider’s current counting guidance and usage reports to understand differences between visible text and billed or capacity-counted tokens. Reasoning, message serialization and multimodal inputs may have special rules. Claude’s documentation describes its own accounting; do not transfer those rules to every model.
- Record fixed base, per-exchange growth, next-message reserve, answer reserve and margin.
- Check maximum output independently from total capacity.
- Run typical and larger-message scenarios, including retained tool output.
- Recount after truncation or compaction rather than assuming the old formula still applies.
- Test whether essential facts survive any history reduction.
Technical references: Claude context-window documentation · OpenAI tiktoken
Sources and scope
Provider rules and supported features can change. These sources support the technical background; the worked examples and decision checklists are authored for this article.
- Claude context-window documentation
Current provider-specific discussion of context and reasoning accounting.
- OpenAI tiktoken
Use an appropriate encoding rather than assuming one universal character-to-token ratio.