tokenleak 1.1.1 → 1.3.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 +465 -49
- package/package.json +1 -1
- package/tokenleak +9518 -3391
package/README.md
CHANGED
|
@@ -1,19 +1,56 @@
|
|
|
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
|
-
Tokenleak
|
|
27
|
+
Install Tokenleak with the package manager you already use:
|
|
10
28
|
|
|
11
29
|
```bash
|
|
30
|
+
# Bun
|
|
12
31
|
bun install -g tokenleak
|
|
32
|
+
|
|
33
|
+
# npm
|
|
34
|
+
npm install -g tokenleak
|
|
35
|
+
|
|
36
|
+
# Run without a global install
|
|
37
|
+
bunx tokenleak --help
|
|
38
|
+
npx tokenleak --help
|
|
13
39
|
```
|
|
14
40
|
|
|
15
|
-
After installing, run `tokenleak` in your terminal. It
|
|
16
|
-
In an interactive TTY, plain `tokenleak`
|
|
41
|
+
After installing, run `tokenleak` in your terminal. It auto-detects supported providers from their local logs.
|
|
42
|
+
In an interactive TTY, plain `tokenleak` opens a launcher where you can:
|
|
43
|
+
|
|
44
|
+
- render the standard terminal dashboard
|
|
45
|
+
- open a tabbed terminal dashboard
|
|
46
|
+
- export JSON, SVG, or PNG
|
|
47
|
+
- build compare reports
|
|
48
|
+
- run explain reports for a specific day
|
|
49
|
+
- run focus reports for deep-work sessions
|
|
50
|
+
- inspect richer analytics such as model efficiency, cache ROI, session/project drill-downs, and attribution clusters
|
|
51
|
+
- start the local live dashboard
|
|
52
|
+
- launch the interactive AI Wrapped presentation in a browser
|
|
53
|
+
- inspect provider availability and aliases
|
|
17
54
|
|
|
18
55
|
### From source
|
|
19
56
|
|
|
@@ -37,6 +74,9 @@ tokenleak
|
|
|
37
74
|
# Skip the launcher and render directly with flags
|
|
38
75
|
tokenleak --format terminal
|
|
39
76
|
|
|
77
|
+
# Start the local live dashboard server
|
|
78
|
+
tokenleak --live-server
|
|
79
|
+
|
|
40
80
|
# Output as JSON
|
|
41
81
|
tokenleak --format json
|
|
42
82
|
|
|
@@ -46,12 +86,107 @@ tokenleak --format svg --output usage.svg
|
|
|
46
86
|
# Export a PNG image
|
|
47
87
|
tokenleak --format png --output usage.png
|
|
48
88
|
|
|
89
|
+
# Generate your AI Coding Wrapped story card
|
|
90
|
+
tokenleak --format wrapped
|
|
91
|
+
tokenleak --format wrapped --theme light --output my-wrapped.png --open
|
|
92
|
+
|
|
93
|
+
# Launch the interactive AI Wrapped presentation in a browser
|
|
94
|
+
tokenleak --wrapped-live
|
|
95
|
+
tokenleak --wrapped-live --days 365
|
|
96
|
+
|
|
97
|
+
# Get model efficiency recommendations
|
|
98
|
+
tokenleak --advisor
|
|
99
|
+
tokenleak --advisor --days 30 --claude
|
|
100
|
+
|
|
49
101
|
# Save to a file (format is inferred from the extension)
|
|
50
102
|
tokenleak -o report.json
|
|
51
103
|
tokenleak -o heatmap.svg
|
|
52
104
|
tokenleak -o card.png
|
|
105
|
+
|
|
106
|
+
# Explain one day's usage
|
|
107
|
+
tokenleak explain 2026-03-10
|
|
108
|
+
tokenleak explain 2026-03-10 --format json
|
|
109
|
+
|
|
110
|
+
# Rank deep-work sessions
|
|
111
|
+
tokenleak focus
|
|
112
|
+
tokenleak focus --provider codex --days 30
|
|
113
|
+
|
|
114
|
+
# Authenticate Cursor and sync its local cache
|
|
115
|
+
tokenleak cursor login --name work
|
|
116
|
+
|
|
117
|
+
# Show registered providers, availability, and aliases
|
|
118
|
+
tokenleak --list-providers
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Analysis commands
|
|
122
|
+
|
|
123
|
+
Tokenleak ships two dedicated investigation commands in addition to the main dashboard flow:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Explain what drove a specific day
|
|
127
|
+
tokenleak explain 2026-03-10
|
|
128
|
+
|
|
129
|
+
# Emit the explain report as JSON
|
|
130
|
+
tokenleak explain 2026-03-10 --format json --output explain.json
|
|
131
|
+
|
|
132
|
+
# Rank sessions by deep-work score
|
|
133
|
+
tokenleak focus --days 30
|
|
134
|
+
|
|
135
|
+
# Focus report as JSON
|
|
136
|
+
tokenleak focus --format json --provider pi --output focus.json
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
- `tokenleak explain <date>` builds a narrative day report with top providers, sessions, projects, models, and anomaly flags.
|
|
140
|
+
- `tokenleak focus` ranks sessions by a deep-work score derived from duration, token density, and project streak.
|
|
141
|
+
|
|
142
|
+
### Cursor commands
|
|
143
|
+
|
|
144
|
+
Use these commands to manage Cursor authentication and the local cache that Tokenleak reads:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
tokenleak cursor login --name work
|
|
148
|
+
tokenleak cursor status
|
|
149
|
+
tokenleak cursor accounts --json
|
|
150
|
+
tokenleak cursor switch work
|
|
151
|
+
tokenleak cursor logout --name work
|
|
152
|
+
tokenleak cursor logout --all --purge-cache
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
- Getting a Cursor session token:
|
|
156
|
+
|
|
157
|
+
The exact Cursor UI may change, but this flow works when the token is not exposed directly in settings:
|
|
158
|
+
|
|
159
|
+
1. Open Cursor and sign in.
|
|
160
|
+
2. Open `https://www.cursor.com/settings`.
|
|
161
|
+
3. Open your browser developer tools, then go to the Network tab.
|
|
162
|
+
4. Refresh the settings page.
|
|
163
|
+
5. Inspect a request sent to `cursor.com` and copy the session token from the authenticated request headers or cookies.
|
|
164
|
+
6. Paste that token into `tokenleak cursor login --name <label>` when prompted.
|
|
165
|
+
|
|
166
|
+
- Local checkout flow:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
# Build once from the repo root
|
|
170
|
+
bun install
|
|
171
|
+
bun run build
|
|
172
|
+
|
|
173
|
+
# Validate the saved Cursor session token
|
|
174
|
+
bun packages/cli/dist/cli.js cursor status
|
|
175
|
+
|
|
176
|
+
# Trigger the first Cursor cache sync and show Cursor-only usage
|
|
177
|
+
bun packages/cli/dist/cli.js --provider cursor --format terminal
|
|
178
|
+
|
|
179
|
+
# Inspect raw Cursor data
|
|
180
|
+
bun packages/cli/dist/cli.js --provider cursor --format json
|
|
53
181
|
```
|
|
54
182
|
|
|
183
|
+
- Normal dashboard/report runs auto-refresh Cursor cache when you are logged in and Cursor is requested or available.
|
|
184
|
+
- If refresh fails but cached CSVs exist, Tokenleak falls back to the cached data.
|
|
185
|
+
- `tokenleak cursor status` only validates the saved session token. It does not mark Cursor as available by itself.
|
|
186
|
+
- `tokenleak --list-providers` reports whether local provider data exists. For Cursor, that means `cursor-cache/usage*.csv` must already be present.
|
|
187
|
+
- 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`.
|
|
188
|
+
- Cursor session tokens are stored in plaintext at `~/.config/tokenleak/cursor-credentials.json` (or under `TOKENLEAK_CURSOR_DIR`) with local-only file permissions.
|
|
189
|
+
|
|
55
190
|
### Date filtering
|
|
56
191
|
|
|
57
192
|
By default, Tokenleak shows the last **90 days** of usage.
|
|
@@ -80,8 +215,27 @@ tokenleak --provider claude-code
|
|
|
80
215
|
# Only Codex
|
|
81
216
|
tokenleak --provider codex
|
|
82
217
|
|
|
218
|
+
# Only Cursor
|
|
219
|
+
tokenleak --provider cursor
|
|
220
|
+
|
|
221
|
+
# Only Pi
|
|
222
|
+
tokenleak --provider pi
|
|
223
|
+
|
|
83
224
|
# Multiple providers (comma-separated)
|
|
84
|
-
tokenleak --provider claude-code,codex
|
|
225
|
+
tokenleak --provider claude-code,codex,cursor,pi
|
|
226
|
+
|
|
227
|
+
# Provider aliases are supported too
|
|
228
|
+
tokenleak --provider anthropic,openai,cursor-ide,pi-mono
|
|
229
|
+
|
|
230
|
+
# Shortcut flags
|
|
231
|
+
tokenleak --claude
|
|
232
|
+
tokenleak --codex
|
|
233
|
+
tokenleak --cursor
|
|
234
|
+
tokenleak --pi
|
|
235
|
+
tokenleak --open-code
|
|
236
|
+
|
|
237
|
+
# Ignore all provider filters and use every available provider
|
|
238
|
+
tokenleak --all-providers
|
|
85
239
|
```
|
|
86
240
|
|
|
87
241
|
### Compare mode
|
|
@@ -89,18 +243,83 @@ tokenleak --provider claude-code,codex
|
|
|
89
243
|
Compare your usage across two time periods to see how your token consumption has changed:
|
|
90
244
|
|
|
91
245
|
```bash
|
|
92
|
-
# Auto-compare: splits your date range in half
|
|
93
|
-
# (
|
|
246
|
+
# Auto-compare: splits your selected date range in half
|
|
247
|
+
# (for example, --days 60 compares the last 30 days against the previous 30 days)
|
|
94
248
|
tokenleak --compare auto
|
|
95
249
|
|
|
96
250
|
# Compare against a specific previous period
|
|
97
251
|
tokenleak --compare 2025-01-01..2025-03-31
|
|
98
252
|
|
|
99
|
-
#
|
|
253
|
+
# JSON compare output contains periodA, periodB, and deltas
|
|
100
254
|
tokenleak --compare auto --format json
|
|
255
|
+
|
|
256
|
+
# Compare cards for images use expanded stats automatically
|
|
257
|
+
tokenleak --compare auto --format png --output compare.png
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
Compare mode compares the current selection against an earlier period and reports deltas for tokens, cost, streaks, active days, average daily tokens, and cache hit rate.
|
|
261
|
+
When you use `--format json`, the output shape is `periodA`, `periodB`, and `deltas`.
|
|
262
|
+
When you use `--format png` or `--format svg`, Tokenleak enables expanded compare cards automatically.
|
|
263
|
+
|
|
264
|
+
### AI Coding Wrapped
|
|
265
|
+
|
|
266
|
+
Generate a Spotify-Wrapped-style story card as a tall PNG image showing your AI coding stats, streaks, model usage, habits, achievements, and more.
|
|
267
|
+
|
|
268
|
+
```bash
|
|
269
|
+
# Generate your wrapped card (dark theme, opens automatically)
|
|
270
|
+
tokenleak --format wrapped --open
|
|
271
|
+
|
|
272
|
+
# Light theme, custom output path
|
|
273
|
+
tokenleak --format wrapped --theme light --output my-wrapped.png
|
|
274
|
+
|
|
275
|
+
# Specific date range
|
|
276
|
+
tokenleak --format wrapped --since 2025-01-01 --until 2025-12-31
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
The wrapped card includes 12 sections: title, big numbers, streak story, top model donut chart, provider mix, day-of-week bars, time-of-day distribution, cache efficiency gauge, peak day spotlight, earned achievements, monthly burn projection, and footer.
|
|
280
|
+
|
|
281
|
+
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.
|
|
282
|
+
|
|
283
|
+
The interactive launcher also includes Wrapped as option `3` with a guided setup flow.
|
|
284
|
+
|
|
285
|
+
### Wrapped Live
|
|
286
|
+
|
|
287
|
+
Launch the AI Wrapped as an interactive 12-slide presentation in your browser with smooth transitions, keyboard/swipe navigation, and progress dots:
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
# Start the wrapped live server (opens on localhost:3456)
|
|
291
|
+
tokenleak --wrapped-live
|
|
292
|
+
|
|
293
|
+
# With a full year of data
|
|
294
|
+
tokenleak --wrapped-live --days 365 --claude
|
|
295
|
+
|
|
296
|
+
# Filter to specific providers
|
|
297
|
+
tokenleak --wrapped-live --provider claude-code,codex
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
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.
|
|
301
|
+
|
|
302
|
+
The interactive launcher includes Wrapped Live as option `4`.
|
|
303
|
+
|
|
304
|
+
### Model Efficiency Advisor
|
|
305
|
+
|
|
306
|
+
Analyze your usage patterns and get actionable recommendations for reducing costs:
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
# Run the advisor (last 90 days by default)
|
|
310
|
+
tokenleak --advisor
|
|
311
|
+
|
|
312
|
+
# Analyze last 30 days, Claude Code only
|
|
313
|
+
tokenleak --advisor --days 30 --claude
|
|
101
314
|
```
|
|
102
315
|
|
|
103
|
-
|
|
316
|
+
The advisor detects three types of opportunities:
|
|
317
|
+
|
|
318
|
+
- **Model downgrades** — identifies expensive models used for short outputs and suggests cheaper alternatives with concrete $/month savings
|
|
319
|
+
- **Cache optimization** — flags low cache hit rates and poor reuse ratios
|
|
320
|
+
- **Usage patterns** — warns about model concentration risk, cost trend increases, and burst days
|
|
321
|
+
|
|
322
|
+
Each recommendation includes current cost, projected cost, monthly savings, and a confidence level (high/medium/low). The advisor is also available as a `get_efficiency_advice` tool in the MCP server.
|
|
104
323
|
|
|
105
324
|
### Themes
|
|
106
325
|
|
|
@@ -123,8 +342,18 @@ tokenleak --no-color
|
|
|
123
342
|
|
|
124
343
|
# Hide the insights panel
|
|
125
344
|
tokenleak --no-insights
|
|
345
|
+
|
|
346
|
+
# Add expanded analytics to terminal/image/json output
|
|
347
|
+
tokenleak --more
|
|
126
348
|
```
|
|
127
349
|
|
|
350
|
+
With `--more`, Tokenleak surfaces:
|
|
351
|
+
|
|
352
|
+
- model efficiency scoring with transparent component breakdowns
|
|
353
|
+
- prompt-cache ROI analysis by provider, model, and project
|
|
354
|
+
- session and project drill-down tables
|
|
355
|
+
- attribution clusters that group work by repo/directory and time window
|
|
356
|
+
|
|
128
357
|
### Sharing
|
|
129
358
|
|
|
130
359
|
```bash
|
|
@@ -134,34 +363,75 @@ tokenleak --format json --clipboard
|
|
|
134
363
|
# Open the output file in your default application after saving
|
|
135
364
|
tokenleak -o usage.svg --open
|
|
136
365
|
|
|
366
|
+
# If no output path is provided for json/svg/png, Tokenleak uses tokenleak.<format>
|
|
367
|
+
tokenleak --format png --open
|
|
368
|
+
|
|
137
369
|
# Upload to a GitHub Gist (requires gh CLI to be authenticated)
|
|
138
370
|
tokenleak --format json --upload gist
|
|
139
371
|
```
|
|
140
372
|
|
|
373
|
+
## Interactive modes
|
|
374
|
+
|
|
375
|
+
### Launcher
|
|
376
|
+
|
|
377
|
+
In a real TTY, `tokenleak` opens a launcher instead of rendering immediately. You can move with arrow keys, use number shortcuts, inspect the exact command preview before running it, and stay inside the same session after each command finishes.
|
|
378
|
+
|
|
379
|
+
### Tabbed terminal dashboard
|
|
380
|
+
|
|
381
|
+
The launcher can open a full-screen terminal dashboard with:
|
|
382
|
+
|
|
383
|
+
- time ranges: `7d`, `30d`, `90d`, `365d`
|
|
384
|
+
- metric tabs: `overview`, `sess`, `tok`, `model`, `cwd`, `dow`, `tod`
|
|
385
|
+
- keyboard navigation for scrolling and switching views
|
|
386
|
+
|
|
387
|
+
This mode uses event-level data when available, so session, token, project, attribution, model-efficiency, and hour-of-day views are most useful for providers that include session metadata in their local logs.
|
|
388
|
+
|
|
389
|
+
### Live dashboard
|
|
390
|
+
|
|
391
|
+
`tokenleak --live-server` starts a local HTTP server that serves an interactive HTML dashboard. The server starts on `http://localhost:3333` and increments the port if needed.
|
|
392
|
+
|
|
141
393
|
## All flags
|
|
142
394
|
|
|
143
395
|
When you run bare `tokenleak` in a real terminal, the launcher shows these flags in-app before you run anything.
|
|
144
396
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
|
153
|
-
|
|
|
154
|
-
| `--
|
|
155
|
-
| `--
|
|
156
|
-
| `--
|
|
157
|
-
| `--
|
|
158
|
-
| `--
|
|
159
|
-
| `--
|
|
160
|
-
| `--
|
|
161
|
-
| `--
|
|
162
|
-
| `--
|
|
163
|
-
|
|
164
|
-
|
|
397
|
+
Subcommands:
|
|
398
|
+
|
|
399
|
+
- `tokenleak explain <date>` supports `--format terminal|json`, `--output`, `--width`, and the standard provider filters.
|
|
400
|
+
- `tokenleak focus` supports `--format terminal|json`, `--output`, `--width`, and the standard provider/date filters.
|
|
401
|
+
- `tokenleak cursor --help` prints the Cursor auth/cache command help text.
|
|
402
|
+
- `tokenleak explain --help` and `tokenleak focus --help` print the subcommand-specific help text.
|
|
403
|
+
|
|
404
|
+
| Flag | Alias | Default | Description |
|
|
405
|
+
| --- | --- | --- | --- |
|
|
406
|
+
| `--format` | `-f` | `terminal` | Output format: `json`, `svg`, `png`, `terminal`, `wrapped` |
|
|
407
|
+
| `--theme` | `-t` | `dark` | Theme for `png`, `svg`, and live output: `dark`, `light` |
|
|
408
|
+
| `--since` | `-s` | | Start date (`YYYY-MM-DD`). Overrides `--days` |
|
|
409
|
+
| `--until` | `-u` | today | End date (`YYYY-MM-DD`) |
|
|
410
|
+
| `--days` | `-d` | `90` | Number of trailing days to include |
|
|
411
|
+
| `--output` | `-o` | stdout | Output path. Format is inferred from the file extension when possible |
|
|
412
|
+
| `--width` | `-w` | `80` | Terminal render width |
|
|
413
|
+
| `--provider` | `-p` | auto | Filter to specific provider(s), comma-separated |
|
|
414
|
+
| `--claude` | | `false` | Shortcut for `--provider claude-code` |
|
|
415
|
+
| `--codex` | | `false` | Shortcut for `--provider codex` |
|
|
416
|
+
| `--cursor` | | `false` | Shortcut for `--provider cursor` |
|
|
417
|
+
| `--pi` | | `false` | Shortcut for `--provider pi` |
|
|
418
|
+
| `--open-code` | | `false` | Shortcut for `--provider open-code` |
|
|
419
|
+
| `--all-providers` | | `false` | Ignore provider filters and use every available provider |
|
|
420
|
+
| `--list-providers` | | `false` | Show registered providers, aliases, and availability |
|
|
421
|
+
| `--compare` | | | Compare against `auto` or `YYYY-MM-DD..YYYY-MM-DD` |
|
|
422
|
+
| `--more` | | `false` | Add expanded PNG/SVG stats and include extra summary data in JSON output |
|
|
423
|
+
| `--clipboard` | | `false` | Copy rendered output to the system clipboard |
|
|
424
|
+
| `--open` | | `false` | Open the rendered file in the default app |
|
|
425
|
+
| `--upload` | | | Upload output to a service. Supported: `gist` |
|
|
426
|
+
| `--live-server` | `-L` | `false` | Start the local browser dashboard |
|
|
427
|
+
| `--wrapped-live` | | `false` | Start the interactive AI Wrapped presentation in a browser |
|
|
428
|
+
| `--advisor` | | `false` | Run the model efficiency advisor |
|
|
429
|
+
| `--no-color` | | `false` | Strip ANSI escape codes from terminal output |
|
|
430
|
+
| `--no-insights` | | `false` | Hide terminal insights |
|
|
431
|
+
| `--version` | | | Print version information |
|
|
432
|
+
| `--help` | | | Print usage information |
|
|
433
|
+
|
|
434
|
+
## Provider details
|
|
165
435
|
|
|
166
436
|
### Claude Code
|
|
167
437
|
|
|
@@ -169,9 +439,10 @@ Reads JSONL conversation logs from the Claude Code projects directory. Each assi
|
|
|
169
439
|
|
|
170
440
|
| | |
|
|
171
441
|
| ----------------- | -------------------------------------------- |
|
|
172
|
-
| **Data location** | `~/.claude/projects
|
|
442
|
+
| **Data location** | `~/.claude/projects/**/*.jsonl` |
|
|
173
443
|
| **Override** | Set `CLAUDE_CONFIG_DIR` environment variable |
|
|
174
444
|
| **Provider name** | `claude-code` |
|
|
445
|
+
| **Aliases** | `anthropic`, `claude`, `claudecode` |
|
|
175
446
|
|
|
176
447
|
### Codex
|
|
177
448
|
|
|
@@ -179,30 +450,58 @@ Reads JSONL session logs from the Codex sessions directory. Parses `response` ev
|
|
|
179
450
|
|
|
180
451
|
| | |
|
|
181
452
|
| ----------------- | ------------------------------------- |
|
|
182
|
-
| **Data location** | `~/.codex/sessions
|
|
453
|
+
| **Data location** | `~/.codex/sessions/**/*.jsonl` |
|
|
183
454
|
| **Override** | Set `CODEX_HOME` environment variable |
|
|
184
455
|
| **Provider name** | `codex` |
|
|
456
|
+
| **Aliases** | `openai` |
|
|
457
|
+
|
|
458
|
+
### Cursor
|
|
459
|
+
|
|
460
|
+
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.
|
|
461
|
+
|
|
462
|
+
`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.
|
|
185
463
|
|
|
186
|
-
|
|
464
|
+
| | |
|
|
465
|
+
| ----------------- | ----------------------------------------------------- |
|
|
466
|
+
| **Data location** | `~/.config/tokenleak/cursor-cache/usage*.csv` |
|
|
467
|
+
| **Override** | Set `TOKENLEAK_CURSOR_DIR` environment variable |
|
|
468
|
+
| **Provider name** | `cursor` |
|
|
469
|
+
| **Aliases** | `cursor-ide`, `cursoride` |
|
|
187
470
|
|
|
188
|
-
|
|
471
|
+
### OpenCode
|
|
472
|
+
|
|
473
|
+
Reads usage data from current OpenCode message storage when available. Falls back to legacy SQLite databases or legacy JSON session files.
|
|
189
474
|
|
|
190
475
|
| | |
|
|
191
476
|
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
192
|
-
| **Data location** | `~/.local/share/opencode/storage/message/<session>/*.json` (
|
|
477
|
+
| **Data location** | `~/.local/share/opencode/storage/message/<session>/*.json` or `~/.config/opencode/storage/message/<session>/*.json` (current), `~/.opencode/opencode.db` or `~/.opencode/sessions.db` (legacy), `~/.opencode/sessions/*.json` (legacy fallback) |
|
|
193
478
|
| **Provider name** | `open-code` |
|
|
479
|
+
| **Aliases** | `opencode`, `open_code` |
|
|
480
|
+
|
|
481
|
+
### Pi
|
|
482
|
+
|
|
483
|
+
Reads local `pi-mono` session JSONL files. Assistant messages with `usage` metadata are aggregated from the on-disk session history.
|
|
484
|
+
|
|
485
|
+
| | |
|
|
486
|
+
| ----------------- | ------------------------------------------------ |
|
|
487
|
+
| **Data location** | `~/.pi/agent/sessions/**/*.jsonl` |
|
|
488
|
+
| **Override** | Set `PI_CODING_AGENT_DIR` environment variable |
|
|
489
|
+
| **Provider name** | `pi` |
|
|
490
|
+
| **Aliases** | `pi-mono` |
|
|
194
491
|
|
|
195
492
|
## Output formats
|
|
196
493
|
|
|
197
494
|
### `terminal` (default)
|
|
198
495
|
|
|
199
|
-
A
|
|
496
|
+
A rendered terminal dashboard with:
|
|
200
497
|
|
|
201
498
|
- GitHub-style heatmap using Unicode block characters (`░▒▓█`)
|
|
202
|
-
-
|
|
203
|
-
-
|
|
204
|
-
-
|
|
205
|
-
-
|
|
499
|
+
- overview and provider sections with tokens, cost, streaks, rolling totals, and model leaders
|
|
500
|
+
- day-of-week breakdown showing which days you code most
|
|
501
|
+
- top models ranked by token usage
|
|
502
|
+
- model efficiency and cache ROI sections when `--more` is enabled
|
|
503
|
+
- session/project drill-down and attribution detail in the tabbed dashboard
|
|
504
|
+
- insights such as peak day, top model, and provider mix
|
|
206
505
|
|
|
207
506
|
Falls back to a compact one-liner when terminal width is under 40 characters.
|
|
208
507
|
|
|
@@ -251,6 +550,45 @@ Structured JSON output containing:
|
|
|
251
550
|
"totalCost": 52.5,
|
|
252
551
|
// ... rolling windows, peaks, averages, day-of-week, top models
|
|
253
552
|
},
|
|
553
|
+
"more": null
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
When `--more` is enabled, the `more` field contains expanded metrics such as:
|
|
558
|
+
|
|
559
|
+
- `inputOutput`, `monthlyBurn`, `cacheEconomics`, and `hourOfDay`
|
|
560
|
+
- `modelEfficiency` rankings and ineligible-model reasons
|
|
561
|
+
- `cacheRoi` summary plus provider/model/project ROI breakdowns
|
|
562
|
+
- `sessionMetrics`, `sessionDrilldown`, and `projectDrilldown`
|
|
563
|
+
- `attribution` clusters for repo/directory-oriented work grouping
|
|
564
|
+
- compare metadata when applicable
|
|
565
|
+
|
|
566
|
+
The dedicated analysis commands also support JSON output:
|
|
567
|
+
|
|
568
|
+
```bash
|
|
569
|
+
tokenleak explain 2026-03-10 --format json
|
|
570
|
+
tokenleak focus --format json
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
- `tokenleak explain ... --format json` returns an explain report with headline, summary bullets, evidence tables, and anomaly flags.
|
|
574
|
+
- `tokenleak focus ... --format json` returns a ranked focus report with deep-work scores, durations, densities, streaks, and rationales per session.
|
|
575
|
+
|
|
576
|
+
When `--compare` is used with `--format json`, the output is a compare payload with:
|
|
577
|
+
|
|
578
|
+
```jsonc
|
|
579
|
+
{
|
|
580
|
+
"schemaVersion": 1,
|
|
581
|
+
"generated": "2026-03-14T10:15:00.000Z",
|
|
582
|
+
"periodA": { "range": { "since": "2026-02-15", "until": "2026-03-14" }, "stats": {} },
|
|
583
|
+
"periodB": { "range": { "since": "2026-01-18", "until": "2026-02-14" }, "stats": {} },
|
|
584
|
+
"deltas": {
|
|
585
|
+
"tokens": 125000,
|
|
586
|
+
"cost": 4.8,
|
|
587
|
+
"streak": 3,
|
|
588
|
+
"activeDays": 5,
|
|
589
|
+
"averageDailyTokens": 4200,
|
|
590
|
+
"cacheHitRate": 0.08
|
|
591
|
+
}
|
|
254
592
|
}
|
|
255
593
|
```
|
|
256
594
|
|
|
@@ -262,10 +600,13 @@ A self-contained SVG image with:
|
|
|
262
600
|
- Month labels and day-of-week labels
|
|
263
601
|
- Stats panel and insights panel
|
|
264
602
|
- Supports `dark` and `light` themes
|
|
603
|
+
- Supports compare cards and expanded stat panels when `--more` is enabled
|
|
265
604
|
|
|
266
605
|
### `png`
|
|
267
606
|
|
|
268
|
-
Same layout as SVG, rendered to a PNG image via [sharp](https://sharp.pixelplumbing.com/). Useful for embedding in documents or sharing on platforms that
|
|
607
|
+
Same layout as SVG, rendered to a PNG image via [sharp](https://sharp.pixelplumbing.com/). Useful for embedding in documents or sharing on platforms that do not support SVG.
|
|
608
|
+
|
|
609
|
+
With `--more`, PNG output includes expanded stat blocks such as input/output efficiency, projected monthly burn, cache economics, session metrics, hour-of-day activity, and model mix shift for compare renders. The newest drill-down analytics are optimized first for terminal and JSON output.
|
|
269
610
|
|
|
270
611
|
## Configuration file
|
|
271
612
|
|
|
@@ -278,7 +619,8 @@ Create `~/.tokenleakrc` to set persistent defaults:
|
|
|
278
619
|
"days": 90,
|
|
279
620
|
"width": 120,
|
|
280
621
|
"noColor": false,
|
|
281
|
-
"noInsights": false
|
|
622
|
+
"noInsights": false,
|
|
623
|
+
"more": false
|
|
282
624
|
}
|
|
283
625
|
```
|
|
284
626
|
|
|
@@ -288,18 +630,20 @@ All fields are optional. Only include the ones you want to override.
|
|
|
288
630
|
|
|
289
631
|
## Environment variables
|
|
290
632
|
|
|
291
|
-
| Variable
|
|
292
|
-
|
|
|
293
|
-
| `TOKENLEAK_FORMAT`
|
|
294
|
-
| `TOKENLEAK_THEME`
|
|
295
|
-
| `TOKENLEAK_DAYS`
|
|
633
|
+
| Variable | Default | Description |
|
|
634
|
+
| --- | --- | --- |
|
|
635
|
+
| `TOKENLEAK_FORMAT` | `terminal` | Default output format |
|
|
636
|
+
| `TOKENLEAK_THEME` | `dark` | Default theme |
|
|
637
|
+
| `TOKENLEAK_DAYS` | `90` | Default lookback period in days |
|
|
296
638
|
| `TOKENLEAK_MAX_JSONL_RECORD_BYTES` | `10485760` (10 MB) | Max size of a single JSONL record before it is rejected |
|
|
297
|
-
| `CLAUDE_CONFIG_DIR`
|
|
298
|
-
| `CODEX_HOME`
|
|
639
|
+
| `CLAUDE_CONFIG_DIR` | `~/.claude` | Claude Code configuration directory |
|
|
640
|
+
| `CODEX_HOME` | `~/.codex` | Codex home directory |
|
|
641
|
+
| `TOKENLEAK_CURSOR_DIR` | `~/.config/tokenleak` | Cursor credentials/cache root (`cursor-credentials.json`, `cursor-cache/`) |
|
|
642
|
+
| `PI_CODING_AGENT_DIR` | `~/.pi/agent` | Pi coding agent directory (sessions live under `sessions/`) |
|
|
299
643
|
|
|
300
644
|
## What Tokenleak tracks
|
|
301
645
|
|
|
302
|
-
Tokenleak reads your **local**
|
|
646
|
+
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.
|
|
303
647
|
|
|
304
648
|
For each day of usage, it tracks:
|
|
305
649
|
|
|
@@ -318,7 +662,78 @@ It then computes:
|
|
|
318
662
|
- **Cache hit rate** — percentage of input tokens served from cache
|
|
319
663
|
- **Top models** — models ranked by total token consumption
|
|
320
664
|
- **Daily averages** — mean tokens and cost per day
|
|
665
|
+
- **Model efficiency** — output-per-dollar, output/input ratio, cache coverage, and a composite score
|
|
666
|
+
- **Prompt-cache ROI** — read savings, write cost, net savings, reuse ratio, and payback ratio
|
|
667
|
+
- **Session and project drill-downs** — duration, dominant models, active days, and streaks
|
|
668
|
+
- **Attribution clusters** — repo/directory-oriented groupings of sessions into investigations or feature work
|
|
669
|
+
- **Explain and focus reports** — narrative daily diagnostics and deep-work session rankings
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
## MCP Server
|
|
673
|
+
|
|
674
|
+
Tokenleak includes an MCP (Model Context Protocol) server that lets AI coding assistants query your token usage directly. Ask Claude Code, Cursor, or any MCP-compatible client "how much have I spent this week?" and get answers from your local data without leaving the editor.
|
|
675
|
+
|
|
676
|
+
### Setup
|
|
677
|
+
|
|
678
|
+
Add the server to your MCP client configuration:
|
|
679
|
+
|
|
680
|
+
**Claude Code** (`.mcp.json` in your project or `~/.claude/claude_desktop_config.json`):
|
|
681
|
+
|
|
682
|
+
```json
|
|
683
|
+
{
|
|
684
|
+
"mcpServers": {
|
|
685
|
+
"tokenleak": {
|
|
686
|
+
"command": "bun",
|
|
687
|
+
"args": ["run", "/path/to/tokenleak/packages/mcp/dist/index.js"]
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
```
|
|
321
692
|
|
|
693
|
+
**Cursor** (Settings > MCP Servers):
|
|
694
|
+
|
|
695
|
+
```json
|
|
696
|
+
{
|
|
697
|
+
"mcpServers": {
|
|
698
|
+
"tokenleak": {
|
|
699
|
+
"command": "bun",
|
|
700
|
+
"args": ["run", "/path/to/tokenleak/packages/mcp/dist/index.js"]
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
```
|
|
705
|
+
|
|
706
|
+
> Replace `/path/to/tokenleak` with your actual clone path. Make sure to run `bun run build` first.
|
|
707
|
+
|
|
708
|
+
### Available tools
|
|
709
|
+
|
|
710
|
+
| Tool | Description |
|
|
711
|
+
| --- | --- |
|
|
712
|
+
| `list_providers` | List all registered providers and their availability |
|
|
713
|
+
| `get_usage_summary` | Token/cost summary with streaks, rolling windows, and per-provider breakdown |
|
|
714
|
+
| `get_daily_usage` | Day-by-day usage data for trend analysis (default: 14 days) |
|
|
715
|
+
| `get_cost_breakdown` | Models ranked by cost with token counts and share percentages |
|
|
716
|
+
| `get_streaks_and_habits` | Streaks, day-of-week patterns, peak day, session metrics (default: 90 days) |
|
|
717
|
+
| `compare_periods` | Compare two time periods with deltas for tokens, cost, streaks, and cache rate |
|
|
718
|
+
|
|
719
|
+
All tools accept optional `days`, `since`, and `until` parameters for date filtering. `get_usage_summary` and `get_daily_usage` also accept a `provider` parameter to filter to a specific provider.
|
|
720
|
+
|
|
721
|
+
### Available resources
|
|
722
|
+
|
|
723
|
+
| Resource | Description |
|
|
724
|
+
| --- | --- |
|
|
725
|
+
| `tokenleak://overview` | 30-day usage summary as JSON |
|
|
726
|
+
| `tokenleak://provider/{name}` | Per-provider usage data |
|
|
727
|
+
|
|
728
|
+
### Running the server directly
|
|
729
|
+
|
|
730
|
+
```bash
|
|
731
|
+
# Build first
|
|
732
|
+
bun run build
|
|
733
|
+
|
|
734
|
+
# Start the MCP server (stdio transport)
|
|
735
|
+
bun packages/mcp/dist/index.js
|
|
736
|
+
```
|
|
322
737
|
|
|
323
738
|
## Project structure
|
|
324
739
|
|
|
@@ -329,6 +744,7 @@ tokenleak/
|
|
|
329
744
|
registry/ Provider parsers and model pricing
|
|
330
745
|
renderers/ JSON, SVG, PNG, and terminal output
|
|
331
746
|
cli/ CLI entrypoint and config handling
|
|
747
|
+
mcp/ MCP server for AI assistant integration
|
|
332
748
|
scripts/
|
|
333
749
|
build-npm.ts Bundles CLI for npm publishing
|
|
334
750
|
dist/
|