Skip to main content

tokstats

Keep and combine your Claude Code stats from all your computers and accounts.

Claude Code keeps its usage stats on each computer only, and it deletes session transcripts after 30 days. If you use a laptop, a desktop and a server, or you change from one account to another, your history is split and slowly lost. tokstats copies the transcripts into one archive, combines all hosts, and shows what you delivered: merged PRs, commits, projects, active days, and tokens.

  • Nothing is lost. A SessionEnd hook copies each session into the archive as it ends. Claude Code's 30-day cleanup cannot delete it after that.
  • All hosts in one report. tokstats pull <ssh-host> copies other computers through SSH. Each session counts once, also when two hosts have a copy.
  • Outcomes first. PRs, commits, projects and languages come from the transcripts. tokstats verify-prs checks the PRs on GitHub.
  • A card for your profile or CV. tokstats card writes an SVG with your merged PRs, active days, streak, languages and a 12-month activity graph.
  • Tokens counted once. Claude Code's /usage counts each streamed line of a response, about 2x the real number. tokstats counts each response once (see Why the numbers differ from /usage).
  • Local only. tokstats has no server. It sends nothing anywhere, except PR URLs to GitHub when you run verify-prs.
  • No dependencies. Python 3.9+ standard library.

Example

The card of the author (tokstats card), from a laptop and a Mac mini:

tokstats card: merged PRs, active days, longest streak, tokens, activity graph and languages

The full report (tokstats report --redact, which hides the project names):

tokstats · 2 hosts (laptop, macmini) · 2026-02-13 to 2026-11-27

OUTCOMES
  Merged PRs (verified)  510 in 20 repositories (GitHub: author muradyan, 517 of 517 PRs checked)
  PRs worked on          517 in 20 repositories
  Commits                517
  Projects               17 (9 with 3+ active days)
  Lines changed          +65,115 / -495 (Edit and Write tool calls)
  Languages              Python 34%, JavaScript 21%, Rust 15%, HTML 12%, TypeScript 9%, Shell 7%

ACTIVITY
  Active days    209 (longest streak 72 days, current 72)
  Active time    204 hours (5-minute buckets with activity)
  Sessions       510 (1,303 prompts, 159 subagent runs)
  Tool calls     29,018 (606 test runs)
  Hours (local)  ▁▁▁▁▁▁▁▂▂▆▇▇▇▇█▇▅▄▂▂▄▅▄▂
                 0     6     12    18   23

TOKENS BY MODEL
  model                   input   output  cache read  cache write    total
  claude-opus-5-5        59.49k   19.48M       5.18B      100.98M     5.3B
  claude-fable-5-2        1.44k  674.15k     136.37M        3.07M  140.11M
  claude-fable-5-1        3.85k  145.46k      14.94M      545.85k   15.63M
  claude-haiku-5-5          226  294.55k       2.14M        1.76M     4.2M
  total, transcripts        65k    20.6M       5.33B      106.35M    5.46B
  older days (estimate)                                            ~13.57B
  total                                                            ~19.02B

HOSTS
  host     sessions  active days   tokens  first day   last day    cleanup days
  laptop        456          206  ~13.59B  2026-02-13  2026-11-27          3650
  macmini        54           70   ~5.43B  2026-08-18  2026-11-27          3650

MONTHS
  month    days  sessions  PRs  tokens
  2026-02     1        11    0       -
  2026-03     4         4    0       -
  2026-04    23        54    0       -
  2026-05    21        69    0       -
  2026-06    24        63    0  ~7.24M  █
  2026-07    29        55    0   ~2.7B  ████████████
  2026-08    26       103    0  ~4.14B  ███████████████████
  2026-09    23        37    0  ~4.36B  ████████████████████
  2026-10    31        30  200  ~4.17B  ███████████████████
  2026-11    27        84  317   3.64B  █████████████████

TOP PROJECTS
  project     active days  sessions  PRs   tokens
  project-01           45        33  164    2.32B
  project-02           35        35  315    2.12B
  project-03           15         7   29  234.11M
  project-04           10         3    0   80.29M
  project-05            9         1    9  123.38M
  project-06            6         1    0  479.25M
  project-07            5         1    0    8.75M
  project-08            4         1    0   50.91M

Note: ~ = estimate. Claude Code already deleted the transcripts of 164 days. For these days only the daily totals in stats-cache.json remain: ~13.57B tokens (stats-cache.json counts each streamed line of a response; on 48 days that both sources know, it shows 2.14x the real tokens (median), so tokstats divides by 2.14).
Note: Outcomes, projects, prompts, tool calls and active time come from the archived transcripts only (from 2026-10-03).
Note: API providers by session: Anthropic 97, unknown 3. Accounts: 1 Claude account(s); 22 sessions have no account record (older Claude Code versions and some providers do not write it).

Other formats: --format md (Markdown, for a CV or a GitHub profile) and --format json.

Install

pipx install git+https://github.com/muradyan/tokstats
# or
uv tool install git+https://github.com/muradyan/tokstats
# or
pip install --user git+https://github.com/muradyan/tokstats

Quick start

On each computer where you use Claude Code:

tokstats collect --host-name laptop   # copy this computer's transcripts (the name is saved)
tokstats hook install                 # copy each session again when it ends

On the computer where you want the combined report:

tokstats pull macmini gpu-server      # copy other computers through SSH (names from ~/.ssh/config)
tokstats verify-prs                   # optional: check the PRs on GitHub with the gh CLI
tokstats report                       # the combined report
tokstats card -o card.svg             # the SVG card
tokstats schedule install             # every day: collect, pull all remote hosts, check new PRs
tokstats status                       # the archive of each host, and the data at risk

To show the card on your GitHub profile, commit card.svg to your profile repository (<user>/<user>) and add <img src="card.svg" width="720"> to its README. The card follows the light or dark setting of the viewer.

pull needs only SSH access (key-based) and tar on the remote computer. tokstats does not have to be installed there. Run pull at least every 3 weeks, or set "cleanupPeriodDays" higher in ~/.claude/settings.json on that computer. tokstats status warns you when a host is close to the cleanup.

Commands

Command What it does
tokstats collect [--host-name NAME] [--quiet] Copy new and changed local transcripts into the archive.
tokstats pull SSH_HOST... [--as NAME] Copy new and changed transcripts of remote hosts through SSH, and remember the hosts for sync.
tokstats sync [--no-verify] collect, then pull all remembered hosts, then check new PRs on GitHub.
tokstats schedule install|uninstall|status [--at HH:MM] Run sync every day: launchd on macOS, cron on Linux. The log is ~/.tokstats/sync.log.
tokstats remote list|remove [SSH_HOST] Show or forget the remote hosts of sync. The archive of a forgotten host stays.
tokstats card [-o FILE] [--theme auto|light|dark] [--title TEXT] Write the SVG card.
tokstats report [--format text|md|json] [--days N] [--since D] [--until D] [--host H] [--redact] [-o FILE] Show the combined report.
tokstats verify-prs [--force] Check each PR on GitHub: merged or not, and the author. Needs gh auth login.
tokstats hook install|uninstall|status Add or remove the SessionEnd hook in ~/.claude/settings.json (a backup is kept).
tokstats status Show the archive size, the last copy and the cleanup period of each host.

What the report counts

Metric Source
Merged PRs (verified) PR links in the transcripts, then GitHub: the PR is merged and you are the author.
PRs worked on The pr-link records that Claude Code writes for the PR of a session.
Commits Bash tool calls with git commit.
Test runs Bash tool calls with pytest, npm test, cargo test, go test and similar.
Projects The working folder of each session (worktrees count as their main folder).
Languages The file extensions of Edit and Write tool calls; config and text files are not counted.
Lines changed A line diff of each Edit and MultiEdit call; the lines of each Write call (a second Write of the same file counts the difference only). Changes made through Bash commands (scripts, sed) are not counted.
API provider The format of the response ID: Anthropic, Google Vertex AI (msg_vrtx_) or Amazon Bedrock (msg_bdrk_).
Active days, active time Days and 5-minute periods with at least one prompt or response.
Sessions, prompts, tool calls, subagent runs Records in the transcripts. A prompt is a message that you typed, not a tool result.
Tokens message.usage of each API response, counted once: input, output, cache read, cache write.

Why the numbers differ from /usage

Claude Code streams each API response and writes one JSONL line for each content block (text, thinking, each tool call). Each of these lines repeats the usage of the full response. Claude Code's own stats-cache.json (which /usage shows) counts every line. On the author's data, it shows a median of 2.14x the real tokens, on 48 days where both sources exist.

tokstats keys each response by message.id and requestId and counts it once. For old days whose transcripts Claude Code already deleted, only the daily totals in stats-cache.json remain. tokstats keeps these totals, divides them by the measured ratio, and marks them with ~ as an estimate.

Where the data is

~/.tokstats/
  config.json                                  the name of this host
  archive/<host>/projects/<project>/<session>.jsonl.gz   gzip copies of the transcripts
  archive/<host>/stats-history.json            every daily row of stats-cache.json ever seen
  archive/<host>/manifest.json, host.json      file sizes, cleanup period, last copy
  cache/                                       parsed summaries (safe to delete)
  prs.json                                     results of verify-prs

The archive only adds and updates files. It holds your full transcripts (prompts, code, outputs), so keep it as private as ~/.claude. Set TOKSTATS_HOME to use a different folder, and CLAUDE_CONFIG_DIR if your Claude Code folder is not ~/.claude.

Privacy

  • tokstats reads your local files and the files that you pull through SSH.
  • It sends nothing to any server. verify-prs sends only PR numbers and repository names to GitHub, through your own gh login.
  • The report shows no prompts, no code and no file paths. --redact also hides the project names. The report shows the GitHub login of verified PRs.

Limits

  • Claude Code only, for now. Anthropic does not document the transcript format, so a new Claude Code version can change it. The archive keeps the raw transcripts, so a fixed parser can read them again.
  • Days that only stats-cache.json knows have no projects, PRs or active time.
  • Older Claude Code versions do not write the account record of a session. The report counts these sessions, but cannot name the account.

Other tools cover parts of this. Use the one that fits:

  • ccusage: detailed local token and cost reports for many AI tools. It also counts each response once.
  • CodeBurn: cost by project and task, commits, many AI tools, and device pairing on a local network.
  • tokscale and viberank: public leaderboards, profiles and badges, based on tokens and cost.

What tokstats adds: an archive of the raw transcripts that the 30-day cleanup cannot delete, hosts combined through plain SSH, merged PRs verified on GitHub, and a card that shows outcomes, not only tokens. It needs no server and no dependencies.

Roadmap

  1. v0 (this version): a local CLI. It combines hosts through SSH, keeps an archive, writes the report and the card, and syncs every day.
  2. v1: an optional server with GitHub sign-in, a host link for each computer, verified PRs, and a public profile page and SVG badge for a CV or a README. Only summaries go to the server, never transcripts.
  3. v2: more AI tools: Codex CLI, Gemini CLI, Cursor and other editors.

Development

python3 -m venv .venv && .venv/bin/pip install -e . pytest
.venv/bin/pytest -q

License

MIT

Metadata

Release files for tokstats 0.2.0

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

Source distribution (sdist)

Source distribution for tokstats 0.2.0
File Size Uploaded Provenance Actions
tokstats-0.2.0.tar.gz 40.9 kB With provenance Details for tokstats-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 78.1 kB

Release files / tokstats-0.2.0.tar.gz

Download URL tokstats-0.2.0.tar.gz
Size 40.9 kB
Tags Source
SHA-256 checksum
How to use checksums
93416bfcb3ad2623b5aa69deb7cafe170bc0c2bac9a6f4da366031552f97f6f6
BLAKE2b-256 checksum
How to use checksums
fc2a48a05df93c82a004cd7e38563f3d3b2eeac1e27e049e3fae56a65f2278a6
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 28, 2026.

Transparency log

Release files / tokstats-0.2.0-py3-none-any.whl

Download URL tokstats-0.2.0-py3-none-any.whl
Size 37.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5be7c5b9bd46923f0dc95968b09c2991588b40e1f43edf0c02e3d61cae62f0b6
BLAKE2b-256 checksum
How to use checksums
7282908bf2a2b763bfa99f84df7a7929690d4c4c94760dc4cbc90f6642ab49d8
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 28, 2026.

Transparency log

Security for tokstats 0.2.0

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 tokstats-0.2.0.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 28, 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

0.2.0 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