Measurement and sustainability

Does reusing code save AI energy? Measure tokens and time before carbon

Reusing a relevant implementation can reduce generated tokens, repeated tool calls and review cycles. That can reduce compute demand, but the defensible claim starts with measured model usage and clearly labeled scenarios—not a universal grams-of-carbon number.

By Moresq Corpus9 min read
One verified implementation passing through a retrieval gate instead of several regenerated alternatives.
Reuse can avoid generation and review cycles, but environmental savings remain estimates unless token, latency and infrastructure energy are measured. Open image.

A transparent method for estimating how verified code reuse can reduce AI tokens, latency, review work, facility energy and location-based CO2e.

Code reuse can avoid work, but the baseline is counterfactual

A coding agent that retrieves one strong implementation may avoid generating several alternatives, debugging a familiar failure mode and asking a reviewer to reconstruct provenance. The direct outcomes are fewer generation tokens, fewer agent rounds and less engineering time.

The comparison still needs a baseline. “Tokens saved” means the difference between a credible control workflow without corpus guidance and a treatment workflow that searches, retrieves and adapts an artifact. If the retrieved pattern is a poor match, reuse can consume more time and energy than a short direct implementation.

Metadata-first search matters because an agent can reject weak candidates without loading full source. The economical retrieval policy is selective: reuse a strong, proven match; record a miss when the fit is weak.

Measure tokens, latency and cost before estimating energy

The strongest record uses real API or session logs for both workflows. Capture input and output tokens, model, tokenizer, number of rounds, wall-clock latency, corpus fee and model cost. Keep measured values separate from planning estimates.

For repeated internal work without a controlled comparison, code-size and avoided-round estimates can still be useful, but they should use ranges and a confidence score. Unknown model prices should produce a null cost field rather than an invented dollar saving.

  • Measured tokens: use provider or session logs when available.
  • Estimated tokens: publish a range and the avoided-work assumptions.
  • Latency: include retrieval time as well as avoided generation and review.
  • Review risk: report qualitatively unless incidents or review hours are tracked.
  • Cost: leave null when the model, token split or price is unknown.
Economy calculationtext
tokens_saved = control_tokens - treatment_tokens
savings_rate = tokens_saved / control_tokens
net_cost_saved = control_model_cost - treatment_model_cost - corpus_fee

Energy, CO2e and water require separate assumptions

Token savings are not an energy meter. Model architecture, serving hardware, batching, utilization, response length and data-center efficiency all affect electricity use. Without provider telemetry, energy savings should be presented as a scenario range for avoided inference work.

Facility energy includes infrastructure overhead through power usage effectiveness. Location-based CO2e multiplies facility electricity by the grid intensity where compute ran. Market-based procurement and marginal emissions answer different questions and should remain unknown unless specific evidence exists.

A water usage effectiveness scenario can provide a direct operational water proxy. It does not include indirect water used by power generation unless a separate regional source supports that calculation.

Environmental scenariostext
facility_Wh = estimated_IT_Wh × PUE
location_CO2e_g = facility_kWh × grid_gCO2e_per_kWh
direct_water_L = facility_kWh × WUE_L_per_kWh

A July 27 Moresq example: useful evidence, not a power reading

Across three internal Moresq engineering sessions on July 27, 2026, the economy ledger estimated 6,180 to 9,030 output tokens avoided by reusing billing, workspace, deployment and verification patterns. The records estimated 1.36 to 55 Wh of avoided IT inference and 1.49 to 93.5 Wh at the facility after PUE scenarios.

Those facility scenarios correspond to roughly 0.07 to 4.68 gCO2e on a 50 g/kWh low-carbon grid, 0.37 to 23.38 gCO2e at 250 g/kWh, and 0.81 to 50.96 gCO2e in a 545 g/kWh stress case. Market-based and marginal emissions remained unknown.

The builds, tests and production checks were measured. Tokens, provider energy, CO2e and water were not. The correct conclusion is that reuse probably reduced inference demand and clearly reduced engineering time; the environmental magnitude is directional.

Publish claims that another engineer can audit

A trustworthy sustainability claim names the project and action, reused sources, baseline and treatment, measured token logs if available, estimated savings, reuse count and confidence. Environmental values need the PUE, grid-intensity and WUE assumptions beside them.

This method makes modest results valuable. A small validator may save few tokens per reuse but compound across hundreds of projects while also reducing review risk. Global savings should still be shown separately from observed reuse.

  • Separate measured values from estimates.
  • Separate location-based, market-based and marginal emissions.
  • Do not infer physical floor or rack space from token counts.
  • Use ranges when model, hardware or data-center location is unknown.
  • Record misses and harmful reuse, not only successful retrievals.

FAQ

Frequently asked questions

Does reusing code always save AI energy?

No. A strong match can avoid generation and review rounds, while a weak match can add work. Measure or estimate the control and treatment workflows before claiming a saving.

Can tokens be converted directly into watt-hours?

Not reliably without model, hardware and serving data. Tokens can support a scenario estimate, but they are not an electricity measurement.

What can Moresq measure today?

Moresq can record control and treatment token usage, latency, model cost, corpus fee and reuse metadata when those logs are supplied. Environmental values remain estimated unless infrastructure telemetry is available.

Does a lower token count prove lower carbon emissions?

It suggests lower inference demand under comparable conditions. Actual location-based, market-based and marginal emissions require separate electricity and procurement evidence.

Moresq Corpus

Retrieve proven code with source, rights and proof attached.