Clear Every Third Task: A Measured U-Curve in the Context Economy of Coding Agents
Abstract
Version 1.2 (15 September 2026): correction of the modeled costs. Versions 1.0 (DOI 10.5281/zenodo.22699668) and 1.1 (DOI 10.5281/zenodo.22749959) priced the token counters with two errors. Both are the author's. The price level was wrong. Costs used $3.00/$15.00 per million input/output tokens, with cache reads at $0.30. claude-sonnet-5 is listed at $2.00/$10.00, the standard price since 10 August 2026, with reads at $0.20. Every cache write was priced at the 5-minute rate ($3.75). All cache writes in the 36 runs are 1-hour writes, billed at 2× input ($4.00). The first error scales all costs equally. The second changes the weight of cache writes, and with it the percentages, the p-values and part of the conclusions. Token counters, calls, sessions, wall-clock times and test outcomes are unchanged. Mean cost per run at 1/2/3/4/6/12 tasks per session: $2.165 / 1.854 / 1.622 / 1.704 / 1.679 / 1.780 (was 2.680 / 2.399 / 2.138 / 2.279 / 2.281 / 2.473). The minimum stays at three tasks. Clearing after every task vs every third: +33.5%, p = 0.0022, Holm-adjusted 0.011 (was +25.3%). Clearing every second task vs every third: +14.3%, p = 0.0022, Holm 0.011 (was +12.2%, p = 0.0108). Never clearing vs every third: +9.7%, p = 0.046, Holm 0.14, which is not significant (was +15.6%, p = 0.0108). The earlier claim that both extremes are significantly more expensive than the optimum is withdrawn for never clearing. Every fourth / every sixth task vs every third: +5.1%, p = 0.17 / +3.5%, p = 0.45 (was p = 0.097 / 0.21). The middle is still a plateau. Cost drop from every task to every third: 25.1% (was 20.2%). Price of a cache write relative to a cache read: 20× (was 12.5×). Spend at the optimum: 39.0% cache read, 32.3% cache write, 28.7% output (was 44 / 23 / 33). Limitations now stated explicitly. "Zero failures" refers to tests the agent wrote itself, and the number of tests differed between conditions: 116.8 per run on average when clearing after every task, 106.8 when never clearing. The reference condition was selected after the fact as the observed minimum. Corrected per-run costs are in runs_ucurve_costs_v1.2.json, and the recomputation scripts with their outputs are in recompute-2026-09-15.zip. runs_ucurve.json is unchanged, and its modeled_cost_usd field keeps the old prices. Price list: https://platform.claude.com/docs/en/about-claude/pricing (retrieved 15 September 2026). How often should an LLM coding agent's context be cleared? A fixed set of twelve programming tasks was run under six session-length policies — a fresh session every 1, 2, 3, 4, 6 and 12 tasks — with six replicates each, holding the model, the tasks and their order constant. 36 runs. Modelled cost is not monotone in session length. It falls from $2.17 per run when the context is cleared after every task to $1.62 at every third task, then rises to $1.78 when the context is never cleared. Clearing after every task is significantly more expensive than clearing every third task (exact permutation test p = 0.0022, Holm-adjusted 0.011). Never clearing is 9.7% more expensive, but not significantly so (p = 0.046, adjusted 0.14). Three, four and six tasks per session are indistinguishable, so the low region is a plateau rather than a point. The U-shape decomposes into cache writes falling and context per call rising, with 1-hour cache writes priced at 20× cache reads. Run-level token counters and the harness are released with the report. Version 1.1 — corrections to version 1.0 (DOI 10.5281/zenodo.22699668). In version 1.1 the measurements, the tables, the statistics and the conclusions were unchanged from version 1.0. What changed is text that overstated what the verification gate established, plus technical information that was missing from the record: Corrected: the abstract said the design held “the verification suite constant”. It did not. The suite is written by the agent as part of each task, so it differs between runs; the phrase has been removed. Corrected: the abstract said “4086 tests, zero failures, in every condition”. 4086 is the total over all 36 runs, not a per-condition figure. Zero failures in every run and every condition is correct and stands. Added: Table 2, the per-condition breakdown of tests executed (701, 697, 687, 699, 661, 641), with the per-run range of 97 to 127. Added: the model snapshot and toolchain, absent from version 1.0 — the model alias resolves in the session logs to claude-sonnet-5 with no dated suffix; Node v24.20.0; Claude Code 2.1.252; list prices $3.00/$15.00 per million input/output tokens, cache writes $3.75, cache reads $0.30 (these prices were wrong and are corrected in version 1.2). Added: an explicit statement that temperature was never set and is not recorded, so none is reported. Added: a threat to validity recording that the verification suite is agent-authored, and a rewritten quality-control paragraph saying what the gate can and cannot certify. The two corrected statements were identified in adversarial review and reported publicly by the author to the W3C Agent Conformance group before this version was issued (public-agent-conformance, September 2026, message 0031). The cost result does not depend on the verification suite: every figure in Table 1 is computed from token counters.
Publication details
- Journal / source
- Zenodo (CERN European Organization for Nuclear Research)
- Publication date
- 15 September 2026