# An AI Coding Cost Tracker Needs a Measurement Contract

> Source: <https://dev.to/agentis/an-ai-coding-cost-tracker-needs-a-measurement-contract-15pj>
> Published: 2026-07-25 23:08:57+00:00

The most dangerous number in an AI coding dashboard is the one labeled **cost** without a definition.

A local tool can reconstruct token activity from Claude Code and Codex session records. It can apply a dated model-price table. That produces an estimate with a clear use: comparing periods and understanding the shape of local activity.

It does not produce an invoice.

Claude Code and Codex do not write identical usage records. Claude can expose input, output, cache creation, and cache-read fields on assistant messages. Codex can separate model context from later token events, and cached input may be included inside total input.

Normalize those formats before calculating anything:

```
provider
timestamp
model
input tokens
output tokens
cache creation tokens
cache read tokens
```

Once that boundary exists, the rest of the report does not need to guess what a raw provider field means.

For a Codex event, a safe calculation starts by separating cached input:

```
non-cached input = max(total input - cached input, 0)
```

Then price non-cached input, output, cache creation, and cache reads with their own rates. Pricing total input and adding cache reads again creates a precise-looking overcount.

This is why a generic `tokens * price`

function is not enough for a multi-provider tracker.

Session files are read repeatedly. Apps restart. Watchers reconnect. Archived files can reappear. If the same event is counted every time it is observed, the weekly report grows while the underlying work stays unchanged.

Replay protection is part of accounting. Use stable provider event identifiers when they exist. If a format lacks one, document the fallback and its uncertainty instead of hiding it behind a polished total.

New model identifiers can appear before a desktop app knows their rates. API prices can also change.

A tracker should:

In Agent Island, the calculated number is labeled **API value**. It is a counterfactual estimate under the embedded rates.

A useful dashboard should not collapse these into one metric:

Only the fourth is a bill. The local records do not contain enough context to recreate it.

Before trusting an AI coding cost tracker, ask:

The implementation can be sophisticated, but the contract should be easy to explain. If the number can be mistaken for money paid, the explanation belongs next to the number.

The full measurement contract and current Agent Island scope are in the canonical guide: [AI coding cost tracker](https://agent-island.dev/ai-coding-cost-tracker/?utm_source=devto&utm_medium=owned_social&utm_campaign=ai_coding_cost_tracker_20260726).
