Originally published at Trida AI.
Turn on tool-result clearing for a long-running agent and two numbers move in opposite directions. The context window gets smaller, which is the number everyone watches. The cache-write column in the usage report gets bigger, which is the number almost nobody watches. A team can ship the first change, celebrate the headroom, and never notice that the run got more expensive while it got leaner.
The two settings are usually owned as separate features. Caching is a cost optimisation someone enabled in the spring. Clearing is a context fix someone enables in the autumn, when runs start bumping into the window limit. They are not separate. They act on the same prefix, and the second one spends what the first one saved.
What a clear actually removes
Claude's context editing works server-side, before the prompt reaches the model. When the conversation passes a trigger you set, the API removes the oldest tool results first and replaces each one with a placeholder saying the content was removed. The tool calls themselves stay visible, so the model can still see what it did; it just can't see what came back. Your client keeps the full, unmodified history. The edit exists only in what the model is shown.
The defaults tell you the intended shape of the thing. Clearing starts at 100,000 input tokens and keeps the three most recent tool use/result pairs. This is a mechanism for long, tool-heavy runs, not a tidy-up for ordinary conversations. Most of the results it removes are file reads, search returns and query output: bulk the model has already used, which is exactly why it can usually be dropped. Usually is doing real work in that sentence, and we'll come back to it.
The context window as one run assembles it. Clearing removes blocks from the history zone; everything after the earliest removed block has to be written to the cache again.
Price the clear before you schedule it
Prompt caching works on prefixes. On the Claude API the cached prefix runs tools, then system, then messages, and a cache read costs 10 percent of the ordinary input price at the standard multiplier, while writing the cache costs 25 percent more than ordinary input for the 5-minute TTL. That asymmetry is the whole game: a stable prefix is read cheaply turn after turn, and the write premium is paid once.
Clearing breaks the prefix at the point where content is removed. Everything before the earliest cleared block still matches. Everything after it is a new prefix, and the next request pays a cache write on it. Clear a few hundred tokens every couple of turns and you pay that write premium again and again to save almost nothing; the documentation's own advice is to clear enough each time to make the invalidation worthwhile. That is what the clear_at_least setting is for. It sets a floor, in the same unit as your trigger: if a clearing pass cannot free at least that much, it does not run at all.
So set the policy the way you'd set any budget. Clear rarely and in large batches: a high trigger, a clear_at_least floor sized to the run's real results, not to a round number. Keep the recent results the current line of work still leans on. And exclude the tools whose results are expensive or impossible to fetch again. A cleared result the model still needs doesn't vanish politely; the model re-issues the call, and you pay for the fetch, the tokens and the turn. Some tools should never be eligible at all: the one that fetches the approval record, the one whose query takes forty seconds to run. Paired with the memory tool, Claude receives an automatic warning when the conversation approaches the clearing threshold, so it can write what matters into its memory files before the clear takes the originals. That warning only helps if the run is set up to act on it.
Example clearing receipt, illustrative: one clearing event on one run, as reported back in the response's context management fields.
Where this stops helping
Short runs never reach the trigger, and for them all of this is configuration that never fires. Fine. The failure to avoid is the opposite: tuning clearing on a run whose problem is not history at all. If the tool definitions and system instructions already fill a third of the window before the first user message, the baseline is the problem, and clearing history will not fix a baseline. That material sits in front of the history zone; it is priced and attended to on every turn, and it needs its own decision: fewer tools loaded up front, tighter instructions, retrieval at the point of need instead of preloading.
There is also a debugging cost that arrives quietly. Once editing is on, your stored transcript is no longer what the model saw. When a run goes wrong three hours in, the local log shows results the model never received, or received and lost. The honest record is the one the API reports back: each response carries the edits that were applied and the tokens they cleared, and the token counting endpoint will show you the count before and after editing for the same prompt. Read those two numbers after any policy change. If the after number fell and the cache writes climbed by more than the fall is worth, the policy is wrong, whatever the window graph says.
Context is a finite resource with an attention budget attached, and clearing is one of the few tools that genuinely returns space to it. We're not arguing against clearing. We're arguing against treating it as free. Every clear is a purchase: window space, bought with a cache rewrite and occasionally with a re-fetch. Purchases get budgets, thresholds and receipts. Give it all three and it earns its place in the run.
Work with us
If your long-running agents are getting leaner and more expensive at the same time, the clearing policy and the cache are probably fighting each other. Send the run to Trida AI's intake and we'll set the context budget with you: what gets cleared, what never does, and what the receipts should show.


Top comments (0)