Context collapse risk detector
Long conversations fail quietly: once the running history plus your next reply exceed the model’s window, the oldest turns get truncated and the model starts forgetting. This detector paste-and-counts a conversation turn by turn, shows the running token total, and flags the exact turn where you cross your usable context limit — so you can summarize or trim before quality drops.
What context collapse looks like in practice
Context collapse is usually invisible until it causes a problem. The model does not announce “I have dropped your earlier messages.” Instead:
- The model “forgets” a constraint you specified in turn 2 by turn 25 — and starts violating it.
- A multi-step task that was going well suddenly produces a response that ignores earlier results.
- The model asks you to repeat something you already told it — a sign the relevant turn has been truncated.
- In production chatbots, long-running sessions produce nonsensical or off-topic responses as the conversation history gets silently cropped.
The collapse happens at the provider level: once the prompt exceeds the context window, the API typically truncates from the beginning, dropping the oldest turns silently. Some clients warn you; most do not.
How the detection works
You paste the conversation with one turn per line (or blank-line separated). Each turn’s characters are converted to an estimated token count (about four characters per token), and the tool keeps a running total. From your chosen model context window it subtracts the tokens you reserve for the response to get the usable budget. The first turn whose running total exceeds that budget is marked as the collapse point, and the tool reports how many tokens you must reclaim to fit.
usable_budget = context_window − reserved_output_tokens
running_total = sum of token estimates from turn 1 through turn N
collapse_point = first turn N where running_total > usable_budget
tokens_to_trim = running_total − usable_budget
Recovery strategies once you identify the collapse point
Summarize old turns. Take the conversation from turn 1 to the collapse point and replace it with a compact summary: “User is building a Python CLI tool. We established the architecture and wrote the file parser module. Key decisions: single-pass architecture, no async.” This can reclaim 80–90% of the tokens while preserving the information the model needs.
Drop irrelevant turns entirely. Not every past turn is load-bearing. Early pleasantries, solved sub-problems, and exploratory dead ends can often be dropped without loss. The detector shows you the token cost of each turn, making it easy to identify large low-value turns.
Move reference material to retrieval. Long documents, code files, or data that you paste into the conversation at turn 3 and keep re-sending are the most common cause of premature collapse. Move these to a RAG pipeline where only the relevant section is retrieved per turn.
Switch to a larger context model. If the conversation is genuinely long and dense with load-bearing turns, upgrading to a model with a larger window is sometimes the right answer rather than fighting the limit.
Tips
- Reserve realistic output room — if replies are long, reserve more; forgetting this is a common cause of mid-conversation truncation.
- Token estimates here use ~4 characters per token, which is accurate for English prose but less so for code or non-Latin scripts. For content near the limit, verify with your model’s tokenizer.
- Run this check before long production sessions, not after you’ve already started hitting degraded output.