{
 "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": "f7008ec13242",
 "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 f7008ec13242 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": "613,133 responses from 31 March to 4 December 2026; the window is 14 days to 3 December 22:00 UTC, 113,005 responses: 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 hand query is not in the tree, so what it counted is inferred from the figures",
  "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 (write_5m plus write_1h) when the same session's previous response, whenever it was, is 5 minutes 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",
  "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,538 (26.9% of all spend; 30.2% of Claude Code's)",
   "note": "15% over the hand figure of about $3,070 on either scope; not explained. A window that starts later, taking the previous response only from inside the window, ordering by row id, folding subagents into their parent, a 10-minute gap and a different split of the two cache tiers were each tried and none gives $3,070. 84% of it, $2,965, is subagent responses that wrote to the 5-minute cache; main sessions' 1-hour writes are $574"
  },
  {
   "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; 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,938 over all harnesses (60.4%); $7,090 Claude Code only (60.4%)",
   "note": "1.3% 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, so the differences from the hand figures are in what was counted, not in the query"
  },
  {
   "label": "ctx usage waste --days 14 on the archive copy",
   "value": "median 404 ms of 5 runs (396 to 409 ms; the first, with a cold cache, 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.1 ms (5.7 ms with the line, 5.6 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": "fail",
 "baseline": "the hand-computed figures in the brief, and a separate count of the same rows",
 "meaning": "Speed and the doctor cost pass by a wide margin. The correctness bar fails on one figure, the rebuild, 15% over the hand count with no explanation found, and the long-lived figure is 0.3 points past the bar on Claude Code alone. Total, large and union are within it on that scope, and the all-harness report is higher on total, long-lived and union because it counts pic. The report follows the written definitions exactly, as the separate count shows; if the hand count meant something else by a rebuild, that is the thing to settle."
}
