tokstats 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tokstats-0.2.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Arthur Muradyan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,270 @@
1
+ Metadata-Version: 2.4
2
+ Name: tokstats
3
+ Version: 0.2.0
4
+ Summary: Keep and combine your Claude Code stats from all your computers and accounts: merged PRs, active days, exact tokens, and an SVG card.
5
+ Author: Arthur Muradyan
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/muradyan/tokstats
8
+ Keywords: claude,claude-code,ai,usage,statistics,tokens,developer-tools
9
+ Classifier: Topic :: Software Development
10
+ Classifier: Operating System :: MacOS
11
+ Classifier: Operating System :: POSIX :: Linux
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Environment :: Console
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Dynamic: license-file
18
+
19
+ # tokstats
20
+
21
+ Keep and combine your Claude Code stats from all your computers and accounts.
22
+
23
+ Claude Code keeps its usage stats on each computer only, and it deletes session
24
+ transcripts after 30 days. If you use a laptop, a desktop and a server, or you
25
+ change from one account to another, your history is split and slowly lost.
26
+ tokstats copies the transcripts into one archive, combines all hosts, and shows
27
+ what you delivered: merged PRs, commits, projects, active days, and tokens.
28
+
29
+ - **Nothing is lost.** A `SessionEnd` hook copies each session into the archive
30
+ as it ends. Claude Code's 30-day cleanup cannot delete it after that.
31
+ - **All hosts in one report.** `tokstats pull <ssh-host>` copies other computers
32
+ through SSH. Each session counts once, also when two hosts have a copy.
33
+ - **Outcomes first.** PRs, commits, projects and languages come from the
34
+ transcripts. `tokstats verify-prs` checks the PRs on GitHub.
35
+ - **A card for your profile or CV.** `tokstats card` writes an SVG with your
36
+ merged PRs, active days, streak, languages and a 12-month activity graph.
37
+ - **Tokens counted once.** Claude Code's `/usage` counts each streamed line of a
38
+ response, about 2x the real number. tokstats counts each response once (see
39
+ [Why the numbers differ from /usage](#why-the-numbers-differ-from-usage)).
40
+ - **Local only.** tokstats has no server. It sends nothing anywhere, except
41
+ PR URLs to GitHub when you run `verify-prs`.
42
+ - **No dependencies.** Python 3.9+ standard library.
43
+
44
+ ## Example
45
+
46
+ The card of the author (`tokstats card`), from a laptop and a Mac mini:
47
+
48
+ <img src="docs/card.svg" alt="tokstats card: merged PRs, active days, longest streak, tokens, activity graph and languages" width="720">
49
+
50
+ The full report (`tokstats report --redact`, which hides the project names):
51
+
52
+ ```text
53
+ tokstats · 2 hosts (laptop, macmini) · 2026-02-13 to 2026-11-27
54
+
55
+ OUTCOMES
56
+ Merged PRs (verified) 510 in 20 repositories (GitHub: author muradyan, 517 of 517 PRs checked)
57
+ PRs worked on 517 in 20 repositories
58
+ Commits 517
59
+ Projects 17 (9 with 3+ active days)
60
+ Lines changed +65,115 / -495 (Edit and Write tool calls)
61
+ Languages Python 34%, JavaScript 21%, Rust 15%, HTML 12%, TypeScript 9%, Shell 7%
62
+
63
+ ACTIVITY
64
+ Active days 209 (longest streak 72 days, current 72)
65
+ Active time 204 hours (5-minute buckets with activity)
66
+ Sessions 510 (1,303 prompts, 159 subagent runs)
67
+ Tool calls 29,018 (606 test runs)
68
+ Hours (local) ▁▁▁▁▁▁▁▂▂▆▇▇▇▇█▇▅▄▂▂▄▅▄▂
69
+ 0 6 12 18 23
70
+
71
+ TOKENS BY MODEL
72
+ model input output cache read cache write total
73
+ claude-opus-5-5 59.49k 19.48M 5.18B 100.98M 5.3B
74
+ claude-fable-5-2 1.44k 674.15k 136.37M 3.07M 140.11M
75
+ claude-fable-5-1 3.85k 145.46k 14.94M 545.85k 15.63M
76
+ claude-haiku-5-5 226 294.55k 2.14M 1.76M 4.2M
77
+ total, transcripts 65k 20.6M 5.33B 106.35M 5.46B
78
+ older days (estimate) ~13.57B
79
+ total ~19.02B
80
+
81
+ HOSTS
82
+ host sessions active days tokens first day last day cleanup days
83
+ laptop 456 206 ~13.59B 2026-02-13 2026-11-27 3650
84
+ macmini 54 70 ~5.43B 2026-08-18 2026-11-27 3650
85
+
86
+ MONTHS
87
+ month days sessions PRs tokens
88
+ 2026-02 1 11 0 -
89
+ 2026-03 4 4 0 -
90
+ 2026-04 23 54 0 -
91
+ 2026-05 21 69 0 -
92
+ 2026-06 24 63 0 ~7.24M █
93
+ 2026-07 29 55 0 ~2.7B ████████████
94
+ 2026-08 26 103 0 ~4.14B ███████████████████
95
+ 2026-09 23 37 0 ~4.36B ████████████████████
96
+ 2026-10 31 30 200 ~4.17B ███████████████████
97
+ 2026-11 27 84 317 3.64B █████████████████
98
+
99
+ TOP PROJECTS
100
+ project active days sessions PRs tokens
101
+ project-01 45 33 164 2.32B
102
+ project-02 35 35 315 2.12B
103
+ project-03 15 7 29 234.11M
104
+ project-04 10 3 0 80.29M
105
+ project-05 9 1 9 123.38M
106
+ project-06 6 1 0 479.25M
107
+ project-07 5 1 0 8.75M
108
+ project-08 4 1 0 50.91M
109
+
110
+ 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).
111
+ Note: Outcomes, projects, prompts, tool calls and active time come from the archived transcripts only (from 2026-10-03).
112
+ 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).
113
+ ```
114
+
115
+ Other formats: `--format md` (Markdown, for a CV or a GitHub profile) and
116
+ `--format json`.
117
+
118
+ ## Install
119
+
120
+ ```sh
121
+ pipx install git+https://github.com/muradyan/tokstats
122
+ # or
123
+ uv tool install git+https://github.com/muradyan/tokstats
124
+ # or
125
+ pip install --user git+https://github.com/muradyan/tokstats
126
+ ```
127
+
128
+ ## Quick start
129
+
130
+ On each computer where you use Claude Code:
131
+
132
+ ```sh
133
+ tokstats collect --host-name laptop # copy this computer's transcripts (the name is saved)
134
+ tokstats hook install # copy each session again when it ends
135
+ ```
136
+
137
+ On the computer where you want the combined report:
138
+
139
+ ```sh
140
+ tokstats pull macmini gpu-server # copy other computers through SSH (names from ~/.ssh/config)
141
+ tokstats verify-prs # optional: check the PRs on GitHub with the gh CLI
142
+ tokstats report # the combined report
143
+ tokstats card -o card.svg # the SVG card
144
+ tokstats schedule install # every day: collect, pull all remote hosts, check new PRs
145
+ tokstats status # the archive of each host, and the data at risk
146
+ ```
147
+
148
+ To show the card on your GitHub profile, commit `card.svg` to your profile
149
+ repository (`<user>/<user>`) and add `<img src="card.svg" width="720">` to its
150
+ README. The card follows the light or dark setting of the viewer.
151
+
152
+ `pull` needs only SSH access (key-based) and `tar` on the remote computer.
153
+ tokstats does not have to be installed there. Run `pull` at least every 3 weeks,
154
+ or set `"cleanupPeriodDays"` higher in `~/.claude/settings.json` on that
155
+ computer. `tokstats status` warns you when a host is close to the cleanup.
156
+
157
+ ## Commands
158
+
159
+ | Command | What it does |
160
+ | --- | --- |
161
+ | `tokstats collect [--host-name NAME] [--quiet]` | Copy new and changed local transcripts into the archive. |
162
+ | `tokstats pull SSH_HOST... [--as NAME]` | Copy new and changed transcripts of remote hosts through SSH, and remember the hosts for `sync`. |
163
+ | `tokstats sync [--no-verify]` | `collect`, then `pull` all remembered hosts, then check new PRs on GitHub. |
164
+ | `tokstats schedule install\|uninstall\|status [--at HH:MM]` | Run `sync` every day: `launchd` on macOS, `cron` on Linux. The log is `~/.tokstats/sync.log`. |
165
+ | `tokstats remote list\|remove [SSH_HOST]` | Show or forget the remote hosts of `sync`. The archive of a forgotten host stays. |
166
+ | `tokstats card [-o FILE] [--theme auto\|light\|dark] [--title TEXT]` | Write the SVG card. |
167
+ | `tokstats report [--format text\|md\|json] [--days N] [--since D] [--until D] [--host H] [--redact] [-o FILE]` | Show the combined report. |
168
+ | `tokstats verify-prs [--force]` | Check each PR on GitHub: merged or not, and the author. Needs `gh auth login`. |
169
+ | `tokstats hook install\|uninstall\|status` | Add or remove the `SessionEnd` hook in `~/.claude/settings.json` (a backup is kept). |
170
+ | `tokstats status` | Show the archive size, the last copy and the cleanup period of each host. |
171
+
172
+ ## What the report counts
173
+
174
+ | Metric | Source |
175
+ | --- | --- |
176
+ | Merged PRs (verified) | PR links in the transcripts, then GitHub: the PR is merged and you are the author. |
177
+ | PRs worked on | The `pr-link` records that Claude Code writes for the PR of a session. |
178
+ | Commits | Bash tool calls with `git commit`. |
179
+ | Test runs | Bash tool calls with `pytest`, `npm test`, `cargo test`, `go test` and similar. |
180
+ | Projects | The working folder of each session (worktrees count as their main folder). |
181
+ | Languages | The file extensions of `Edit` and `Write` tool calls; config and text files are not counted. |
182
+ | 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. |
183
+ | API provider | The format of the response ID: Anthropic, Google Vertex AI (`msg_vrtx_`) or Amazon Bedrock (`msg_bdrk_`). |
184
+ | Active days, active time | Days and 5-minute periods with at least one prompt or response. |
185
+ | Sessions, prompts, tool calls, subagent runs | Records in the transcripts. A prompt is a message that you typed, not a tool result. |
186
+ | Tokens | `message.usage` of each API response, counted once: input, output, cache read, cache write. |
187
+
188
+ ## Why the numbers differ from /usage
189
+
190
+ Claude Code streams each API response and writes one JSONL line for each content
191
+ block (text, thinking, each tool call). Each of these lines repeats the usage of
192
+ the full response. Claude Code's own `stats-cache.json` (which `/usage` shows)
193
+ counts every line. On the author's data, it shows a median of 2.14x the real
194
+ tokens, on 48 days where both sources exist.
195
+
196
+ tokstats keys each response by `message.id` and `requestId` and counts it once.
197
+ For old days whose transcripts Claude Code already deleted, only the daily totals
198
+ in `stats-cache.json` remain. tokstats keeps these totals, divides them by the
199
+ measured ratio, and marks them with `~` as an estimate.
200
+
201
+ ## Where the data is
202
+
203
+ ```text
204
+ ~/.tokstats/
205
+ config.json the name of this host
206
+ archive/<host>/projects/<project>/<session>.jsonl.gz gzip copies of the transcripts
207
+ archive/<host>/stats-history.json every daily row of stats-cache.json ever seen
208
+ archive/<host>/manifest.json, host.json file sizes, cleanup period, last copy
209
+ cache/ parsed summaries (safe to delete)
210
+ prs.json results of verify-prs
211
+ ```
212
+
213
+ The archive only adds and updates files. It holds your full transcripts
214
+ (prompts, code, outputs), so keep it as private as `~/.claude`. Set
215
+ `TOKSTATS_HOME` to use a different folder, and `CLAUDE_CONFIG_DIR` if your
216
+ Claude Code folder is not `~/.claude`.
217
+
218
+ ## Privacy
219
+
220
+ - tokstats reads your local files and the files that you pull through SSH.
221
+ - It sends nothing to any server. `verify-prs` sends only PR numbers and
222
+ repository names to GitHub, through your own `gh` login.
223
+ - The report shows no prompts, no code and no file paths. `--redact` also hides
224
+ the project names. The report shows the GitHub login of verified PRs.
225
+
226
+ ## Limits
227
+
228
+ - Claude Code only, for now. Anthropic does not document the transcript format,
229
+ so a new Claude Code version can change it. The archive keeps the raw
230
+ transcripts, so a fixed parser can read them again.
231
+ - Days that only `stats-cache.json` knows have no projects, PRs or active time.
232
+ - Older Claude Code versions do not write the account record of a session. The
233
+ report counts these sessions, but cannot name the account.
234
+
235
+ ## Related tools
236
+
237
+ Other tools cover parts of this. Use the one that fits:
238
+
239
+ - [ccusage](https://github.com/ccusage/ccusage): detailed local token and cost
240
+ reports for many AI tools. It also counts each response once.
241
+ - [CodeBurn](https://github.com/getagentseal/codeburn): cost by project and
242
+ task, commits, many AI tools, and device pairing on a local network.
243
+ - [tokscale](https://github.com/junhoyeo/tokscale) and
244
+ [viberank](https://github.com/sculptdotfun/viberank): public leaderboards,
245
+ profiles and badges, based on tokens and cost.
246
+
247
+ What tokstats adds: an archive of the raw transcripts that the 30-day cleanup
248
+ cannot delete, hosts combined through plain SSH, merged PRs verified on GitHub,
249
+ and a card that shows outcomes, not only tokens. It needs no server and no
250
+ dependencies.
251
+
252
+ ## Roadmap
253
+
254
+ 1. **v0 (this version):** a local CLI. It combines hosts through SSH, keeps an
255
+ archive, writes the report and the card, and syncs every day.
256
+ 2. **v1:** an optional server with GitHub sign-in, a host link for each computer,
257
+ verified PRs, and a public profile page and SVG badge for a CV or a README.
258
+ Only summaries go to the server, never transcripts.
259
+ 3. **v2:** more AI tools: Codex CLI, Gemini CLI, Cursor and other editors.
260
+
261
+ ## Development
262
+
263
+ ```sh
264
+ python3 -m venv .venv && .venv/bin/pip install -e . pytest
265
+ .venv/bin/pytest -q
266
+ ```
267
+
268
+ ## License
269
+
270
+ MIT
@@ -0,0 +1,252 @@
1
+ # tokstats
2
+
3
+ Keep and combine your Claude Code stats from all your computers and accounts.
4
+
5
+ Claude Code keeps its usage stats on each computer only, and it deletes session
6
+ transcripts after 30 days. If you use a laptop, a desktop and a server, or you
7
+ change from one account to another, your history is split and slowly lost.
8
+ tokstats copies the transcripts into one archive, combines all hosts, and shows
9
+ what you delivered: merged PRs, commits, projects, active days, and tokens.
10
+
11
+ - **Nothing is lost.** A `SessionEnd` hook copies each session into the archive
12
+ as it ends. Claude Code's 30-day cleanup cannot delete it after that.
13
+ - **All hosts in one report.** `tokstats pull <ssh-host>` copies other computers
14
+ through SSH. Each session counts once, also when two hosts have a copy.
15
+ - **Outcomes first.** PRs, commits, projects and languages come from the
16
+ transcripts. `tokstats verify-prs` checks the PRs on GitHub.
17
+ - **A card for your profile or CV.** `tokstats card` writes an SVG with your
18
+ merged PRs, active days, streak, languages and a 12-month activity graph.
19
+ - **Tokens counted once.** Claude Code's `/usage` counts each streamed line of a
20
+ response, about 2x the real number. tokstats counts each response once (see
21
+ [Why the numbers differ from /usage](#why-the-numbers-differ-from-usage)).
22
+ - **Local only.** tokstats has no server. It sends nothing anywhere, except
23
+ PR URLs to GitHub when you run `verify-prs`.
24
+ - **No dependencies.** Python 3.9+ standard library.
25
+
26
+ ## Example
27
+
28
+ The card of the author (`tokstats card`), from a laptop and a Mac mini:
29
+
30
+ <img src="docs/card.svg" alt="tokstats card: merged PRs, active days, longest streak, tokens, activity graph and languages" width="720">
31
+
32
+ The full report (`tokstats report --redact`, which hides the project names):
33
+
34
+ ```text
35
+ tokstats · 2 hosts (laptop, macmini) · 2026-02-13 to 2026-11-27
36
+
37
+ OUTCOMES
38
+ Merged PRs (verified) 510 in 20 repositories (GitHub: author muradyan, 517 of 517 PRs checked)
39
+ PRs worked on 517 in 20 repositories
40
+ Commits 517
41
+ Projects 17 (9 with 3+ active days)
42
+ Lines changed +65,115 / -495 (Edit and Write tool calls)
43
+ Languages Python 34%, JavaScript 21%, Rust 15%, HTML 12%, TypeScript 9%, Shell 7%
44
+
45
+ ACTIVITY
46
+ Active days 209 (longest streak 72 days, current 72)
47
+ Active time 204 hours (5-minute buckets with activity)
48
+ Sessions 510 (1,303 prompts, 159 subagent runs)
49
+ Tool calls 29,018 (606 test runs)
50
+ Hours (local) ▁▁▁▁▁▁▁▂▂▆▇▇▇▇█▇▅▄▂▂▄▅▄▂
51
+ 0 6 12 18 23
52
+
53
+ TOKENS BY MODEL
54
+ model input output cache read cache write total
55
+ claude-opus-5-5 59.49k 19.48M 5.18B 100.98M 5.3B
56
+ claude-fable-5-2 1.44k 674.15k 136.37M 3.07M 140.11M
57
+ claude-fable-5-1 3.85k 145.46k 14.94M 545.85k 15.63M
58
+ claude-haiku-5-5 226 294.55k 2.14M 1.76M 4.2M
59
+ total, transcripts 65k 20.6M 5.33B 106.35M 5.46B
60
+ older days (estimate) ~13.57B
61
+ total ~19.02B
62
+
63
+ HOSTS
64
+ host sessions active days tokens first day last day cleanup days
65
+ laptop 456 206 ~13.59B 2026-02-13 2026-11-27 3650
66
+ macmini 54 70 ~5.43B 2026-08-18 2026-11-27 3650
67
+
68
+ MONTHS
69
+ month days sessions PRs tokens
70
+ 2026-02 1 11 0 -
71
+ 2026-03 4 4 0 -
72
+ 2026-04 23 54 0 -
73
+ 2026-05 21 69 0 -
74
+ 2026-06 24 63 0 ~7.24M █
75
+ 2026-07 29 55 0 ~2.7B ████████████
76
+ 2026-08 26 103 0 ~4.14B ███████████████████
77
+ 2026-09 23 37 0 ~4.36B ████████████████████
78
+ 2026-10 31 30 200 ~4.17B ███████████████████
79
+ 2026-11 27 84 317 3.64B █████████████████
80
+
81
+ TOP PROJECTS
82
+ project active days sessions PRs tokens
83
+ project-01 45 33 164 2.32B
84
+ project-02 35 35 315 2.12B
85
+ project-03 15 7 29 234.11M
86
+ project-04 10 3 0 80.29M
87
+ project-05 9 1 9 123.38M
88
+ project-06 6 1 0 479.25M
89
+ project-07 5 1 0 8.75M
90
+ project-08 4 1 0 50.91M
91
+
92
+ 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).
93
+ Note: Outcomes, projects, prompts, tool calls and active time come from the archived transcripts only (from 2026-10-03).
94
+ 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).
95
+ ```
96
+
97
+ Other formats: `--format md` (Markdown, for a CV or a GitHub profile) and
98
+ `--format json`.
99
+
100
+ ## Install
101
+
102
+ ```sh
103
+ pipx install git+https://github.com/muradyan/tokstats
104
+ # or
105
+ uv tool install git+https://github.com/muradyan/tokstats
106
+ # or
107
+ pip install --user git+https://github.com/muradyan/tokstats
108
+ ```
109
+
110
+ ## Quick start
111
+
112
+ On each computer where you use Claude Code:
113
+
114
+ ```sh
115
+ tokstats collect --host-name laptop # copy this computer's transcripts (the name is saved)
116
+ tokstats hook install # copy each session again when it ends
117
+ ```
118
+
119
+ On the computer where you want the combined report:
120
+
121
+ ```sh
122
+ tokstats pull macmini gpu-server # copy other computers through SSH (names from ~/.ssh/config)
123
+ tokstats verify-prs # optional: check the PRs on GitHub with the gh CLI
124
+ tokstats report # the combined report
125
+ tokstats card -o card.svg # the SVG card
126
+ tokstats schedule install # every day: collect, pull all remote hosts, check new PRs
127
+ tokstats status # the archive of each host, and the data at risk
128
+ ```
129
+
130
+ To show the card on your GitHub profile, commit `card.svg` to your profile
131
+ repository (`<user>/<user>`) and add `<img src="card.svg" width="720">` to its
132
+ README. The card follows the light or dark setting of the viewer.
133
+
134
+ `pull` needs only SSH access (key-based) and `tar` on the remote computer.
135
+ tokstats does not have to be installed there. Run `pull` at least every 3 weeks,
136
+ or set `"cleanupPeriodDays"` higher in `~/.claude/settings.json` on that
137
+ computer. `tokstats status` warns you when a host is close to the cleanup.
138
+
139
+ ## Commands
140
+
141
+ | Command | What it does |
142
+ | --- | --- |
143
+ | `tokstats collect [--host-name NAME] [--quiet]` | Copy new and changed local transcripts into the archive. |
144
+ | `tokstats pull SSH_HOST... [--as NAME]` | Copy new and changed transcripts of remote hosts through SSH, and remember the hosts for `sync`. |
145
+ | `tokstats sync [--no-verify]` | `collect`, then `pull` all remembered hosts, then check new PRs on GitHub. |
146
+ | `tokstats schedule install\|uninstall\|status [--at HH:MM]` | Run `sync` every day: `launchd` on macOS, `cron` on Linux. The log is `~/.tokstats/sync.log`. |
147
+ | `tokstats remote list\|remove [SSH_HOST]` | Show or forget the remote hosts of `sync`. The archive of a forgotten host stays. |
148
+ | `tokstats card [-o FILE] [--theme auto\|light\|dark] [--title TEXT]` | Write the SVG card. |
149
+ | `tokstats report [--format text\|md\|json] [--days N] [--since D] [--until D] [--host H] [--redact] [-o FILE]` | Show the combined report. |
150
+ | `tokstats verify-prs [--force]` | Check each PR on GitHub: merged or not, and the author. Needs `gh auth login`. |
151
+ | `tokstats hook install\|uninstall\|status` | Add or remove the `SessionEnd` hook in `~/.claude/settings.json` (a backup is kept). |
152
+ | `tokstats status` | Show the archive size, the last copy and the cleanup period of each host. |
153
+
154
+ ## What the report counts
155
+
156
+ | Metric | Source |
157
+ | --- | --- |
158
+ | Merged PRs (verified) | PR links in the transcripts, then GitHub: the PR is merged and you are the author. |
159
+ | PRs worked on | The `pr-link` records that Claude Code writes for the PR of a session. |
160
+ | Commits | Bash tool calls with `git commit`. |
161
+ | Test runs | Bash tool calls with `pytest`, `npm test`, `cargo test`, `go test` and similar. |
162
+ | Projects | The working folder of each session (worktrees count as their main folder). |
163
+ | Languages | The file extensions of `Edit` and `Write` tool calls; config and text files are not counted. |
164
+ | 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. |
165
+ | API provider | The format of the response ID: Anthropic, Google Vertex AI (`msg_vrtx_`) or Amazon Bedrock (`msg_bdrk_`). |
166
+ | Active days, active time | Days and 5-minute periods with at least one prompt or response. |
167
+ | Sessions, prompts, tool calls, subagent runs | Records in the transcripts. A prompt is a message that you typed, not a tool result. |
168
+ | Tokens | `message.usage` of each API response, counted once: input, output, cache read, cache write. |
169
+
170
+ ## Why the numbers differ from /usage
171
+
172
+ Claude Code streams each API response and writes one JSONL line for each content
173
+ block (text, thinking, each tool call). Each of these lines repeats the usage of
174
+ the full response. Claude Code's own `stats-cache.json` (which `/usage` shows)
175
+ counts every line. On the author's data, it shows a median of 2.14x the real
176
+ tokens, on 48 days where both sources exist.
177
+
178
+ tokstats keys each response by `message.id` and `requestId` and counts it once.
179
+ For old days whose transcripts Claude Code already deleted, only the daily totals
180
+ in `stats-cache.json` remain. tokstats keeps these totals, divides them by the
181
+ measured ratio, and marks them with `~` as an estimate.
182
+
183
+ ## Where the data is
184
+
185
+ ```text
186
+ ~/.tokstats/
187
+ config.json the name of this host
188
+ archive/<host>/projects/<project>/<session>.jsonl.gz gzip copies of the transcripts
189
+ archive/<host>/stats-history.json every daily row of stats-cache.json ever seen
190
+ archive/<host>/manifest.json, host.json file sizes, cleanup period, last copy
191
+ cache/ parsed summaries (safe to delete)
192
+ prs.json results of verify-prs
193
+ ```
194
+
195
+ The archive only adds and updates files. It holds your full transcripts
196
+ (prompts, code, outputs), so keep it as private as `~/.claude`. Set
197
+ `TOKSTATS_HOME` to use a different folder, and `CLAUDE_CONFIG_DIR` if your
198
+ Claude Code folder is not `~/.claude`.
199
+
200
+ ## Privacy
201
+
202
+ - tokstats reads your local files and the files that you pull through SSH.
203
+ - It sends nothing to any server. `verify-prs` sends only PR numbers and
204
+ repository names to GitHub, through your own `gh` login.
205
+ - The report shows no prompts, no code and no file paths. `--redact` also hides
206
+ the project names. The report shows the GitHub login of verified PRs.
207
+
208
+ ## Limits
209
+
210
+ - Claude Code only, for now. Anthropic does not document the transcript format,
211
+ so a new Claude Code version can change it. The archive keeps the raw
212
+ transcripts, so a fixed parser can read them again.
213
+ - Days that only `stats-cache.json` knows have no projects, PRs or active time.
214
+ - Older Claude Code versions do not write the account record of a session. The
215
+ report counts these sessions, but cannot name the account.
216
+
217
+ ## Related tools
218
+
219
+ Other tools cover parts of this. Use the one that fits:
220
+
221
+ - [ccusage](https://github.com/ccusage/ccusage): detailed local token and cost
222
+ reports for many AI tools. It also counts each response once.
223
+ - [CodeBurn](https://github.com/getagentseal/codeburn): cost by project and
224
+ task, commits, many AI tools, and device pairing on a local network.
225
+ - [tokscale](https://github.com/junhoyeo/tokscale) and
226
+ [viberank](https://github.com/sculptdotfun/viberank): public leaderboards,
227
+ profiles and badges, based on tokens and cost.
228
+
229
+ What tokstats adds: an archive of the raw transcripts that the 30-day cleanup
230
+ cannot delete, hosts combined through plain SSH, merged PRs verified on GitHub,
231
+ and a card that shows outcomes, not only tokens. It needs no server and no
232
+ dependencies.
233
+
234
+ ## Roadmap
235
+
236
+ 1. **v0 (this version):** a local CLI. It combines hosts through SSH, keeps an
237
+ archive, writes the report and the card, and syncs every day.
238
+ 2. **v1:** an optional server with GitHub sign-in, a host link for each computer,
239
+ verified PRs, and a public profile page and SVG badge for a CV or a README.
240
+ Only summaries go to the server, never transcripts.
241
+ 3. **v2:** more AI tools: Codex CLI, Gemini CLI, Cursor and other editors.
242
+
243
+ ## Development
244
+
245
+ ```sh
246
+ python3 -m venv .venv && .venv/bin/pip install -e . pytest
247
+ .venv/bin/pytest -q
248
+ ```
249
+
250
+ ## License
251
+
252
+ MIT
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tokstats"
7
+ version = "0.2.0"
8
+ description = "Keep and combine your Claude Code stats from all your computers and accounts: merged PRs, active days, exact tokens, and an SVG card."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Arthur Muradyan" }]
14
+ keywords = ["claude", "claude-code", "ai", "usage", "statistics", "tokens", "developer-tools"]
15
+ classifiers = [
16
+ "Topic :: Software Development",
17
+ "Operating System :: MacOS",
18
+ "Operating System :: POSIX :: Linux",
19
+ "Programming Language :: Python :: 3",
20
+ "Environment :: Console",
21
+ ]
22
+ dependencies = []
23
+
24
+ [project.scripts]
25
+ tokstats = "tokstats.cli:main"
26
+
27
+ [project.urls]
28
+ Homepage = "https://github.com/muradyan/tokstats"
29
+
30
+ [tool.setuptools.packages.find]
31
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """tokstats: keep and combine your AI coding stats from all hosts and accounts."""
2
+
3
+ __version__ = "0.2.0"
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())