tokenleak 1.1.0 → 1.2.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.
Files changed (3) hide show
  1. package/README.md +374 -47
  2. package/package.json +1 -1
  3. package/tokenleak +8905 -2383
package/README.md CHANGED
@@ -1,19 +1,38 @@
1
1
  # Tokenleak
2
2
 
3
- See where your AI tokens actually go. Tokenleak reads local usage logs from **Claude Code**, **Codex**, and **Open Code**, then renders heatmaps, dashboards, and shareable cards — all from your terminal.
3
+ See where your AI tokens actually go. Tokenleak reads local usage logs from **Claude Code**, **Codex**, **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
  ![Tokenleak preview card](./docs/preview.png)
6
6
 
7
7
  ## Install
8
8
 
9
- Tokenleak requires [Bun](https://bun.sh) (v1.0+).
9
+ Install Tokenleak with the package manager you already use:
10
10
 
11
11
  ```bash
12
+ # Bun
12
13
  bun install -g tokenleak
14
+
15
+ # npm
16
+ npm install -g tokenleak
17
+
18
+ # Run without a global install
19
+ bunx tokenleak --help
20
+ npx tokenleak --help
13
21
  ```
14
22
 
15
- After installing, run `tokenleak` in your terminal. It will automatically detect which AI coding tools you have installed and display your usage.
16
- In an interactive TTY, plain `tokenleak` now opens a launcher where you can move with arrow keys or press number shortcuts.
23
+ After installing, run `tokenleak` in your terminal. It auto-detects supported providers from their local logs.
24
+ In an interactive TTY, plain `tokenleak` opens a launcher where you can:
25
+
26
+ - render the standard terminal dashboard
27
+ - open a tabbed terminal dashboard
28
+ - export JSON, SVG, or PNG
29
+ - build compare reports
30
+ - run explain reports for a specific day
31
+ - run focus reports for deep-work sessions
32
+ - inspect richer analytics such as model efficiency, cache ROI, session/project drill-downs, and attribution clusters
33
+ - start the local live dashboard
34
+ - launch the interactive AI Wrapped presentation in a browser
35
+ - inspect provider availability and aliases
17
36
 
18
37
  ### From source
19
38
 
@@ -37,6 +56,9 @@ tokenleak
37
56
  # Skip the launcher and render directly with flags
38
57
  tokenleak --format terminal
39
58
 
59
+ # Start the local live dashboard server
60
+ tokenleak --live-server
61
+
40
62
  # Output as JSON
41
63
  tokenleak --format json
42
64
 
@@ -46,12 +68,56 @@ tokenleak --format svg --output usage.svg
46
68
  # Export a PNG image
47
69
  tokenleak --format png --output usage.png
48
70
 
71
+ # Generate your AI Coding Wrapped story card
72
+ tokenleak --format wrapped
73
+ tokenleak --format wrapped --theme light --output my-wrapped.png --open
74
+
75
+ # Launch the interactive AI Wrapped presentation in a browser
76
+ tokenleak --wrapped-live
77
+ tokenleak --wrapped-live --days 365
78
+
79
+ # Get model efficiency recommendations
80
+ tokenleak --advisor
81
+ tokenleak --advisor --days 30 --claude
82
+
49
83
  # Save to a file (format is inferred from the extension)
50
84
  tokenleak -o report.json
51
85
  tokenleak -o heatmap.svg
52
86
  tokenleak -o card.png
87
+
88
+ # Explain one day's usage
89
+ tokenleak explain 2026-03-10
90
+ tokenleak explain 2026-03-10 --format json
91
+
92
+ # Rank deep-work sessions
93
+ tokenleak focus
94
+ tokenleak focus --provider codex --days 30
95
+
96
+ # Show registered providers, availability, and aliases
97
+ tokenleak --list-providers
98
+ ```
99
+
100
+ ### Analysis commands
101
+
102
+ Tokenleak ships two dedicated investigation commands in addition to the main dashboard flow:
103
+
104
+ ```bash
105
+ # Explain what drove a specific day
106
+ tokenleak explain 2026-03-10
107
+
108
+ # Emit the explain report as JSON
109
+ tokenleak explain 2026-03-10 --format json --output explain.json
110
+
111
+ # Rank sessions by deep-work score
112
+ tokenleak focus --days 30
113
+
114
+ # Focus report as JSON
115
+ tokenleak focus --format json --provider pi --output focus.json
53
116
  ```
54
117
 
118
+ - `tokenleak explain <date>` builds a narrative day report with top providers, sessions, projects, models, and anomaly flags.
119
+ - `tokenleak focus` ranks sessions by a deep-work score derived from duration, token density, and project streak.
120
+
55
121
  ### Date filtering
56
122
 
57
123
  By default, Tokenleak shows the last **90 days** of usage.
@@ -80,8 +146,23 @@ tokenleak --provider claude-code
80
146
  # Only Codex
81
147
  tokenleak --provider codex
82
148
 
149
+ # Only Pi
150
+ tokenleak --provider pi
151
+
83
152
  # Multiple providers (comma-separated)
84
- tokenleak --provider claude-code,codex
153
+ tokenleak --provider claude-code,codex,pi
154
+
155
+ # Provider aliases are supported too
156
+ tokenleak --provider anthropic,openai,pi-mono
157
+
158
+ # Shortcut flags
159
+ tokenleak --claude
160
+ tokenleak --codex
161
+ tokenleak --pi
162
+ tokenleak --open-code
163
+
164
+ # Ignore all provider filters and use every available provider
165
+ tokenleak --all-providers
85
166
  ```
86
167
 
87
168
  ### Compare mode
@@ -89,18 +170,83 @@ tokenleak --provider claude-code,codex
89
170
  Compare your usage across two time periods to see how your token consumption has changed:
90
171
 
91
172
  ```bash
92
- # Auto-compare: splits your date range in half
93
- # (e.g. with --days 60, compares last 30 days vs. previous 30 days)
173
+ # Auto-compare: splits your selected date range in half
174
+ # (for example, --days 60 compares the last 30 days against the previous 30 days)
94
175
  tokenleak --compare auto
95
176
 
96
177
  # Compare against a specific previous period
97
178
  tokenleak --compare 2025-01-01..2025-03-31
98
179
 
99
- # Compare outputs deltas for total tokens, cost, streaks, etc.
180
+ # JSON compare output contains periodA, periodB, and deltas
100
181
  tokenleak --compare auto --format json
182
+
183
+ # Compare cards for images use expanded stats automatically
184
+ tokenleak --compare auto --format png --output compare.png
185
+ ```
186
+
187
+ 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.
188
+ When you use `--format json`, the output shape is `periodA`, `periodB`, and `deltas`.
189
+ When you use `--format png` or `--format svg`, Tokenleak enables expanded compare cards automatically.
190
+
191
+ ### AI Coding Wrapped
192
+
193
+ Generate a Spotify-Wrapped-style story card as a tall PNG image showing your AI coding stats, streaks, model usage, habits, achievements, and more.
194
+
195
+ ```bash
196
+ # Generate your wrapped card (dark theme, opens automatically)
197
+ tokenleak --format wrapped --open
198
+
199
+ # Light theme, custom output path
200
+ tokenleak --format wrapped --theme light --output my-wrapped.png
201
+
202
+ # Specific date range
203
+ tokenleak --format wrapped --since 2025-01-01 --until 2025-12-31
204
+ ```
205
+
206
+ 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.
207
+
208
+ 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
+
210
+ The interactive launcher also includes Wrapped as option `3` with a guided setup flow.
211
+
212
+ ### Wrapped Live
213
+
214
+ Launch the AI Wrapped as an interactive 12-slide presentation in your browser with smooth transitions, keyboard/swipe navigation, and progress dots:
215
+
216
+ ```bash
217
+ # Start the wrapped live server (opens on localhost:3456)
218
+ tokenleak --wrapped-live
219
+
220
+ # With a full year of data
221
+ tokenleak --wrapped-live --days 365 --claude
222
+
223
+ # Filter to specific providers
224
+ tokenleak --wrapped-live --provider claude-code,codex
225
+ ```
226
+
227
+ 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
+
229
+ The interactive launcher includes Wrapped Live as option `4`.
230
+
231
+ ### Model Efficiency Advisor
232
+
233
+ Analyze your usage patterns and get actionable recommendations for reducing costs:
234
+
235
+ ```bash
236
+ # Run the advisor (last 90 days by default)
237
+ tokenleak --advisor
238
+
239
+ # Analyze last 30 days, Claude Code only
240
+ tokenleak --advisor --days 30 --claude
101
241
  ```
102
242
 
103
- Compare mode outputs a JSON object with `currentPeriod`, `previousPeriod`, and `deltas` showing the difference between the two periods (positive = increase, negative = decrease).
243
+ The advisor detects three types of opportunities:
244
+
245
+ - **Model downgrades** — identifies expensive models used for short outputs and suggests cheaper alternatives with concrete $/month savings
246
+ - **Cache optimization** — flags low cache hit rates and poor reuse ratios
247
+ - **Usage patterns** — warns about model concentration risk, cost trend increases, and burst days
248
+
249
+ 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
250
 
105
251
  ### Themes
106
252
 
@@ -123,8 +269,18 @@ tokenleak --no-color
123
269
 
124
270
  # Hide the insights panel
125
271
  tokenleak --no-insights
272
+
273
+ # Add expanded analytics to terminal/image/json output
274
+ tokenleak --more
126
275
  ```
127
276
 
277
+ With `--more`, Tokenleak surfaces:
278
+
279
+ - model efficiency scoring with transparent component breakdowns
280
+ - prompt-cache ROI analysis by provider, model, and project
281
+ - session and project drill-down tables
282
+ - attribution clusters that group work by repo/directory and time window
283
+
128
284
  ### Sharing
129
285
 
130
286
  ```bash
@@ -134,32 +290,71 @@ tokenleak --format json --clipboard
134
290
  # Open the output file in your default application after saving
135
291
  tokenleak -o usage.svg --open
136
292
 
293
+ # If no output path is provided for json/svg/png, Tokenleak uses tokenleak.<format>
294
+ tokenleak --format png --open
295
+
137
296
  # Upload to a GitHub Gist (requires gh CLI to be authenticated)
138
297
  tokenleak --format json --upload gist
139
298
  ```
140
299
 
300
+ ## Interactive modes
301
+
302
+ ### Launcher
303
+
304
+ 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.
305
+
306
+ ### Tabbed terminal dashboard
307
+
308
+ The launcher can open a full-screen terminal dashboard with:
309
+
310
+ - time ranges: `7d`, `30d`, `90d`, `365d`
311
+ - metric tabs: `overview`, `sess`, `tok`, `model`, `cwd`, `dow`, `tod`
312
+ - keyboard navigation for scrolling and switching views
313
+
314
+ 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.
315
+
316
+ ### Live dashboard
317
+
318
+ `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.
319
+
141
320
  ## All flags
142
321
 
143
322
  When you run bare `tokenleak` in a real terminal, the launcher shows these flags in-app before you run anything.
144
323
 
145
- | Flag | Alias | Default | Description |
146
- | --------------- | ----- | ---------- | --------------------------------------------------------------- |
147
- | `--format` | `-f` | `terminal` | Output format: `json`, `svg`, `png`, `terminal` |
148
- | `--theme` | `-t` | `dark` | Colour theme: `dark`, `light` |
149
- | `--since` | `-s` | | Start date (`YYYY-MM-DD`). Overrides `--days` |
150
- | `--until` | `-u` | today | End date (`YYYY-MM-DD`) |
151
- | `--days` | `-d` | `90` | Number of days to look back |
152
- | `--output` | `-o` | stdout | Output file path. Format is inferred from extension |
153
- | `--width` | `-w` | `80` | Terminal width for dashboard layout |
154
- | `--no-color` | | `false` | Strip ANSI escape codes from terminal output |
155
- | `--no-insights` | | `false` | Hide the insights panel |
156
- | `--compare` | | | Compare two date ranges. Use `auto` or `YYYY-MM-DD..YYYY-MM-DD` |
157
- | `--provider` | `-p` | all | Filter to specific provider(s), comma-separated |
158
- | `--clipboard` | | `false` | Copy output to clipboard after rendering |
159
- | `--open` | | `false` | Open output file in default app (requires `--output`) |
160
- | `--upload` | | | Upload output to a service. Supported: `gist` |
161
- | `--version` | | | Print version number |
162
- | `--help` | | | Print usage information |
324
+ Subcommands:
325
+
326
+ - `tokenleak explain <date>` supports `--format terminal|json`, `--output`, `--width`, and the standard provider filters.
327
+ - `tokenleak focus` supports `--format terminal|json`, `--output`, `--width`, and the standard provider/date filters.
328
+ - `tokenleak explain --help` and `tokenleak focus --help` print the subcommand-specific help text.
329
+
330
+ | Flag | Alias | Default | Description |
331
+ | --- | --- | --- | --- |
332
+ | `--format` | `-f` | `terminal` | Output format: `json`, `svg`, `png`, `terminal`, `wrapped` |
333
+ | `--theme` | `-t` | `dark` | Theme for `png`, `svg`, and live output: `dark`, `light` |
334
+ | `--since` | `-s` | | Start date (`YYYY-MM-DD`). Overrides `--days` |
335
+ | `--until` | `-u` | today | End date (`YYYY-MM-DD`) |
336
+ | `--days` | `-d` | `90` | Number of trailing days to include |
337
+ | `--output` | `-o` | stdout | Output path. Format is inferred from the file extension when possible |
338
+ | `--width` | `-w` | `80` | Terminal render width |
339
+ | `--provider` | `-p` | auto | Filter to specific provider(s), comma-separated |
340
+ | `--claude` | | `false` | Shortcut for `--provider claude-code` |
341
+ | `--codex` | | `false` | Shortcut for `--provider codex` |
342
+ | `--pi` | | `false` | Shortcut for `--provider pi` |
343
+ | `--open-code` | | `false` | Shortcut for `--provider open-code` |
344
+ | `--all-providers` | | `false` | Ignore provider filters and use every available provider |
345
+ | `--list-providers` | | `false` | Show registered providers, aliases, and availability |
346
+ | `--compare` | | | Compare against `auto` or `YYYY-MM-DD..YYYY-MM-DD` |
347
+ | `--more` | | `false` | Add expanded PNG/SVG stats and include extra summary data in JSON output |
348
+ | `--clipboard` | | `false` | Copy rendered output to the system clipboard |
349
+ | `--open` | | `false` | Open the rendered file in the default app |
350
+ | `--upload` | | | Upload output to a service. Supported: `gist` |
351
+ | `--live-server` | `-L` | `false` | Start the local browser dashboard |
352
+ | `--wrapped-live` | | `false` | Start the interactive AI Wrapped presentation in a browser |
353
+ | `--advisor` | | `false` | Run the model efficiency advisor |
354
+ | `--no-color` | | `false` | Strip ANSI escape codes from terminal output |
355
+ | `--no-insights` | | `false` | Hide terminal insights |
356
+ | `--version` | | | Print version information |
357
+ | `--help` | | | Print usage information |
163
358
 
164
359
  ## Supported providers
165
360
 
@@ -169,9 +364,10 @@ Reads JSONL conversation logs from the Claude Code projects directory. Each assi
169
364
 
170
365
  | | |
171
366
  | ----------------- | -------------------------------------------- |
172
- | **Data location** | `~/.claude/projects/*/*.jsonl` |
367
+ | **Data location** | `~/.claude/projects/**/*.jsonl` |
173
368
  | **Override** | Set `CLAUDE_CONFIG_DIR` environment variable |
174
369
  | **Provider name** | `claude-code` |
370
+ | **Aliases** | `anthropic`, `claude`, `claudecode` |
175
371
 
176
372
  ### Codex
177
373
 
@@ -179,30 +375,45 @@ Reads JSONL session logs from the Codex sessions directory. Parses `response` ev
179
375
 
180
376
  | | |
181
377
  | ----------------- | ------------------------------------- |
182
- | **Data location** | `~/.codex/sessions/*.jsonl` |
378
+ | **Data location** | `~/.codex/sessions/**/*.jsonl` |
183
379
  | **Override** | Set `CODEX_HOME` environment variable |
184
380
  | **Provider name** | `codex` |
381
+ | **Aliases** | `openai` |
185
382
 
186
- ### Open Code
383
+ ### OpenCode
187
384
 
188
- Reads usage data from the Open Code SQLite database. Falls back to legacy JSON session files if no database is found.
385
+ Reads usage data from current OpenCode message storage when available. Falls back to legacy SQLite databases or legacy JSON session files.
189
386
 
190
387
  | | |
191
388
  | ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
192
- | **Data location** | `~/.local/share/opencode/storage/message/<session>/*.json` (primary), `~/.opencode/opencode.db` or `~/.opencode/sessions.db` (legacy), `~/.opencode/sessions/*.json` (legacy fallback) |
389
+ | **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
390
  | **Provider name** | `open-code` |
391
+ | **Aliases** | `opencode`, `open_code` |
392
+
393
+ ### Pi
394
+
395
+ Reads local `pi-mono` session JSONL files. Assistant messages with `usage` metadata are aggregated from the on-disk session history.
396
+
397
+ | | |
398
+ | ----------------- | ------------------------------------------------ |
399
+ | **Data location** | `~/.pi/agent/sessions/**/*.jsonl` |
400
+ | **Override** | Set `PI_CODING_AGENT_DIR` environment variable |
401
+ | **Provider name** | `pi` |
402
+ | **Aliases** | `pi-mono` |
194
403
 
195
404
  ## Output formats
196
405
 
197
406
  ### `terminal` (default)
198
407
 
199
- A full-width dashboard rendered in your terminal with:
408
+ A rendered terminal dashboard with:
200
409
 
201
410
  - GitHub-style heatmap using Unicode block characters (`░▒▓█`)
202
- - Stats panel: current streak, longest streak, total tokens, total cost, 30-day rolling totals, daily averages, cache hit rate
203
- - Day-of-week breakdown showing which days you code most
204
- - Top models ranked by token usage
205
- - Insights: peak day, most active day, top model, top provider
411
+ - overview and provider sections with tokens, cost, streaks, rolling totals, and model leaders
412
+ - day-of-week breakdown showing which days you code most
413
+ - top models ranked by token usage
414
+ - model efficiency and cache ROI sections when `--more` is enabled
415
+ - session/project drill-down and attribution detail in the tabbed dashboard
416
+ - insights such as peak day, top model, and provider mix
206
417
 
207
418
  Falls back to a compact one-liner when terminal width is under 40 characters.
208
419
 
@@ -251,6 +462,45 @@ Structured JSON output containing:
251
462
  "totalCost": 52.5,
252
463
  // ... rolling windows, peaks, averages, day-of-week, top models
253
464
  },
465
+ "more": null
466
+ }
467
+ ```
468
+
469
+ When `--more` is enabled, the `more` field contains expanded metrics such as:
470
+
471
+ - `inputOutput`, `monthlyBurn`, `cacheEconomics`, and `hourOfDay`
472
+ - `modelEfficiency` rankings and ineligible-model reasons
473
+ - `cacheRoi` summary plus provider/model/project ROI breakdowns
474
+ - `sessionMetrics`, `sessionDrilldown`, and `projectDrilldown`
475
+ - `attribution` clusters for repo/directory-oriented work grouping
476
+ - compare metadata when applicable
477
+
478
+ The dedicated analysis commands also support JSON output:
479
+
480
+ ```bash
481
+ tokenleak explain 2026-03-10 --format json
482
+ tokenleak focus --format json
483
+ ```
484
+
485
+ - `tokenleak explain ... --format json` returns an explain report with headline, summary bullets, evidence tables, and anomaly flags.
486
+ - `tokenleak focus ... --format json` returns a ranked focus report with deep-work scores, durations, densities, streaks, and rationales per session.
487
+
488
+ When `--compare` is used with `--format json`, the output is a compare payload with:
489
+
490
+ ```jsonc
491
+ {
492
+ "schemaVersion": 1,
493
+ "generated": "2026-03-14T10:15:00.000Z",
494
+ "periodA": { "range": { "since": "2026-02-15", "until": "2026-03-14" }, "stats": {} },
495
+ "periodB": { "range": { "since": "2026-01-18", "until": "2026-02-14" }, "stats": {} },
496
+ "deltas": {
497
+ "tokens": 125000,
498
+ "cost": 4.8,
499
+ "streak": 3,
500
+ "activeDays": 5,
501
+ "averageDailyTokens": 4200,
502
+ "cacheHitRate": 0.08
503
+ }
254
504
  }
255
505
  ```
256
506
 
@@ -262,10 +512,13 @@ A self-contained SVG image with:
262
512
  - Month labels and day-of-week labels
263
513
  - Stats panel and insights panel
264
514
  - Supports `dark` and `light` themes
515
+ - Supports compare cards and expanded stat panels when `--more` is enabled
265
516
 
266
517
  ### `png`
267
518
 
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 don't support SVG.
519
+ 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.
520
+
521
+ 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
522
 
270
523
  ## Configuration file
271
524
 
@@ -278,7 +531,8 @@ Create `~/.tokenleakrc` to set persistent defaults:
278
531
  "days": 90,
279
532
  "width": 120,
280
533
  "noColor": false,
281
- "noInsights": false
534
+ "noInsights": false,
535
+ "more": false
282
536
  }
283
537
  ```
284
538
 
@@ -288,18 +542,19 @@ All fields are optional. Only include the ones you want to override.
288
542
 
289
543
  ## Environment variables
290
544
 
291
- | Variable | Default | Description |
292
- | ---------------------------------- | ------------------ | ------------------------------------------------------- |
293
- | `TOKENLEAK_FORMAT` | `terminal` | Default output format |
294
- | `TOKENLEAK_THEME` | `dark` | Default colour theme |
295
- | `TOKENLEAK_DAYS` | `90` | Default lookback period in days |
545
+ | Variable | Default | Description |
546
+ | --- | --- | --- |
547
+ | `TOKENLEAK_FORMAT` | `terminal` | Default output format |
548
+ | `TOKENLEAK_THEME` | `dark` | Default theme |
549
+ | `TOKENLEAK_DAYS` | `90` | Default lookback period in days |
296
550
  | `TOKENLEAK_MAX_JSONL_RECORD_BYTES` | `10485760` (10 MB) | Max size of a single JSONL record before it is rejected |
297
- | `CLAUDE_CONFIG_DIR` | `~/.claude` | Claude Code configuration directory |
298
- | `CODEX_HOME` | `~/.codex` | Codex home directory |
551
+ | `CLAUDE_CONFIG_DIR` | `~/.claude` | Claude Code configuration directory |
552
+ | `CODEX_HOME` | `~/.codex` | Codex home directory |
553
+ | `PI_CODING_AGENT_DIR` | `~/.pi/agent` | Pi coding agent directory (sessions live under `sessions/`) |
299
554
 
300
555
  ## What Tokenleak tracks
301
556
 
302
- Tokenleak reads your **local** log files only. It never sends data anywhere (unless you explicitly use `--upload`).
557
+ Tokenleak reads your **local** logs only. It does not send usage data anywhere unless you explicitly use a sharing feature such as `--upload gist`.
303
558
 
304
559
  For each day of usage, it tracks:
305
560
 
@@ -318,8 +573,79 @@ It then computes:
318
573
  - **Cache hit rate** — percentage of input tokens served from cache
319
574
  - **Top models** — models ranked by total token consumption
320
575
  - **Daily averages** — mean tokens and cost per day
576
+ - **Model efficiency** — output-per-dollar, output/input ratio, cache coverage, and a composite score
577
+ - **Prompt-cache ROI** — read savings, write cost, net savings, reuse ratio, and payback ratio
578
+ - **Session and project drill-downs** — duration, dominant models, active days, and streaks
579
+ - **Attribution clusters** — repo/directory-oriented groupings of sessions into investigations or feature work
580
+ - **Explain and focus reports** — narrative daily diagnostics and deep-work session rankings
321
581
 
322
582
 
583
+ ## MCP Server
584
+
585
+ 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.
586
+
587
+ ### Setup
588
+
589
+ Add the server to your MCP client configuration:
590
+
591
+ **Claude Code** (`.mcp.json` in your project or `~/.claude/claude_desktop_config.json`):
592
+
593
+ ```json
594
+ {
595
+ "mcpServers": {
596
+ "tokenleak": {
597
+ "command": "bun",
598
+ "args": ["run", "/path/to/tokenleak/packages/mcp/dist/index.js"]
599
+ }
600
+ }
601
+ }
602
+ ```
603
+
604
+ **Cursor** (Settings > MCP Servers):
605
+
606
+ ```json
607
+ {
608
+ "mcpServers": {
609
+ "tokenleak": {
610
+ "command": "bun",
611
+ "args": ["run", "/path/to/tokenleak/packages/mcp/dist/index.js"]
612
+ }
613
+ }
614
+ }
615
+ ```
616
+
617
+ > Replace `/path/to/tokenleak` with your actual clone path. Make sure to run `bun run build` first.
618
+
619
+ ### Available tools
620
+
621
+ | Tool | Description |
622
+ | --- | --- |
623
+ | `list_providers` | List all registered providers and their availability |
624
+ | `get_usage_summary` | Token/cost summary with streaks, rolling windows, and per-provider breakdown |
625
+ | `get_daily_usage` | Day-by-day usage data for trend analysis (default: 14 days) |
626
+ | `get_cost_breakdown` | Models ranked by cost with token counts and share percentages |
627
+ | `get_streaks_and_habits` | Streaks, day-of-week patterns, peak day, session metrics (default: 90 days) |
628
+ | `compare_periods` | Compare two time periods with deltas for tokens, cost, streaks, and cache rate |
629
+
630
+ 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.
631
+
632
+ ### Available resources
633
+
634
+ | Resource | Description |
635
+ | --- | --- |
636
+ | `tokenleak://overview` | 30-day usage summary as JSON |
637
+ | `tokenleak://provider/{name}` | Per-provider usage data |
638
+
639
+ ### Running the server directly
640
+
641
+ ```bash
642
+ # Build first
643
+ bun run build
644
+
645
+ # Start the MCP server (stdio transport)
646
+ bun packages/mcp/dist/index.js
647
+ ```
648
+
323
649
  ## Project structure
324
650
 
325
651
  ```
@@ -329,6 +655,7 @@ tokenleak/
329
655
  registry/ Provider parsers and model pricing
330
656
  renderers/ JSON, SVG, PNG, and terminal output
331
657
  cli/ CLI entrypoint and config handling
658
+ mcp/ MCP server for AI assistant integration
332
659
  scripts/
333
660
  build-npm.ts Bundles CLI for npm publishing
334
661
  dist/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenleak",
3
- "version": "1.1.0",
3
+ "version": "1.2.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": {