Skip to main content

tokstat

PyPI Python License Downloads

One command to see what your AI coding assistants really cost you — in tokens, money, and carbon — and how they work internally: prompts, responses, tool calls, and the internal prompts agents send themselves.

tokstat scans the local data of every assistant you use — Claude Code, Codex, Cursor, Kiro, GitHub Copilot, Copilot CLI, Gemini CLI, Antigravity, opencode, pi, Qwen Code, plus claude.ai / ChatGPT web exports — and turns it into clear, color-coded terminal tables: cost with live LiteLLM pricing, an electricity & carbon footprint, a browsable history of every prompt, response and tool call to audit sessions and projects, and plan & optimization tips. Zero dependencies, nothing leaves your machine.

pip install tokstat     # Python 3.7+, no dependencies
tokstat                 # aggregated overview across all tools

Accuracy. On our test account, tokstat's Claude Code estimate matched Anthropic billing within ~5% over 30 days. It varies by tool: Claude Code, Codex, Antigravity, Gemini CLI, opencode, pi, Qwen Code and the Copilot CLI read exact token counts; Cursor reads exact counts where recorded and flags the rest ⚠ no data; Kiro and GitHub Copilot expose no token counts (activity only); web exports are estimated from text length. Estimates only — see Tools for per-tool accuracy.

What it helps you do

  • 💰 Estimate cost — spend per tool, model, project and session, with live pricing. → --total, --plan
  • 🌱 Estimate impact — electricity (kWh) and carbon (CO₂e) footprint of your usage. → --impact
  • 🔎 Audit sessions & projects — browse the full prompt/response history and tool-call timeline, including the prompts agents send themselves (sub-agent hand-offs, inter-session messages, the tool loop) — scoped to any conversation or repo. → --prompts, --tool-use, --export
  • 🛠️ Optimize — technical anomaly detection and per-provider plan recommendations. → --anomalies, --plan

Quickstart

tokstat                              # overview: by period, project, model
tokstat --period "30 days"           # pick a window (default: today)
tokstat --prompts                    # per-exchange detail (tokens, tools, cost)
tokstat --total --tool codex         # compact totals for one tool
tokstat --impact                     # energy & CO₂ estimate
tokstat --watch                      # live, refreshing overview

Scope any view with --tool, --project, --session and --period — e.g. tokstat --impact --session 019f6a75 or tokstat --prompts --project tokstat. See Filters.

Supported tools

tokstat aggregates everything; each assistant also has its own *-token-usage command.

Agent Command Tokens
Claude Code claude-token-usage ✓ exact
Codex (OpenAI) codex-token-usage ✓ exact
Gemini CLI gemini-token-usage ✓ exact
opencode opencode-token-usage ✓ exact
pi pi-token-usage ✓ exact
Qwen Code qwen-token-usage ✓ exact
Antigravity antigravity-token-usage ✓ exact
Cursor cursor-token-usage exact / ⚠ no data
Kiro kiro-token-usage activity only
GitHub Copilot (Chat) copilot-token-usage activity only
GitHub Copilot CLI copilot-cli-token-usage ✓ exact
claude.ai / ChatGPT (web) claude-web-token-usage / chatgpt-web-token-usage ~ estimated (import)

Full table, accuracy notes and the web-export workflow → docs/tools.md.

Documentation

  • Tools — every supported assistant, data sources, accuracy, web exports.
  • Modes — overview, --prompts, --tool-use, --anomalies, --activity, --total, --plan, --export, --watch.
  • Filters — --period, --tool, --project, --session.
  • Impact — the --impact energy & CO₂ estimate (EcoLogits), in depth.
  • Reference — pricing, caches, diagnostics (TOKSTAT_TIMING).
  • Changelog — release history.

Credits

Environmental-impact estimates (--impact) port the usage-phase energy formula and constants of EcoLogits (MPL-2.0) and use its model database, fetched and cached locally.

License

tokstat is MIT (see LICENSE), except src/tokstat/_ecologits.py, which is licensed under the MPL-2.0 because it ports MPL-2.0 source from EcoLogits. The MPL-2.0 is a file-level copyleft and governs only that one file; everything else is MIT. See NOTICE for details.

Metadata

Release files for tokstat 1.32.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tokstat 1.32.1
File Size Uploaded Provenance Actions
tokstat-1.32.1.tar.gz 101.7 kB With provenance Details for tokstat-1.32.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tokstat 1.32.1
File Interpreter ABI Platform Actions
tokstat-1.32.1-py3-none-any.whl Python 3 none any Details for tokstat-1.32.1-py3-none-any.whl

Total release size: 237.9 kB

Release files / tokstat-1.32.1.tar.gz

Download URL tokstat-1.32.1.tar.gz
Size 101.7 kB
Tags Source
SHA-256 checksum
How to use checksums
12bffd59107f7978d52c94a8271f59904606f8cec0ca04b78982af0fe25b5eb6
BLAKE2b-256 checksum
How to use checksums
6050bd10923681ec161b390d4ad67abed56b8b9115b1b8b4107a801882c4eb90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / tokstat-1.32.1-py3-none-any.whl

Download URL tokstat-1.32.1-py3-none-any.whl
Size 136.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6ff23f17e2a50a7d5a1f2567340489d0b99f39eb98ac6985dec72bd3910877f
BLAKE2b-256 checksum
How to use checksums
c5d5073b6b5bc81189b279a73e6334f6d1440d68e4236d68e1f83ed4214a5856
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for tokstat 1.32.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tokstat-1.32.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.32.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page