Skip to main content

AI coding tool token analytics powered by DuckDB

Project description

clanker-analytics

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

Supports Claude Code, Codex, and Gemini CLI.

Install

uv tool install clanker-analytics

Or run without installing:

uvx clanker-analytics

Usage

clanker-analytics                        # ranked by project (default)
clanker-analytics --since 24h            # last 24 hours (also: 7d, 2w, 2026-03-01)
clanker-analytics --by date              # daily totals
clanker-analytics --by model             # per-model breakdown
clanker-analytics --by session           # per-session breakdown
clanker-analytics --tool claude          # Claude Code only
clanker-analytics --tool codex           # Codex only
clanker-analytics --tool gemini          # Gemini CLI only
clanker-analytics --chart                # generate PNG chart
clanker-analytics --share                # generate chart + open X compose
clanker-analytics --refresh              # force cache rebuild
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) and auto-invalidated when source files change.

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

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 2.5 Pro $1.25/MTok $0.315/MTok (auto) $10/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

Requirements

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

Project details


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.2.0.tar.gz (2.6 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.2.0-py3-none-any.whl (2.6 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clanker_analytics-0.2.0.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clanker_analytics-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a342816319fd67eb2553562d88e053c2999c436d06ead2e81e8bd7a7cfa24496
MD5 d4f0ef4a6fbee7dae0f9c752f1251fd9
BLAKE2b-256 12ea18a1781f5bf4873de915b6cae2397374cf6b11da4671651108d5ffc2e92b

See more details on using hashes here.

Provenance

The following attestation bundles were made for clanker_analytics-0.2.0.tar.gz:

Publisher: publish.yml on wakamex/clanker-analytics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for clanker_analytics-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 047389b2fc541451fb661b2f55a41f967e953f95fd4af0bcf9d6bce87a3ed2ac
MD5 a34add895e3bfe611977504c755ad28f
BLAKE2b-256 16273d2b297baf9dc71c7e6c882f5729606eb96e07714f2926fde1013af109c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for clanker_analytics-0.2.0-py3-none-any.whl:

Publisher: publish.yml on wakamex/clanker-analytics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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