AI Coding Agents
How to Measure Coding Agent Token Savings
Measure coding agent token savings by repeating the same tasks with the optimizer off and on, from the same starting state. Sum fresh input, cache reads, cache writes, and output from provider usage, then compare cost per accepted task alongside turns and elapsed time. Use the optimizer’s dashboard to see what it changed and reconcile the cost estimate against billing records.
Define what it means to finish
Choose tasks the optimizer could realistically affect. For a shell filter, use work that normally produces noisy test or build results. For a wire proxy, include a workload with long tool responses or reused history. Include a task that rarely uses the intercepted path, too. It can reveal fixed overhead that a favorable demo would miss. Assign each task to a workload group before collecting results so the mix stays the same in both configurations.
Give each task an acceptance rubric before you run it. A patch might need to pass the same targeted regression test and repository checks, preserve an existing interface, and avoid touching unrelated files. A review might need to identify the specific defect and point to evidence in the original output. Apply the rubric to the final result with the same level of human review in both arms. Record a failed, aborted, or time-limited attempt even if it produced a plausible partial answer.
Set a spend and time limit for each attempt. Specify how to handle external outages, operator intervention, and retryable errors before looking at results. If an attempt fails after consuming tokens, include those charges in the operational totals. Mark infrastructure-related invalid attempts separately when your protocol allows an exclusion, retain their trace, and report the exclusion count so readers can see what happened.
Reset the workspace and control cache state
Create a repeatable starting snapshot with the same repository revision, fixtures, generated inputs, and tool permissions. Pin the agent, provider, model or model map, optimizer version, and tool settings. Save the exact task prompt and any scripted operator answers. Restore the snapshot and start a fresh agent session for each attempt. Keep native compaction and enabled tools constant unless the optimizer installation changes them. Log any such changes as part of the treatment.
Run the native configuration with the optimizer disabled and the treatment with it enabled. Interleave attempts so the configurations encounter comparable provider and machine conditions. Repeat the task in each configuration to see how much outcomes vary, including how often the agent chooses a different tool sequence. Watch for state in temporary files, local indexes, or shared optimizer stores that can carry over between runs. Decide whether that state belongs in a cold-start test or a warmed deployment test.
Define cache conditions independently of session reset. A fresh transcript alone cannot prove that the provider starts cold. For a warm-cache trial, use the same intended warm-up procedure in each arm and record the usage of those requests. Keep setup and steady-state costs visible and include setup in the overall spend if deployment would pay for it. If the provider reports actual cache reads and writes, use them to verify which runs entered the expected state. If access to cache data is limited, describe the cache state as unverified. Context compression versus prompt caching
Capture request usage and wall time
Store raw usage events and a normalized ledger. Join each request to the task, attempt, arm, and phase so the totals can be reproduced later. Capture the actual returned model or billing route when available. Include model calls by subagents, summarizers, retries, and fallbacks when they incur charges. A streaming response may expose usage only after generation. Log missing usage explicitly and reconcile against the provider’s billing export where possible.
| Field | What to log | What it explains |
|---|---|---|
| Fresh billed input | Uncached input exclusive of separate cache buckets | Whether new text or a cache miss raised the full-price input charge |
| Cache read | Tokens billed at the cache-read rate | How much repeated input the provider reused |
| Cache write | Tokens billed at each applicable write rate | The cost of establishing a new reusable prefix |
| Output | Generated tokens billed as output | Changes in answer length, tool-call arguments, or billable generation on extra requests |
| Model turns and tool calls | Model request count, retry count, and tool calls by family | Whether smaller prompts came with a longer path or a different tool mix |
| Time | Elapsed task time, model request time if available, and time spent in tools or retries | Whether the change helps the user finish sooner |
| Outcome | Acceptance, failure or timeout, and rubric results | Whether a reduction in spend preserved task quality |
| Optimizer events | Rewrites, bytes or tokens removed, retrievals, and pass-through events | Whether the feature engaged and which payloads it changed |
Define a turn as a model request for the comparison and log retries consistently. Keep model latency and end-to-end latency separate. A proxy that returns streaming output smoothly can still add enough processing time to delay the first usable response. A tool that reduces input can still lengthen the task if the agent makes more calls to fill in missing context. Compare user-visible duration across complete attempts and inspect model and tool timings when a run gets slower.
Convert reported usage into a cost estimate
Inspect what the provider’s input field includes. If it already includes cache reads, subtract those from the inclusive figure before pricing the fresh bucket. If the API reports mutually exclusive categories, use those as given. Handle write categories the same way and preserve the original fields for audit. Treat an absent field as unknown until the provider record establishes that the category was unused.
Per request, multiply fresh input, cache reads, cache writes, and output by their respective USD rates per million tokens. Add the products and divide by a million. Sum those estimates across the attempt using each request’s actual model and rate. Reconcile against account billing before treating the estimates as dollars paid. A subscription allowance or a quota-based endpoint may need a separate usage comparison. Current provider rates
For a worked comparison, assume the baseline turn has 100,000 cache-read tokens and 10,000 fresh tokens, and the treatment retains the same cache read while reducing fresh input to 2,000 tokens. Assume equal output and no writes on the measured turn. At the committed Anthropic claude-sonnet-5-5 rates of $0.10 per million reads and $2 per million fresh input, the baseline input estimate is (100,000 × $0.10 + 10,000 × $2) ÷ 1,000,000 = $0.030. The treatment estimate is (100,000 × $0.10 + 2,000 × $2) ÷ 1,000,000 = $0.014. The estimate covers the measured turn only. Subsequent requests to recover removed details would enter the treatment’s task ledger.
Compute cost per accepted task by dividing the spend across all attempts in an arm by the number of attempts that passed. Keep the raw spend and acceptance count beside the ratio. If no attempt passed, the ratio is undefined and the failure rate is itself a result. Use paired task groups to see whether an overall improvement depends on a particular type of task. Cost per accepted task
Reconcile the dashboard against the provider
RTK’s README describes rtk gain as a view of command savings and documents filtered and bypassed commands. A large percentage can reflect excellent shortening of a narrow stream. Compare the count of intercepted commands with the count of native tool calls and the overall request mix. Separate command filtering from RTK’s optional proxy if both are available in the version you trial. A treatment that silently activates both changes what the test can attribute to the command hook. RTK
Headroom’s README describes an outbound compression path and local recovery of originals through CCR. When a result is recovered, save the retrieval event and identify the model turn that followed it. A dashboard can legitimately count a reduction on the first send even when recovery adds context and requests later. An outbound request ledger is useful for confirming a payload changed. Provider usage lets you see how the surviving text was billed. Headroom
In the independent tokbench pilot, with N=1 per arm, RTK’s own meter reported 58.4K tokens saved, a 74.7% reduction on the commands it touched. That reported saving was about 2.5% of native billed input. The RTK arm logged 2.89M billed input tokens against 2.28M for native, a gap tokbench’s notes attribute to run-path variance. The same pilot reports on-wire compression in Headroom’s arm alongside a longer run. Product metrics describe the payloads they observe, while provider input includes instructions, schemas, untouched tool results, and history across the requests the agent actually made. That pilot’s provider offered no prompt-cache discounts. tokbench pilot and scope
When you reconcile records, compare the same period, task IDs, model and attempt boundaries. Look for missing streaming usage, requests outside the named agent process, and input fields that already include cache buckets. Keep an “unattributed” entry when the bill includes usage you cannot join to a request. An unexplained gap limits how confidently you can assign the savings to a particular feature. Preserve that gap in the report.
Check which phase changed the result
Break down the paired runs at a boundary the task already exposes, such as investigation, editing, and test verification. For each phase, record the average billed input per model request and the number of requests. This helps distinguish a smaller request from a shorter workflow. Compare category totals inside the phase as well. An apparent improvement after warm-up can disappear in a workflow that repeatedly starts fresh sessions.
For a shell-heavy trial, preserve a small sample of raw and rewritten results with their provider request IDs. Check whether the agent reran a command to recover details or chose a native tool that bypassed the filter. Doing this for a passing task and a failed task can reveal why a similar dashboard reduction produced different outcomes.
Read the result before rolling out
Put acceptance rate, cost per accepted task, billed categories, turns, and elapsed time next to each other. Show individual attempts as well as a typical result and spread. Ask whether the difference between configurations is larger than the variation between repeated native attempts. Check whether a slow or expensive treatment run used substantially more turns, incurred new cache writes, or had to reread compressed material. Inspect the trace at the phase where the difference first appeared.
Use the traces to choose a bounded deployment. If shell-heavy tasks improve and file-heavy tasks show little change, scope command filtering to the shell-heavy workflow you measured. If a proxy reduces fresh input but pushes writes up on warm sessions, test a prefix-preserving setting separately. If a task passes only after an operator supplies missing evidence, count the intervention under the rubric you wrote before the trial.
Save the task snapshot, pass criteria, configuration, version pins, ordering, starting cache observations, raw usage, derived cost ledger, and exclusions together. That record lets you retest after a change in the host, model, integration, or rates. When bills are unavailable, report provider token usage and a rate-based estimate with that limitation. The result is a reproducible test of the configuration and workload you actually ran.
Sources
- tokbench independent pilot, N=1 per arm (GitHub, accessed 2026-11-30)
- RTK command filtering and gain reports (GitHub, accessed 2026-11-30)
- Headroom pipeline and local retrieval (GitHub, accessed 2026-11-30)
Interactive report
- Do Token Savers Actually Save?: RTK reported saving 74.7% of the tokens on the commands it touched. In tokbench’s pilot, the RTK run still used 27% more provider-billed input than the unmodified run. The comparison shows why a tool’s savings counter and the provider’s meter can move in opposite directions.
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
How to Measure Coding Agent Token Savings. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/measure-coding-agent-token-savings/