# Efficiency Measurement <!-- ref: @protocol/efficiency-measurement tags: [efficiency, measurement, context, claude-code, metrics] triggers: [measure agent efficiency, did this change help, is my agent cheaper, context cost, CCU] version: 5 updated_at: 2026-11-21T21:18:10.709Z --> Measure whether a change made your coding agent cheaper per unit of accepted work without making it worse — CCU (carried context per accepted unit) plus three guards, computed from Claude Code transcripts alone. **Question this answers:** *did a change — a new bootstrap, a protocol, a model, a habit — make the agent cheaper per piece of work it got right, without making the work worse?* The tool is `optimizer.mjs` (attached to `@protocol/optimizer-install`). `report` runs locally and sends nothing anywhere; `@protocol/optimizer-install` sets up the optional push for a dashboard. ## The one number: CCU **CCU = carried context per accepted unit of work.** Lower is better. - **Carried context** of one turn = `input + cache_read + cache_creation` tokens: the window the model re-read on that call. *Why this and not output or price:* a turn costs what it carries, not what it just did. One oversized tool result taxes every later turn; summing the window per turn (`ctx_integral`) measures that tax directly, where counting bytes added does not. - **Accepted unit** = a session that made a durable act (a file write/edit, a real `git commit`, or a Bash `git commit` / `gh pr create|merge` that exited 0) **and** whose next 3 human prompts after the last durable act contain no correction. *Why:* "tokens per session" rewards doing nothing. Dividing by work that stuck makes a cheap session that produced nothing count as zero output, not as efficiency. - CCU is also reported as a **median** (robust to one monster session) and **cost-weighted** (input 1, cache read 0.1, 5-minute cache write 1.25, 1-hour write 2, output 5 — input-token equivalents within one model). *Why both:* the mean answers "what did it cost", the median answers "what is typical"; when they disagree, a few sessions are driving the result. ## The guards: cheaper must not mean worse A falling CCU counts only if none of these worsens beyond its band: | Guard | Definition | Band | |---|---|---| | acceptance rate | accepted ÷ sessions | −5 points | | corrections | correction prompts per 100 human prompts | +1 per 100 | | rework | per session: files written more than twice, plus `git revert` calls | +0.10 | *Why guards:* every efficiency lever has a degenerate setting — load nothing, skip verification, stop early. Each makes CCU fall and quietly makes the work worse. The guards are the work getting worse, measured. ## The verdict | Verdict | When | |---|---| | `improved` | CCU falls ≥10% and no guard worsens beyond its band | | `cheaper-not-better` | CCU falls but a guard worsens — the saving was paid for in quality | | `no-detectable-change` | anything else with enough data | | `insufficient-data` | an arm has fewer than 10 accepted units, or metric versions are mixed | *Why 10% and 10 units:* the same task run twice can differ in cost by up to 30×. Below those thresholds the noise is the signal. ## Four checks the report does not run yet `optimizer.mjs` does not compute these yet, so do them by hand from `rollup` (per-session rows) until it does. Each one closes a gap that the published cost-efficiency metrics already cover. 1. **Put an interval on the verdict.** Resample sessions within each arm (bootstrap, 1,000 draws), and call `improved` only when the 95% interval on the CCU change sits entirely below −10%. Print the accepted-unit count of each arm next to the verdict. *Why:* identical runs of one task differ by up to 30× in tokens ([Bai et al. 2026](https://arxiv.org/abs/2604.22750)), and single-run pass@1 on SWE-bench Verified moves 2.2–6.0 points between runs ([On Randomness in Agentic Evals](https://arxiv.org/abs/2602.07150)). At a few dozen units, a 10% point change can be pure noise. 2. **Report the cost of sessions that did not land.** CCU sums carried context over *accepted* sessions only, so the cost of a session that did not land appears nowhere. Report the median carried context of non-accepted sessions per arm, and the all-sessions form (total carried context ÷ accepted units). The all-sessions form is the [Cost-of-Pass](https://arxiv.org/abs/2504.13359) shape: cost per attempt over the success rate. *Why:* failed agent runs are the expensive ones, with unresolved runs using about 4× the tokens of resolved ones ([SWE-Effi](https://arxiv.org/abs/2509.09853)). A change that makes failures longer, or more frequent and expensive, is invisible to accepted-only CCU. 3. **Compare across models in dollars, not weighted tokens.** `ccuWeighted` uses token weights within one model. When the change *is* a model switch, multiply each model's tokens by its list price, then compare dollars per accepted unit. That is the unit public leaderboards use ([HAL](https://arxiv.org/abs/2510.11977), Cost-of-Pass). Keep raw CCU as the headline for same-model changes, where price is constant and tokens are the cleaner signal. 4. **On repeated tasks, add pass^k.** Where the same task recurs (a fixed eval suite, a scheduled sweep), run it k times and report pass^k next to the acceptance rate. pass^k is the share of tasks that succeed on all k runs. *Why:* averages hide collapse. On [τ-bench](https://arxiv.org/abs/2406.12045), a frontier model under 50% at pass^1 fell under 25% at pass^8. Live transcripts don't repeat tasks, so this applies to suites only. ## Running it ```bash node optimizer.mjs report --days 28 # one window, protocol_used cut node optimizer.mjs report --from 2026-10-01T00:00:00Z --to 2026-10-29T00:00:00Z --cut 2026-10-15T00:00:00Z node optimizer.mjs report --days 28 --json # machine-readable ``` 1. **Pick the cut before you look.** `--cut <ISO>` splits sessions by start time — before vs after you made the change. *Why first:* choosing the cut after seeing the numbers is how you find the result you wanted. 2. **Give each arm at least two weeks.** *Why:* weekday mix, task mix and model releases move CCU more than most changes do; a short window measures your calendar. 3. **Read the guards before CCU.** If a guard moved, the verdict is about quality, whatever CCU says. 4. **Compare windows, never sessions.** One session is an anecdote at 30× variance. ## Traps - **Bucket by UTC hour, never local day.** Local-day bucketing moved sessions across the cut and produced a 27% count error in testing. - **Dedupe turns by `message.id`.** One API message is split across several transcript rows; counting rows double-counts usage. - **Subagent turns count toward the parent's cost but not its window gauges.** A subagent has its own window; mixing them makes the main thread look bigger than it was. - **The `protocol_used` cut can be confounded.** It splits sessions by whether they called the knowledge base. If every interactive session does (because the bootstrap runs at startup), the "without" arm holds only automated or trivial sessions and the comparison is meaningless — on one heavy user's machine it held 1 accepted unit in 1,096 sessions. Since metric `283.2` headless `claude -p` calls (entrypoint `sdk-cli`) sit outside both arms and are reported as a count, because a tool's subroutine is not work a person asked for. That removes the automated sessions but not the confound: when nearly every interactive session bootstraps, the "without" arm is still close to empty (43 sessions, 1 accepted, on the same machine after the change). Check the arm sizes; when one arm is nearly empty of accepted work, use a time cut at the install date instead. - **Changing a definition changes the number.** Every rollup carries a metric version (`283.2`); compare only within one version. ## Definitions, in full | Term | Definition | |---|---| | turn | One assistant API message, deduped by `message.id`; usage from the row with the largest `output_tokens`; tool uses summed across the id's rows; `<synthetic>` skipped | | human prompt | A `user` row that is not meta, not a compact summary, not a tool result, not a sidechain row, and does not start with `<` (slash commands, caveats) | | correction | A human prompt matching the correction markers (*that's not good*, *you should have*, *why didn't you*, *still not working*, …). Only the count is kept | | gauges | medians of boot context, per-call p50 and peak; turns per accepted unit; cache read ÷ output; cold-wake share (a main turn >300s after the previous one that writes more cache than it reads); tool calls per turn | --- *Related: `@content/web/xinyadu/2026-11-29-claude-code-task-framing-study` · `@protocol/silent-signal-and-evidence-traps` · `@content/web/huggingface/2026-11-27-model-managed-context-nvidia-harness` · `@content/web/github/2026-11-27-resume-command-osc-7577-issue-112408` · `@content/web/github/2026-11-26-opus-context-fills-faster-issue-112194`* --- *You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).* *Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*