Skip to main content

clanker-analytics

Token usage analytics for AI coding tools. Reads local session logs and shows per-project breakdowns using DuckDB.

Supports Claude Code, Codex, Gemini CLI, and Agy / Antigravity.

clanker-analytics chart clanker-analytics table clanker-analytics regime

Worried your cache hit rate dropped? --regime auto-detects statistically significant changes using Welch's t-test: clanker-analytics --regime --since 30d --tool claude

Install

uv tool install clanker-analytics

Or run without installing:

uvx clanker-analytics

Usage

clanker-analytics                        # 7-day chart (default)
clanker-analytics --since 24h            # last 24 hours (also: 7d, 2w, 2026-03-01)
clanker-analytics --share                # chart + copy to clipboard + open X
clanker-analytics --table                # tabular view
clanker-analytics --table --by date      # table grouped by date (also: model, session)
clanker-analytics --table --by execution # interactive, exec, and subagent usage
clanker-analytics --regime               # detect cache rate regime changes
clanker-analytics --tool claude          # Claude Code only (also: codex, gemini, agy)
clanker-analytics --refresh              # force cache rebuild
clanker-analytics --debug-timing         # print cache decisions and stage timings
clanker-analytics --profile              # print a cProfile summary to stderr
clanker-analytics --sql "SELECT ..."     # custom SQL against 'tokens' table

How it works

DuckDB reads session logs directly from ~/.claude/projects/, ~/.codex/sessions/, and ~/.gemini/tmp/ — no Python JSON parsing. Results are cached to ~/.cache/clanker-analytics/tokens.parquet (ZSTD compressed) with a per-file manifest at ~/.cache/clanker-analytics/tokens-meta.json.

The cache is incremental: unchanged source files are reused, changed files are re-read, and deleted files are removed from the cached table. A full rebuild only happens when the cache is missing, you pass --refresh, or the cache schema changes.

--debug-timing prints cache decisions and per-stage timings. --profile adds a Python cProfile summary; it is mainly useful for filesystem scanning and Python-side overhead, not DuckDB query execution time.

Columns

  • total — all tokens processed (input + output + cache write + cache read)
  • billable — total minus the 90% cache read discount
  • output — output tokens only
  • cache — cache read hits as % of input tokens
  • api_cost — estimated cost at API rates
  • execution_type - interactive, exec, subagent, or unknown; available through --by execution and custom SQL. Sessions under /.aop/worktrees/ count as subagents even when launched through a headless execution.
  • project_path - exact working directory when the source log provides it
  • token_count_type - exact when the source retained API token metadata, otherwise estimated

For Agy, discovery reads only canonical session logs at ~/.gemini/antigravity-cli/brain/*/.system_generated/logs/transcript_full.jsonl. Compact transcript copies, chunk mirrors, duplicate events, and resumed CONVERSATION_HISTORY replay entries are not counted. When a session retains API usage metadata, those counters are reported exactly. Otherwise, input and output are estimated at four retained characters per token and every affected table total is labeled estimated. Share cards mark estimated costs with ~ and an estimated tool label.

API cost calculation

The api_cost and billable columns use published API pricing. Cache reads are 0.1x the input token price for all three providers:

Input Cache read Cache write Output
Claude Sonnet $3/MTok $0.30/MTok $3.75/MTok $15/MTok
Claude Opus $5/MTok $0.50/MTok $6.25/MTok $25/MTok
GPT-5 $1.25/MTok $0.125/MTok (auto) $10/MTok
Gemini Flash $0.15/MTok $0.0375/MTok (auto) $0.60/MTok
Gemini 2.5 Pro $1.25/MTok $0.125/MTok (auto) $10/MTok
Gemini 3.1 Pro $2/MTok $0.50/MTok (auto) $12/MTok

Sources: Anthropic pricing, OpenAI pricing, Google AI pricing

Environmental impact estimates

The --chart / --share output shows estimated environmental impact per million tokens:

Metric Per 1M tokens Source
Electricity 0.6 kWh Epoch AI, arxiv:2505.09598
Water 1 liter Li & Ren (2023), adjusted for modern models
CO2 90 g Ritchie (2025)

These are rough estimates — actual impact varies 10-100x depending on model, hardware, and data center location. No provider publishes official per-token figures.

Chart colors

Brand colors used in --chart / --share output:

Tool Color Source
Claude Code #d97757 Anthropic brand guidelines
Codex #10a37f OpenAI brand
Gemini #4285f4 Google brand
Agy #a142f4 Distinct Antigravity session color

Requirements

Python 3.13+, DuckDB 1.5+, matplotlib 3.9+.

Tested on Linux, macOS, and Windows (including WSL data auto-discovery).

Release

PyPI publishing uses trusted publishing and only runs for a version tag that matches pyproject.toml. Roll a patch release with:

uv --no-config version --bump patch
uv --no-config lock
uv --no-config run --locked pytest
uv --no-config build --no-sources
git add pyproject.toml uv.lock
git commit -m "Release v$(uv --no-config version --short)"
git tag -a "v$(uv --no-config version --short)" -m "Release v$(uv --no-config version --short)"
git push origin HEAD --follow-tags

Use minor or major instead of patch when appropriate. The tag workflow repeats the locked test and build gates before publishing, so a mismatched tag, stale lockfile, failing test, or build failure cannot reach PyPI.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clanker_analytics-0.3.0.tar.gz (2.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clanker_analytics-0.3.0-py3-none-any.whl (2.6 MB view details)

Uploaded Python 3

File details

Details for the file clanker_analytics-0.3.0.tar.gz.

File metadata

  • Download URL: clanker_analytics-0.3.0.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for clanker_analytics-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c090e31fe2c2027b92cfc6fa48edebcd33bc2822609c5059fd8518cda917dae1
MD5 f7f338ccc326f22848701f98a1aa9660
BLAKE2b-256 9d74bdc1e9e78ab989f5a0e5752b4f78d00cc6a63c1ca47e371d1771e91276a0

See more details on using hashes here.

File details

Details for the file clanker_analytics-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: clanker_analytics-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 2.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for clanker_analytics-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b92391ecf14587a9b82383a422f0266cf114e0268b303fd999c06285ac1f827f
MD5 e8e01a9f55191840564a068adb715a51
BLAKE2b-256 a39de07c81f6be3432b08c0257bb37f1bb0599545c7163d3f7f7905c8f05c946

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page