tokenleak 1.2.0 → 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.
Files changed (3) hide show
  1. package/README.md +94 -5
  2. package/package.json +1 -1
  3. package/tokenleak +2060 -1198
package/README.md CHANGED
@@ -1,9 +1,27 @@
1
1
  # Tokenleak
2
2
 
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.
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
  ![Tokenleak preview card](./docs/preview.png)
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:
@@ -93,6 +111,9 @@ tokenleak explain 2026-03-10 --format json
93
111
  tokenleak focus
94
112
  tokenleak focus --provider codex --days 30
95
113
 
114
+ # Authenticate Cursor and sync its local cache
115
+ tokenleak cursor login --name work
116
+
96
117
  # Show registered providers, availability, and aliases
97
118
  tokenleak --list-providers
98
119
  ```
@@ -118,6 +139,54 @@ tokenleak focus --format json --provider pi --output focus.json
118
139
  - `tokenleak explain <date>` builds a narrative day report with top providers, sessions, projects, models, and anomaly flags.
119
140
  - `tokenleak focus` ranks sessions by a deep-work score derived from duration, token density, and project streak.
120
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
181
+ ```
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
+
121
190
  ### Date filtering
122
191
 
123
192
  By default, Tokenleak shows the last **90 days** of usage.
@@ -146,18 +215,22 @@ tokenleak --provider claude-code
146
215
  # Only Codex
147
216
  tokenleak --provider codex
148
217
 
218
+ # Only Cursor
219
+ tokenleak --provider cursor
220
+
149
221
  # Only Pi
150
222
  tokenleak --provider pi
151
223
 
152
224
  # Multiple providers (comma-separated)
153
- tokenleak --provider claude-code,codex,pi
225
+ tokenleak --provider claude-code,codex,cursor,pi
154
226
 
155
227
  # Provider aliases are supported too
156
- tokenleak --provider anthropic,openai,pi-mono
228
+ tokenleak --provider anthropic,openai,cursor-ide,pi-mono
157
229
 
158
230
  # Shortcut flags
159
231
  tokenleak --claude
160
232
  tokenleak --codex
233
+ tokenleak --cursor
161
234
  tokenleak --pi
162
235
  tokenleak --open-code
163
236
 
@@ -325,6 +398,7 @@ Subcommands:
325
398
 
326
399
  - `tokenleak explain <date>` supports `--format terminal|json`, `--output`, `--width`, and the standard provider filters.
327
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.
328
402
  - `tokenleak explain --help` and `tokenleak focus --help` print the subcommand-specific help text.
329
403
 
330
404
  | Flag | Alias | Default | Description |
@@ -339,6 +413,7 @@ Subcommands:
339
413
  | `--provider` | `-p` | auto | Filter to specific provider(s), comma-separated |
340
414
  | `--claude` | | `false` | Shortcut for `--provider claude-code` |
341
415
  | `--codex` | | `false` | Shortcut for `--provider codex` |
416
+ | `--cursor` | | `false` | Shortcut for `--provider cursor` |
342
417
  | `--pi` | | `false` | Shortcut for `--provider pi` |
343
418
  | `--open-code` | | `false` | Shortcut for `--provider open-code` |
344
419
  | `--all-providers` | | `false` | Ignore provider filters and use every available provider |
@@ -356,7 +431,7 @@ Subcommands:
356
431
  | `--version` | | | Print version information |
357
432
  | `--help` | | | Print usage information |
358
433
 
359
- ## Supported providers
434
+ ## Provider details
360
435
 
361
436
  ### Claude Code
362
437
 
@@ -380,6 +455,19 @@ Reads JSONL session logs from the Codex sessions directory. Parses `response` ev
380
455
  | **Provider name** | `codex` |
381
456
  | **Aliases** | `openai` |
382
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.
463
+
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` |
470
+
383
471
  ### OpenCode
384
472
 
385
473
  Reads usage data from current OpenCode message storage when available. Falls back to legacy SQLite databases or legacy JSON session files.
@@ -550,11 +638,12 @@ All fields are optional. Only include the ones you want to override.
550
638
  | `TOKENLEAK_MAX_JSONL_RECORD_BYTES` | `10485760` (10 MB) | Max size of a single JSONL record before it is rejected |
551
639
  | `CLAUDE_CONFIG_DIR` | `~/.claude` | Claude Code configuration directory |
552
640
  | `CODEX_HOME` | `~/.codex` | Codex home directory |
641
+ | `TOKENLEAK_CURSOR_DIR` | `~/.config/tokenleak` | Cursor credentials/cache root (`cursor-credentials.json`, `cursor-cache/`) |
553
642
  | `PI_CODING_AGENT_DIR` | `~/.pi/agent` | Pi coding agent directory (sessions live under `sessions/`) |
554
643
 
555
644
  ## What Tokenleak tracks
556
645
 
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`.
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.
558
647
 
559
648
  For each day of usage, it tracks:
560
649
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokenleak",
3
- "version": "1.2.0",
3
+ "version": "1.3.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": {