Difficulty-normalized value-per-token efficiency metric for AI-assisted coding
Project description
TokenROI
A difficulty-normalized value-per-token efficiency metric for AI-assisted coding sessions.
Industry went from "tokenmaxxing" (reward token volume) to "tokenminning" (cap spend) without a principled way to measure value-per-token. TokenROI scores how much measurable code value a session produced per dollar of tokens, normalized for task difficulty, in a way that resists gaming by spending more.
Install
# recommended (isolated CLI install; modern macOS/Homebrew Python blocks bare pip — PEP 668):
pipx install "tokenroi-metric[bench]" # brew install pipx first if needed
# or: uv tool install "tokenroi-metric[bench]"
# or in a venv (quotes matter — zsh eats bare [brackets]):
python3 -m venv .venv && . .venv/bin/activate && pip install "tokenroi-metric[bench]"
# or from source:
python3 -m venv .venv && . .venv/bin/activate && pip install -e .
The package imports as tokenroi and the CLI is tokenroi; [bench] adds what benchmark
participants need (pytest + the static-signal tools).
Use the harness
# your local dashboard (also what bare `tokenroi` shows): recent sessions, deduped cost,
# cache share, per-project totals — the COST view (value scores come from bench mode)
tokenroi sessions
tokenroi sessions --by-project --since 7d
# score your own session logs (csv with token counts + the iso signal columns)
tokenroi score --input sessions.csv --output scored.csv
# or generate synthetic sessions with known ground truth and score them
tokenroi demo --tasks 40
# or ingest real Claude Code session logs -> tokens + cache-aware cost
tokenroi ingest --logs "~/.claude/projects/*/*.jsonl"
# or ingest ANY tool's usage export (Claude Code, Codex, Cursor, ...) on one scale
# csv columns: session_id, model, in_tokens, out_tokens
tokenroi ingest-usage --input usage.csv
# developer breakdown: WHY a session got its score + how to improve (not semantic — vs band peers)
tokenroi explain --input sessions.csv --session <id>
Benchmark your friends (bench mode — real data, real value)
Same-task cohort benchmarking: N people solve one task pack with their coding agent, each scores their own run locally (no transcript leaves the machine), the organizer ranks rows. Same task = same difficulty band; the pack's gold tests = real functional value; a fresh work dir = diff-scoped maintainability signals. This is TokenROI end-to-end on real data.
# each participant:
pipx install "tokenroi-metric[bench]" # see Install above if you don't have pipx
tokenroi bench init logparse ~/bench-logparse
cd ~/bench-logparse # do the task with your agent, any way you like
tokenroi bench submit --name alice # -> alice.row.csv (cost + value signals only)
# organizer:
tokenroi bench score rows/*.csv # -> leaderboard + honesty notes
Visible tests are in the work dir; hidden edge-case tests run at submit time from the installed package (honor system in v1). Cost is deduped and cache-aware, labeled API-equivalent — not what anyone paid.
Reproduce the paper's numbers
pip install ".[test,analysis,signals]" tabulate
python -m pytest -q # tests: axioms, dea worked example, e2e ground-truth recovery
python analysis/reproduce_all.py # regenerate EVERY result in one command -> analysis/results/
# or run individual analyses:
python analysis/run_analysis.py # full study -> analysis/results/
python analysis/robustness.py # multi-seed robustness (25 seeds) -> mean +/- CI
python analysis/weighted_baseline.py # the foil: when is the weighted ratio arbitrary?
python analysis/padding_attack.py # gaming resistance: value-padding attack
pip install ".[analysis]" # matplotlib + semopy for figures and CFA
python analysis/cfa.py # confirmatory factor analysis of the ISO structure
Paper
The IEEE-format manuscript (IEEEtran) is in paper/tokenroi.tex with
paper/references.bib and figures in paper/figures/ — drop into Overleaf
to build. A markdown draft lives in docs/paper-draft.md.
How the metric works
raw signals -> orient + normalize per band -> value vector
cost = tokens priced to dollars (the single input; process waste lands here automatically)
lean (headline): R_s = (mean(value)/cost) / max_band(mean(value)/cost) in (0,1]
work (wild logs): value *= W_eff = lines x entropy x survival (scope varies -> extensive value;
padding is entropy-crushed, deleted junk is survival-crushed)
dea (extension): factor-analyze ~15 signals -> ~3 factors (+ W_eff) -> CCR + cross-efficiency, per band
- Value is the objective, tool-measurable ISO/IEC 25010 battery — no LLM/semantic judging.
- Difficulty is handled by competing only within difficulty bands.
- Weights in the DEA extension are derived by a linear program, not hand-picked.
Results (synthetic study, 160 sessions/dataset, replicated across 25 seeds)
| claim | result (mean, 95% range across seeds) |
|---|---|
| recovers ground-truth ROI (H4) | Spearman 0.985 [0.973, 0.992] within band |
| resists gaming (H3) | frugal > wasteful in 100% of tasks, every seed |
| separates equal-quality sessions by cost (H2) | significant (p<0.05) in 100% of seeds |
| difficulty normalization works (H5) | |corr w/ difficulty| 0.08 stratified (vs ~0.37 unstratified) |
| lean ≈ DEA (H6) | Kendall τ 0.925 [0.888, 0.960] (lean often suffices) |
| factors recover ISO groups (EFA) | F1 maintainability, F2 functional/reliability, F3 security; CFA fit moderate (CFI 0.83) |
| value-padding resistance | rank gain +0.001 vs +0.051 for a coverage-trusting metric |
Layout
src/tokenroi/ metric: cost, signals, lean (+ economic_roi), dea, reduction, bootstrap, stats,
synth, cli; adapters (real Claude Code logs), code_signals (static ISO signals)
tests/ axiom + e2e + coverage tests (90% coverage)
analysis/ run_analysis, robustness (25-seed), weighted_baseline, padding_attack, cfa
-> results/ (tables, figures, hypotheses.json)
paper/ IEEEtran manuscript + references.bib + figures
docs/ design spec + paper draft
LICENSE MIT
Limitations
DEA scores are relative to the observed cohort (not absolute); the value model is blind to semantic
quality by design; validation here is on synthetic data with known ground truth — the harness ingests
real agent logs through the same interface for the live study. See docs/ for the full list.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tokenroi_metric-0.1.1.tar.gz.
File metadata
- Download URL: tokenroi_metric-0.1.1.tar.gz
- Upload date:
- Size: 55.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
957138ca4139636b2b540b6238eae0be8af89b9e9c6ff0f6f044cce5e99108e8
|
|
| MD5 |
22e9ca6dae214b64d9fc8f9d2c74815f
|
|
| BLAKE2b-256 |
6f008306a2b679d97a09617e21bbe441f5f65ed8d44efb3b1da5fe8c8a759f4e
|
Provenance
The following attestation bundles were made for tokenroi_metric-0.1.1.tar.gz:
Publisher:
release.yml on mlekhi/tokens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tokenroi_metric-0.1.1.tar.gz -
Subject digest:
957138ca4139636b2b540b6238eae0be8af89b9e9c6ff0f6f044cce5e99108e8 - Sigstore transparency entry: 2052487104
- Sigstore integration time:
-
Permalink:
mlekhi/tokens@acf919757f5eaf312e44fff09a86a0ed9a24eb43 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mlekhi
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@acf919757f5eaf312e44fff09a86a0ed9a24eb43 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tokenroi_metric-0.1.1-py3-none-any.whl.
File metadata
- Download URL: tokenroi_metric-0.1.1-py3-none-any.whl
- Upload date:
- Size: 49.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77dd4c924bee6de6fa51e024e9804be79bc017be8bb525ff6a63d9c8514a33e2
|
|
| MD5 |
22571f9357dd459f8e478860c6097a92
|
|
| BLAKE2b-256 |
1c0de119207d21b936f22a232b75d4447b6043b7b465284b6410fa9a0dab9c97
|
Provenance
The following attestation bundles were made for tokenroi_metric-0.1.1-py3-none-any.whl:
Publisher:
release.yml on mlekhi/tokens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tokenroi_metric-0.1.1-py3-none-any.whl -
Subject digest:
77dd4c924bee6de6fa51e024e9804be79bc017be8bb525ff6a63d9c8514a33e2 - Sigstore transparency entry: 2052487615
- Sigstore integration time:
-
Permalink:
mlekhi/tokens@acf919757f5eaf312e44fff09a86a0ed9a24eb43 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/mlekhi
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@acf919757f5eaf312e44fff09a86a0ed9a24eb43 -
Trigger Event:
push
-
Statement type: