Deep dive4 min read

Raw tokens fell 39–60%. The bill went up 14–36%.

A re-read of a public 945-run Claude Code benchmark, priced with the costUSD Claude Code writes into its own logs. /compact and subagents both look cheaper in tokens and cost more in dollars.

Last week Kensei published something rare: 945 headless Claude Code runs, interleaved arms, three repetitions per question, and every raw log on GitHub. The article compared /compact, /clear and “just keep going” by counting tokens, and found what everyone expects: /compact cuts tokens by 39–60%.

I ran the same logs through the costUSD that Claude Code itself writes into each result. The ranking flips.

The table

Three follow-up questions after forking a session at N = 5, 15 or 30 turns, Sonnet 5.5, 1-hour cache TTL, three reps each. Cost is what Claude Code billed, per call, from its own modelUsage.

Raw tokens versus billed cost for keep going, /clear and /compact after 5, 15 and 30 turns

The /compact row includes the compaction call itself, which is where the money goes.

Why fewer tokens cost more

Three prices are in play, and raw token counts treat them as one.

  • Carrying context is almost free. A cache read is 0.1× the input price. The 155k context at N = 30 costs about 3 cents per model call to carry.

  • The summary is written at the most expensive price. /compact makes the model write a summary at the output price (5×), then writes the new prefix into a 1-hour cache at 2×. At N = 30 that one call is $0.071, more than twice what it saved over the next three questions ($0.027).

  • The summary forgets what was open. The follow-ups after /compact re-read files the old context already held, so the per-question cost after compaction ($0.066–0.071) is barely under the uncompacted one ($0.074–0.080). Divide the compaction fee by that small gap and you get the break-even column: seven or eight more questions before /compact has paid for itself.

/clear wins at N ≥ 15 because it pays neither the summary nor the re-reads of a half-remembered context. It just starts over, and a fresh start on this task was cheap.

The subagent result is the same story

Raw tokens versus billed cost for a subagent versus the main thread

A subagent starts with a cold cache and writes its own prefix. That is the $0.052 → $0.093 jump on the main call. In exchange the parent’s context stays lighter, which saves about $0.002 per follow-up question. Twenty follow-ups to pay back one delegation.

Two things the logs show that the article did not look for

I also ran kvleak over the raw logs, which prices every cache miss in a transcript.

An 8 h 36 m pause inside two 30-turn chains. Rate limiting paused the runs between turn 28 (08:07 UTC) and turn 29 (16:43 UTC). Turn 29 rebuilt 142k tokens of context at the write price: $0.629 for one call, against $0.092 for the call before it. The session still reports a 95.9% cache hit rate. On Sonnet 5.5 with a 1-hour cache, one miss costs as much as nineteen hits of the same context, and the hit rate cannot see it.

$14 of the $79 benchmark bill was the cache-write premium on prefixes nothing read back. Every claude -p run writes its prefix into the 1-hour cache, paying 2× instead of the plain 1×, then exits. The 5-minute cache charges 1.25×, so for one-shot harnesses CLAUDE_CODE_PROMPT_CACHE_TTL=5m cuts that premium by three quarters, to about $3.50.

What to do with this

  1. Do not compact small contexts. At 51k of context /compact never paid back here; at 107k it took about seven more questions. Claude Code’s auto-compact fires near the window limit, which is usually right; the mistake is manual /compact as hygiene.

  2. If you will ask fewer than seven more questions, /clear beats /compact. Or just keep going. Carrying is cheap.

  3. Delegate for isolation or parallelism, not for savings. A subagent costs a cold start.

  4. Set the 5-minute TTL on batch runs. CLAUDE_CODE_PROMPT_CACHE_TTL=5m for anything that exits right after its answer.

  5. Count dollars, not tokens. Three prices, three orders of magnitude between a cache read and a summary. Any tool that reports “tokens saved” is reporting the cheapest line on the bill.

Caveats

Sonnet 5.5 only; three reps per cell, so single-digit percentages are noise; one codebase; the follow-up questions were short and answerable, which favours /clear. A long agentic task that needs the history would move the break-even. The compaction fee and the cold-start jump are not noise, they are the price list.

Reproduce it

Dataset: kenseii1/claude-code-limits-tests (runs/session/*.json, runs/subagent*/*.json). Each log carries a tok block with the per-call delta of costUSD (--resume makes the raw total_cost_usd cumulative; the harness already subtracts the previous call).

<code><code>import json, glob, re, collections, statistics as st
R = "claude-code-limits-tests/runs"
for N in ("N05", "N15", "N30"):
    rows = {}
    for arm in ("continue", "clear", "compact"):
        per_rep = collections.defaultdict(float)
        for f in glob.glob(f"{R}/session/{N}-{arm}-*q*-r*.json"):
            rep = re.search(r"-r(\d+)\.json$", f).group(1)
            per_rep[rep] += json.load(open(f))["tok"]["cost"]
        rows[arm] = st.mean(per_rep.values())
    rows["compact"] += st.mean(json.load(open(f))["tok"]["cost"]
                               for f in glob.glob(f"{R}/session/{N}-compactcmd-*.json"))
    base = rows["continue"]
    print(N, {a: f"{c:.4f} ({(c/base-1)*100:+.0f}%)" for a, c in rows.items()})</code></code>

The miss pricing: uvx kvleak --path claude-code-limits-tests/runs, then uvx kvleak session 600996ac --path … for the 8-hour pause.

An interactive version, with the token-versus-dollar charts, is on the kvleak blog.