Skip to content

About

Don't just count AI coding tokens — blame them. Zero-config offline multi-agent token ledger with 1:1 Git provenance, 30d git-blame patch survival, and burn forensics.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

TokenBlame (v2.2)

Don't just count AI coding tokens — blame them.
Zero-config, 100% offline multi-agent token ledger with out-of-repo Git commit provenance, fixed-horizon (t+30/60/90d) & Squash-Merge-resilient line retention, and exit-code-aware burn forensics.

TokenBlame Overview — Shareable Redacted Edition

TokenBlame is a single-user local observability CLI that joins transcripts across Claude Code, Codex CLI, Gemini CLI, and Antigravity with your local Git repositories (strictly read-only via git --no-optional-locks) — without mutating Git commit history, trailers, or .git/refs.

How TokenBlame Fits Alongside Existing Tools

Token accounting, commit attribution, and code survival each have strong existing tools (ccusage, Tokscale, Git AI, Entire, survived). TokenBlame's design choice is combining zero repo mutation, zero third-party runtime dependencies (Python 3.11+ stdlib), local SQLite retention archiving, and strict fidelity separation in one offline personal workflow:

Tool Primary Focus Token Bucket Breakdown Git / Outcome Linkage Repo Mutation Runtime
ccusage / Tokscale Multi-agent token & cost accounting (+ Tokscale recovery ledger & task reports) Yes (input / cache / output / reasoning) Cost/task-focused (no git blame retention) None Node / Rust
Git AI (OSS / Teams) Line-level AI authorship + Teams PR cost, rework & churn analytics Yes (spec covers buckets & 90d DB; team analytics in Teams tier) Line-level authorship + PR cost/churn Git notes / metadata Rust / Cloud
Entire Session checkpoints & token hotspot diagnostics Yes (fresh / cache / output / subagent) Session checkpoints linked to commits Checkpoint metadata Go
survived Fixed-horizon t+30/60/90d code survival (with notYet cohort separation) No Fixed-horizon commit survival None TypeScript
TokenBlame (v2.2) Local offline multi-agent cost + commit provenance + t+30/60/90d cohorts & HEAD retention + exit-code burn loops Yes (4-bucket + strict unbucketed separation) Out-of-repo record-hook spool + revert, HEAD retention & matured cohorts (notYet separated) None Python 3.11+ stdlib only

Honest measurement scope:

  • HEAD Line Retention vs. Fixed-Horizon Cohorts (t+30/60/90d): line_survival_30d_pct tracks HEAD retention of lines from the recent 30-day window (with Squash-Merge / Rebase fallback and unobserved_lines kept separate on git blame errors). Alongside it, durability.cohorts (t30d, t60d, t90d) measures matured fixed-horizon cohorts explicitly separated from immature notYet commits.
  • Pre-Indexed Query Latency (3.5ms): Refers specifically to filtered tokenblame summary reads against an already-built observatory.sqlite, not cold full-history harvesting or git blame scans.
  • Diagnostic Signals ≠ Causal Proof: FAILURE_LOOP (nonzero exit/error streaks), ITERATION_LOOP (zero-error verification repeats), uncommitted high-burn sessions, and line retention are investigative signals — not automatic proofs of wasted effort, code correctness, or causal ROI.

High-Burn Root-Cause Forensics & Multi-Grain Heatmap

TokenBlame Heatmap and High-Burn Forensics Radar

  • Allowlisted Tool Forensics (Zero Leakage): Extracts peak turn spikes (Peak #T: Out / Fresh) and exit-code-aware loop classifications (FAILURE_LOOP(Bash:pytest x6, err=4) vs normal ITERATION_LOOP(Bash:pytest x4)) using an allowlist of tool/command basenames — never storing command arguments, stdout/stderr, file paths, or prompts.
  • Privacy-Sealed --shareable Mode: tokenblame build --shareable produces a standalone offline HTML dashboard (shareable-observatory.html) with salted SHA-256 aliases (repo-01, c-9a4f1b2c) and zero local paths, usernames, or commit subjects.

Quickstart (Zero-Config, Python 3.11+ Stdlib Only)

# Instant zero-install run via uvx:
uvx tokenblame

# Or install globally:
uv tool install tokenblame
# or: pip install tokenblame

# Harvest logs + build offline HTML + print 30-day summary in one command:
tokenblame

# Also emit privacy-redacted shareable HTML + IR:
tokenblame build --shareable

# Open dashboard in your browser (or Orca tab when running inside Orca):
tokenblame open
tokenblame open --shareable

# Sub-10ms filtered queries powered by indexed observatory.sqlite:
tokenblame summary --days 7
tokenblame summary --days 30 --lane my-repo --json

# Check environment, detected agent logs, timezone, and hook status:
tokenblame doctor

# One-click 1:1 provenance hook setup (with automatic backup & --uninstall):
tokenblame init
tokenblame init --dry-run
tokenblame init --uninstall

# Override local OS timezone when needed:
tokenblame summary --days 7 --tz America/New_York

By default, TokenBlame discovers local Git repos under ~/projects, ~/code, ~/dev, ~/src, ~/work, ~/repos, and ~/GitHub (plus repeatable --scan-root /custom/dir) and writes all local artifacts with 0600 permissions to:

  • macOS: ~/Library/Application Support/tokenblame/
  • Linux: ${XDG_DATA_HOME:-~/.local/share}/tokenblame/
  • Override: TOKENBLAME_DIR=/path/to/dir

Optional 1:1 Commit Provenance Hook (record-hook)

To upgrade concurrent same-repo agent sessions from time-window heuristics ([-2h, +12h]) to deterministic 1:1 EXACT_HOOK_OID attribution without adding files, trailers, or git notes to your repositories:

Claude Code (~/.claude/settings.json)

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "tokenblame record-hook --provider claude"
          }
        ]
      }
    ]
  }
}

Gemini CLI (~/.gemini/settings.json)

{
  "hooks": {
    "AfterTool": [
      {
        "matcher": "run_shell_command",
        "hooks": [
          {
            "type": "command",
            "command": "tokenblame record-hook --provider gemini_cli --emit-empty-json"
          }
        ]
      }
    ]
  }
}

Epistemic Integrity Guarantees

  • Strict Fidelity Separation: Unexposed IDE transcripts or legacy unbucketed SQLite threads are never blended into exact 4-bucket totals; estimated byte-volume side ledgers (ESTIMATED_TRANSCRIPT) are reported separately.
  • Honest API-Equivalent Pricing: Uses pinned official token rates (input, cache_write, cache_read, output), labels alias/fast-mode tiers explicitly, and leaves unpriced preview models as unpriced rather than fabricating USD totals.
  • Transparent Causality Tiers: Separately badges 1:1 HOOK, SHA_META, WINDOW_HEURISTIC, and DAY_EPISODE links so attribution strength is never overstated.

Closing the Loop: Pre-Merge Verification

TokenBlame measures post-hoc token burn, retry loops, and 30-day patch survival. To prevent AI test shortcuts, tautological assertions, and surviving mutants before code merges on GitHub PRs, check out NoCheat Merge Gate — a deterministic, zero-LLM CI verification gate (Apache-2.0).


License

Apache-2.0 — see LICENSE.

About

Don't just count AI coding tokens — blame them. Zero-config offline multi-agent token ledger with 1:1 Git provenance, 30d git-blame patch survival, and burn forensics.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages