{
"name": "usage-waste",
"title": "Spend lost to rebuilds, long-lived subagents and large contexts",
"section": "Records",
"order": 70,
"date": "2026-12-04",
"good_until": "2027-03-04",
"commit": "4ad94f0e470c",
"command": "make ctx && sqlite3 ~/.ctx/ctx.sqlite \".backup COPY\" && CTX_DB=COPY CTX_NOW=2026-12-03T22:00:00Z ./ctx usage waste --days 14 (five runs, median); CTX_DB=COPY ./ctx doctor with the line on and off (fifteen runs each); the independent recount is a Python script that reads the same rows and applies the three definitions one response at a time",
"conditions": {
"build": "ctx at check-in 4ad94f0e470c on the usage-waste branch, run only against a copy of the live archive made with sqlite3 .backup; the live archive was never opened by it",
"archive": "a fresh copy of the archive taken 4 December after the first run: 113,005 responses in the window (14 days to 3 December 22:00 UTC): 104,704 from Claude Code, 7,987 from pic and 314 from Codex",
"hand figures": "the brief's hand-computed numbers for the same window: total about $11,800, rebuild about $3,070 (26%), long-lived about $3,950 (33%), large about $5,150 (44%), union about $7,000. The brief's author has since said the hand rebuild counted every subagent response (non-empty parent) that wrote 100,000 or more tokens to the cache, with no gap condition, and left out main sessions",
"bars": "set in the brief before any run: each figure within 3% of the hand figure or every difference explained; under 2 seconds for --days 14 on the archive copy, median of 5; under 50 ms added to ctx doctor",
"definitions": "a rebuild writes 100,000 or more tokens to the cache after the cache has expired: write_5m of 100,000 or more when the same session's previous response, whenever it was, is 5 minutes or more earlier, or write_1h of 100,000 or more when it is an hour or more earlier; a long-lived subagent response is any response in a session with a parent that has 200 or more responses up to the window's end; a large context response has input plus both cache writes plus cache read over 400,000. Times are compared as the ISO strings in the at column. The first build counted 100,000 across both tiers after 5 minutes whichever tier, and found $3,538; the rule above replaced it after the brief's author found the hand query's rebuild was a different thing",
"doctor": "the line reads a figure the hourly scan keeps in ctx_meta, so doctor does no query of the usage table; the scan's own cost for it is one query of about 0.1 s",
"hand check": "the three kinds were also counted by a separate script that walks each session's responses in order; it matched the SQL to the dollar on the all-harness window and on the Claude Code only window"
},
"summary": "Whether ctx usage waste reproduces a hand count of how much spend went to cache rebuilds, long-lived subagents and large contexts, and what the report and the doctor line cost.",
"metrics": [
{
"label": "Total spend in the window",
"value": "$13,153 over all harnesses; $11,735 Claude Code only",
"note": "the hand figure, about $11,800, is Claude Code only: 0.6% under it. pic's $1,411 and Codex's $7 are in the report because ctx usage counts them"
},
{
"label": "Rebuild",
"value": "$3,488 (26.5% of all spend; 29.7% of Claude Code's)",
"note": "the hand figure, about $3,070, counted every Claude Code subagent response that wrote 100,000 or more tokens with no gap condition: $3,004 over this window and archive, 2% under it, and the difference is the partial day. The report's $3,488 is $2,965 of subagent writes to the 5-minute cache that came after 5 minutes or more (1,915 responses; every subagent rebuild in the window is a 5-minute write) and $523 of main-session writes to the 1-hour cache that came after an hour or more (233 responses). A 1-hour write after 20 minutes, and 100,000 split across the two tiers, are not counted"
},
{
"label": "Long-lived subagent",
"value": "$4,670 over all harnesses (35.5%); $3,821 Claude Code only (32.6%)",
"note": "3.3% under the hand figure of about $3,950 on Claude Code alone, just past the bar. The brief says the hand query took in up to one extra partial day: a window starting 11-19 00:00 instead of 22:00 gives $4,088, so the hand window lies between; pic's long subagent sessions, $849, are the rest of the difference to the all-harness figure"
},
{
"label": "Large context",
"value": "$5,004 (38.0% of all spend; 42.6% of Claude Code's)",
"note": "2.8% under the hand figure of about $5,150, within the bar; pic and Codex have no response over 400,000 tokens"
},
{
"label": "Union of the three",
"value": "$7,924 over all harnesses (60.2%); $7,075 Claude Code only (60.3%)",
"note": "1.1% over the hand figure of about $7,000 on Claude Code alone, within the bar"
},
{
"label": "Agreement with a separate count",
"value": "exact to the dollar on every figure",
"note": "the SQL and the script agree on 113,005 and on 104,704 responses, with the 5-minute and 1-hour rule"
},
{
"label": "ctx usage waste --days 14 on the archive copy",
"value": "median 431 ms of 5 runs (399 to 463 ms; a cold first run earlier took 1.4 s)",
"note": "the first version of the query took 4.2 s: the rebuild test ran again for each of the five sums that use it, until the window and the rebuild ids were computed once; the previous response is found with a window function over the sessions that wrote that much at all, not per response"
},
{
"label": "Added to ctx doctor",
"value": "0.0 ms (5.7 ms with the line, 5.8 ms without, median of 15)",
"note": "computed inside doctor, the same figure took 160 ms; it is now worked out by the hourly scan"
}
],
"bar": "every figure within 3% of the hand figure or each difference explained; ctx usage waste --days 14 under 2 seconds, median of 5; under 50 ms added to ctx doctor",
"verdict": "pass",
"baseline": "the hand-computed figures in the brief, and a separate count of the same rows",
"meaning": "All three bars pass. The rebuild gap to the hand count was the hand query's own definition, subagent writes with no gap condition, not the report's: on the report's rule, which knows the 5-minute and 1-hour cache lifetimes, the rebuild is $3,488. Long-lived is 0.3 points past 3% on Claude Code alone and is put down to the hand query's extra partial day, which the brief names; that is an inference, not a rerun of the hand query. Total, long-lived and union are higher in the report because it counts pic as ctx usage does."
}