tokenleak 1.2.0 → 2.0.0
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.
- package/README.md +147 -34
- package/package.json +3 -2
- package/tokenleak +9063 -4045
package/README.md
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
# Tokenleak
|
|
2
2
|
|
|
3
|
-
See where your AI tokens actually go. Tokenleak reads
|
|
3
|
+
See where your AI tokens actually go. Tokenleak reads usage data from **Claude Code**, **Codex**, **Cursor**, **Pi (`pi-mono`)**, and **OpenCode**, then renders terminal dashboards, heatmaps, compare reports, explain/focus reports, and shareable image cards from the CLI.
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
Tokenleak auto-detects supported providers from their local logs and storage. This is the quick scan of where it looks before it renders dashboards, reports, and images:
|
|
10
|
+
|
|
11
|
+
| Client | Local data location | Provider key and aliases | Supported |
|
|
12
|
+
| ------ | ------------------- | ------------------------ | --------- |
|
|
13
|
+
| Claude Code | `~/.claude/projects/**/*.jsonl` | `claude-code`, `anthropic`, `claude`, `claudecode` | Yes |
|
|
14
|
+
| Codex | `~/.codex/sessions/**/*.jsonl` | `codex`, `openai` | Yes |
|
|
15
|
+
| Cursor | `~/.config/tokenleak/cursor-cache/usage*.csv` after `tokenleak cursor login` | `cursor`, `cursor-ide`, `cursoride` | Yes |
|
|
16
|
+
| OpenCode | `~/.local/share/opencode/storage/message/<session>/*.json` or `~/.config/opencode/storage/message/<session>/*.json`<br />Legacy: `~/.opencode/opencode.db`, `~/.opencode/sessions.db`, `~/.opencode/sessions/*.json` | `open-code`, `opencode`, `open_code` | Yes |
|
|
17
|
+
| Pi (`pi-mono`) | `~/.pi/agent/sessions/**/*.jsonl` | `pi`, `pi-mono` | Yes |
|
|
18
|
+
|
|
19
|
+
- Use `CLAUDE_CONFIG_DIR` to override the Claude Code base directory.
|
|
20
|
+
- Use `CODEX_HOME` to override the Codex base directory.
|
|
21
|
+
- Use `TOKENLEAK_CURSOR_DIR` to override the Cursor credentials/cache directory.
|
|
22
|
+
- Use `PI_CODING_AGENT_DIR` to override the Pi base directory.
|
|
23
|
+
- See [Provider details](#provider-details) for the parser behavior and per-provider notes.
|
|
24
|
+
|
|
7
25
|
## Install
|
|
8
26
|
|
|
9
27
|
Install Tokenleak with the package manager you already use:
|
|
@@ -21,18 +39,18 @@ npx tokenleak --help
|
|
|
21
39
|
```
|
|
22
40
|
|
|
23
41
|
After installing, run `tokenleak` in your terminal. It auto-detects supported providers from their local logs.
|
|
24
|
-
In an interactive TTY, plain `tokenleak`
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
In an interactive TTY, plain `tokenleak` launches a full-screen TUI dashboard with 8 views:
|
|
43
|
+
|
|
44
|
+
- **Overview** — heatmap, stats, providers, and top models
|
|
45
|
+
- **Matrix** — 4-page deep-dive with activity patterns, cache economics, sessions, model efficiency, attribution, and cache ROI by model
|
|
46
|
+
- **Advisor** — model efficiency recommendations with projected savings
|
|
47
|
+
- **Focus** — deep-work session rankings scored by duration, density, and streaks
|
|
48
|
+
- **Explain** — narrative day-by-day usage breakdown
|
|
49
|
+
- **Compare** — side-by-side period comparison with deltas
|
|
50
|
+
- **Export** — save PNG, Wrapped PNG, or launch a live server
|
|
51
|
+
- **Wrapped** — Spotify-Wrapped-style stats card with achievements and usage breakdown
|
|
52
|
+
|
|
53
|
+
Use `tokenleak --legacy` to open the classic interactive launcher instead.
|
|
36
54
|
|
|
37
55
|
### From source
|
|
38
56
|
|
|
@@ -50,10 +68,13 @@ bun dist/tokenleak.js
|
|
|
50
68
|
## Usage
|
|
51
69
|
|
|
52
70
|
```bash
|
|
53
|
-
# Open the
|
|
71
|
+
# Open the TUI dashboard (TTY only)
|
|
54
72
|
tokenleak
|
|
55
73
|
|
|
56
|
-
#
|
|
74
|
+
# Open the classic interactive launcher
|
|
75
|
+
tokenleak --legacy
|
|
76
|
+
|
|
77
|
+
# Skip the TUI and render directly with flags
|
|
57
78
|
tokenleak --format terminal
|
|
58
79
|
|
|
59
80
|
# Start the local live dashboard server
|
|
@@ -93,6 +114,9 @@ tokenleak explain 2026-03-10 --format json
|
|
|
93
114
|
tokenleak focus
|
|
94
115
|
tokenleak focus --provider codex --days 30
|
|
95
116
|
|
|
117
|
+
# Authenticate Cursor and sync its local cache
|
|
118
|
+
tokenleak cursor login --name work
|
|
119
|
+
|
|
96
120
|
# Show registered providers, availability, and aliases
|
|
97
121
|
tokenleak --list-providers
|
|
98
122
|
```
|
|
@@ -118,6 +142,56 @@ tokenleak focus --format json --provider pi --output focus.json
|
|
|
118
142
|
- `tokenleak explain <date>` builds a narrative day report with top providers, sessions, projects, models, and anomaly flags.
|
|
119
143
|
- `tokenleak focus` ranks sessions by a deep-work score derived from duration, token density, and project streak.
|
|
120
144
|
|
|
145
|
+
### Cursor commands
|
|
146
|
+
|
|
147
|
+
Use these commands to manage Cursor authentication and the local cache that Tokenleak reads:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
tokenleak cursor login --name work
|
|
151
|
+
tokenleak cursor status
|
|
152
|
+
tokenleak cursor accounts --json
|
|
153
|
+
tokenleak cursor switch work
|
|
154
|
+
tokenleak cursor logout --name work
|
|
155
|
+
tokenleak cursor logout --all --purge-cache
|
|
156
|
+
tokenleak cursor reset
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
- Getting a Cursor session token:
|
|
160
|
+
|
|
161
|
+
The exact browser wording may vary, but the reliable source of truth is the `WorkosCursorSessionToken` cookie:
|
|
162
|
+
|
|
163
|
+
1. Open Cursor and sign in.
|
|
164
|
+
2. Open `https://www.cursor.com/settings`.
|
|
165
|
+
3. Open your browser developer tools.
|
|
166
|
+
4. Go to `Application` (or `Storage`) -> `Cookies` -> `https://www.cursor.com`.
|
|
167
|
+
5. Copy the value of the `WorkosCursorSessionToken` cookie.
|
|
168
|
+
6. Paste that token into `tokenleak cursor login --name <label>` when prompted, or into the TUI setup modal after pressing `c`.
|
|
169
|
+
|
|
170
|
+
- Local checkout flow:
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
# Build once from the repo root
|
|
174
|
+
bun install
|
|
175
|
+
bun run build
|
|
176
|
+
|
|
177
|
+
# Validate the saved Cursor session token
|
|
178
|
+
bun packages/cli/dist/cli.js cursor status
|
|
179
|
+
|
|
180
|
+
# Trigger the first Cursor cache sync and show Cursor-only usage
|
|
181
|
+
bun packages/cli/dist/cli.js --provider cursor --format terminal
|
|
182
|
+
|
|
183
|
+
# Inspect raw Cursor data
|
|
184
|
+
bun packages/cli/dist/cli.js --provider cursor --format json
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
- Normal dashboard/report runs auto-refresh Cursor cache when you are logged in and Cursor is requested or available.
|
|
188
|
+
- If refresh fails but cached CSVs exist, Tokenleak falls back to the cached data.
|
|
189
|
+
- `tokenleak cursor status` only validates the saved session token. It does not mark Cursor as available by itself.
|
|
190
|
+
- `tokenleak cursor reset` clears saved Cursor credentials and the local Cursor cache so you can re-test the in-TUI setup flow from a clean state.
|
|
191
|
+
- `tokenleak --list-providers` reports whether local provider data exists. For Cursor, that means `cursor-cache/usage*.csv` must already be present.
|
|
192
|
+
- If `cursor status` is valid but `--list-providers` still shows Cursor as unavailable, run `tokenleak --provider cursor` once to sync the cache, then rerun `--list-providers`.
|
|
193
|
+
- Cursor session tokens are stored in plaintext at `~/.config/tokenleak/cursor-credentials.json` (or under `TOKENLEAK_CURSOR_DIR`) with local-only file permissions.
|
|
194
|
+
|
|
121
195
|
### Date filtering
|
|
122
196
|
|
|
123
197
|
By default, Tokenleak shows the last **90 days** of usage.
|
|
@@ -146,18 +220,22 @@ tokenleak --provider claude-code
|
|
|
146
220
|
# Only Codex
|
|
147
221
|
tokenleak --provider codex
|
|
148
222
|
|
|
223
|
+
# Only Cursor
|
|
224
|
+
tokenleak --provider cursor
|
|
225
|
+
|
|
149
226
|
# Only Pi
|
|
150
227
|
tokenleak --provider pi
|
|
151
228
|
|
|
152
229
|
# Multiple providers (comma-separated)
|
|
153
|
-
tokenleak --provider claude-code,codex,pi
|
|
230
|
+
tokenleak --provider claude-code,codex,cursor,pi
|
|
154
231
|
|
|
155
232
|
# Provider aliases are supported too
|
|
156
|
-
tokenleak --provider anthropic,openai,pi-mono
|
|
233
|
+
tokenleak --provider anthropic,openai,cursor-ide,pi-mono
|
|
157
234
|
|
|
158
235
|
# Shortcut flags
|
|
159
236
|
tokenleak --claude
|
|
160
237
|
tokenleak --codex
|
|
238
|
+
tokenleak --cursor
|
|
161
239
|
tokenleak --pi
|
|
162
240
|
tokenleak --open-code
|
|
163
241
|
|
|
@@ -207,7 +285,7 @@ The wrapped card includes 12 sections: title, big numbers, streak story, top mod
|
|
|
207
285
|
|
|
208
286
|
Achievements are computed from your actual data — earn badges like Streak Master (30+ day streak), Cache Master (>50% hit rate), Night Owl (>40% usage 10pm-6am), Power User (>10k avg daily tokens), and more.
|
|
209
287
|
|
|
210
|
-
The
|
|
288
|
+
The TUI dashboard includes a Wrapped view (press `8` or arrow to it). The classic launcher (`tokenleak --legacy`) also offers a guided Wrapped setup flow.
|
|
211
289
|
|
|
212
290
|
### Wrapped Live
|
|
213
291
|
|
|
@@ -226,7 +304,7 @@ tokenleak --wrapped-live --provider claude-code,codex
|
|
|
226
304
|
|
|
227
305
|
The presentation uses the same 12 sections as the static wrapped card but rendered as navigable slides with an obsidian-and-gold design. Use arrow keys, click the nav buttons, or swipe on touch devices to move between slides.
|
|
228
306
|
|
|
229
|
-
The
|
|
307
|
+
The classic launcher (`tokenleak --legacy`) includes Wrapped Live as a menu option.
|
|
230
308
|
|
|
231
309
|
### Model Efficiency Advisor
|
|
232
310
|
|
|
@@ -299,19 +377,36 @@ tokenleak --format json --upload gist
|
|
|
299
377
|
|
|
300
378
|
## Interactive modes
|
|
301
379
|
|
|
302
|
-
###
|
|
380
|
+
### TUI dashboard (default)
|
|
303
381
|
|
|
304
|
-
In a real TTY, `tokenleak`
|
|
382
|
+
In a real TTY, `tokenleak` launches a full-screen terminal dashboard built with [@opentui/core](https://www.npmjs.com/package/@opentui/core). The TUI provides 8 views with keyboard and mouse navigation:
|
|
305
383
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
384
|
+
| Key | Action |
|
|
385
|
+
| --- | --- |
|
|
386
|
+
| `←` / `→` | Switch between views |
|
|
387
|
+
| `Tab` / `>` | Next time period (1D → 7D → 30D → 90D → ALL) |
|
|
388
|
+
| `Shift+Tab` / `<` | Previous time period |
|
|
389
|
+
| `1`–`8` | Jump directly to a view |
|
|
390
|
+
| `j` / `k` | Scroll up/down in scrollable views |
|
|
391
|
+
| `[` / `]` | Matrix page navigation (in Matrix view) |
|
|
392
|
+
| `h` / `l` | Previous/next day (in Explain view) |
|
|
393
|
+
| `s` | Toggle sort mode (in Overview) |
|
|
394
|
+
| `r` | Refresh data |
|
|
395
|
+
| `c` | Open Cursor setup when the dashboard shows a Cursor auth/sync banner |
|
|
396
|
+
| `?` | Help overlay |
|
|
397
|
+
| `q` | Quit |
|
|
398
|
+
|
|
399
|
+
When Cursor needs setup, re-authentication, or a cache retry, the TUI shows a contextual banner. Press `c` to open the built-in Cursor setup flow, paste a session token, validate it, and sync usage CSVs without leaving the dashboard.
|
|
400
|
+
|
|
401
|
+
The Matrix view spans 4 pages:
|
|
402
|
+
1. Overview + time windows + providers + top models
|
|
403
|
+
2. Hour-of-day, day-of-week, I/O breakdown, monthly burn
|
|
404
|
+
3. Cache economics, cache ROI, session metrics, top projects
|
|
405
|
+
4. Model efficiency, attribution clusters, top sessions, cache ROI by model
|
|
406
|
+
|
|
407
|
+
### Classic launcher
|
|
408
|
+
|
|
409
|
+
`tokenleak --legacy` opens the previous interactive launcher with a numbered menu, command preview, and guided setup flows for exports, wrapped cards, and the live dashboard.
|
|
315
410
|
|
|
316
411
|
### Live dashboard
|
|
317
412
|
|
|
@@ -319,12 +414,13 @@ This mode uses event-level data when available, so session, token, project, attr
|
|
|
319
414
|
|
|
320
415
|
## All flags
|
|
321
416
|
|
|
322
|
-
When you run bare `tokenleak` in a real terminal, the
|
|
417
|
+
When you run bare `tokenleak` in a real terminal, the TUI dashboard launches. Pass flags to skip the TUI and render directly.
|
|
323
418
|
|
|
324
419
|
Subcommands:
|
|
325
420
|
|
|
326
421
|
- `tokenleak explain <date>` supports `--format terminal|json`, `--output`, `--width`, and the standard provider filters.
|
|
327
422
|
- `tokenleak focus` supports `--format terminal|json`, `--output`, `--width`, and the standard provider/date filters.
|
|
423
|
+
- `tokenleak cursor --help` prints the Cursor auth/cache command help text.
|
|
328
424
|
- `tokenleak explain --help` and `tokenleak focus --help` print the subcommand-specific help text.
|
|
329
425
|
|
|
330
426
|
| Flag | Alias | Default | Description |
|
|
@@ -339,6 +435,7 @@ Subcommands:
|
|
|
339
435
|
| `--provider` | `-p` | auto | Filter to specific provider(s), comma-separated |
|
|
340
436
|
| `--claude` | | `false` | Shortcut for `--provider claude-code` |
|
|
341
437
|
| `--codex` | | `false` | Shortcut for `--provider codex` |
|
|
438
|
+
| `--cursor` | | `false` | Shortcut for `--provider cursor` |
|
|
342
439
|
| `--pi` | | `false` | Shortcut for `--provider pi` |
|
|
343
440
|
| `--open-code` | | `false` | Shortcut for `--provider open-code` |
|
|
344
441
|
| `--all-providers` | | `false` | Ignore provider filters and use every available provider |
|
|
@@ -351,12 +448,13 @@ Subcommands:
|
|
|
351
448
|
| `--live-server` | `-L` | `false` | Start the local browser dashboard |
|
|
352
449
|
| `--wrapped-live` | | `false` | Start the interactive AI Wrapped presentation in a browser |
|
|
353
450
|
| `--advisor` | | `false` | Run the model efficiency advisor |
|
|
451
|
+
| `--legacy` | | `false` | Open the classic interactive launcher instead of the TUI |
|
|
354
452
|
| `--no-color` | | `false` | Strip ANSI escape codes from terminal output |
|
|
355
453
|
| `--no-insights` | | `false` | Hide terminal insights |
|
|
356
454
|
| `--version` | | | Print version information |
|
|
357
455
|
| `--help` | | | Print usage information |
|
|
358
456
|
|
|
359
|
-
##
|
|
457
|
+
## Provider details
|
|
360
458
|
|
|
361
459
|
### Claude Code
|
|
362
460
|
|
|
@@ -380,6 +478,19 @@ Reads JSONL session logs from the Codex sessions directory. Parses `response` ev
|
|
|
380
478
|
| **Provider name** | `codex` |
|
|
381
479
|
| **Aliases** | `openai` |
|
|
382
480
|
|
|
481
|
+
### Cursor
|
|
482
|
+
|
|
483
|
+
Reads Cursor usage CSV exports from the local Tokenleak cache. The cache is populated by authenticating with `tokenleak cursor login`, after which normal runs auto-refresh the CSVs when possible.
|
|
484
|
+
|
|
485
|
+
`tokenleak cursor status` confirms that your saved session token is valid. Cursor only becomes `[available]` in `tokenleak --list-providers` after the local cache has at least one `usage*.csv` file, usually after the first `tokenleak --provider cursor` run.
|
|
486
|
+
|
|
487
|
+
| | |
|
|
488
|
+
| ----------------- | ----------------------------------------------------- |
|
|
489
|
+
| **Data location** | `~/.config/tokenleak/cursor-cache/usage*.csv` |
|
|
490
|
+
| **Override** | Set `TOKENLEAK_CURSOR_DIR` environment variable |
|
|
491
|
+
| **Provider name** | `cursor` |
|
|
492
|
+
| **Aliases** | `cursor-ide`, `cursoride` |
|
|
493
|
+
|
|
383
494
|
### OpenCode
|
|
384
495
|
|
|
385
496
|
Reads usage data from current OpenCode message storage when available. Falls back to legacy SQLite databases or legacy JSON session files.
|
|
@@ -550,11 +661,12 @@ All fields are optional. Only include the ones you want to override.
|
|
|
550
661
|
| `TOKENLEAK_MAX_JSONL_RECORD_BYTES` | `10485760` (10 MB) | Max size of a single JSONL record before it is rejected |
|
|
551
662
|
| `CLAUDE_CONFIG_DIR` | `~/.claude` | Claude Code configuration directory |
|
|
552
663
|
| `CODEX_HOME` | `~/.codex` | Codex home directory |
|
|
664
|
+
| `TOKENLEAK_CURSOR_DIR` | `~/.config/tokenleak` | Cursor credentials/cache root (`cursor-credentials.json`, `cursor-cache/`) |
|
|
553
665
|
| `PI_CODING_AGENT_DIR` | `~/.pi/agent` | Pi coding agent directory (sessions live under `sessions/`) |
|
|
554
666
|
|
|
555
667
|
## What Tokenleak tracks
|
|
556
668
|
|
|
557
|
-
Tokenleak reads your **local** logs
|
|
669
|
+
Tokenleak reads your **local** logs and caches. For Cursor, Tokenleak can also fetch fresh usage CSVs from Cursor's API after you authenticate with `tokenleak cursor login`; that network step only happens for Cursor and only to refresh the local cache.
|
|
558
670
|
|
|
559
671
|
For each day of usage, it tracks:
|
|
560
672
|
|
|
@@ -654,12 +766,13 @@ tokenleak/
|
|
|
654
766
|
core/ Shared types, constants, aggregation engine
|
|
655
767
|
registry/ Provider parsers and model pricing
|
|
656
768
|
renderers/ JSON, SVG, PNG, and terminal output
|
|
769
|
+
tui/ Full-screen TUI dashboard (default interactive mode)
|
|
657
770
|
cli/ CLI entrypoint and config handling
|
|
658
771
|
mcp/ MCP server for AI assistant integration
|
|
659
772
|
scripts/
|
|
660
773
|
build-npm.ts Bundles CLI for npm publishing
|
|
661
774
|
dist/
|
|
662
|
-
tokenleak
|
|
775
|
+
tokenleak Bundled CLI (generated)
|
|
663
776
|
```
|
|
664
777
|
|
|
665
778
|
## Contributing
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokenleak",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Visualise your AI coding-assistant token usage across providers — heatmaps, dashboards, and shareable cards.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"tokenleak"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"sharp": "^0.34.0"
|
|
13
|
+
"sharp": "^0.34.0",
|
|
14
|
+
"@opentui/core": "^0.1.88"
|
|
14
15
|
},
|
|
15
16
|
"engines": {
|
|
16
17
|
"bun": ">=1.0.0"
|