token-rats 0.1.0 → 0.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/LICENSE +21 -0
- package/README.md +27 -54
- package/dist/index.js +1052 -1194
- package/package.json +4 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Token Rats contributors
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
1
|
# token-rats
|
|
2
2
|
|
|
3
|
-
> Strava for AI token burn — sync your Claude Code + Cursor
|
|
3
|
+
> Strava for AI token burn — sync your Claude Code + Cursor usage to your Token Rats leaderboard.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npx token-rats login # one-time auth
|
|
9
|
-
npx token-rats sync #
|
|
9
|
+
npx token-rats sync # upload your usage
|
|
10
10
|
```
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
```
|
|
15
|
-
Install background sync? [Y/n]
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Say yes once and you’re done. A native OS service (launchd on macOS, systemd `--user` on Linux) keeps watching your Claude Code, Cursor, and Codex logs and uploads new sessions automatically. No more `sync` runs, no cron jobs to babysit.
|
|
19
|
-
|
|
20
|
-
For a stable install across reboots, install globally rather than via npx:
|
|
12
|
+
Or install globally:
|
|
21
13
|
|
|
22
14
|
```bash
|
|
23
15
|
npm install -g token-rats
|
|
@@ -29,11 +21,7 @@ token-rats sync
|
|
|
29
21
|
| Command | Description |
|
|
30
22
|
|---|---|
|
|
31
23
|
| `token-rats login` | Open your browser to authenticate (device-code flow). Saves a token to `~/.config/token-rats/token`. |
|
|
32
|
-
| `token-rats sync` | Discover Claude Code
|
|
33
|
-
| `token-rats watch` | Run the watcher in your terminal (Ctrl-C to stop). Useful for debugging. |
|
|
34
|
-
| `token-rats watch --install` | Install the background watcher (launchd / systemd --user). |
|
|
35
|
-
| `token-rats watch --uninstall` | Remove the background watcher. |
|
|
36
|
-
| `token-rats watch --status` | Show whether the watcher is installed and running. |
|
|
24
|
+
| `token-rats sync` | Discover Claude Code logs and the Cursor cache, parse them, and upload counts to your leaderboard. |
|
|
37
25
|
| `token-rats whoami` | Show the currently signed-in account handle. |
|
|
38
26
|
| `token-rats logout` | Delete your stored credentials. |
|
|
39
27
|
| `token-rats --version` | Print the CLI version. |
|
|
@@ -42,42 +30,15 @@ token-rats sync
|
|
|
42
30
|
### Sync flags
|
|
43
31
|
|
|
44
32
|
```
|
|
45
|
-
token-rats sync [--dry-run] [--verbose] [--
|
|
33
|
+
token-rats sync [--dry-run] [--verbose] [--api-url <url>]
|
|
46
34
|
```
|
|
47
35
|
|
|
48
36
|
| Flag | Description |
|
|
49
37
|
|---|---|
|
|
50
38
|
| `--dry-run` | Parse files but do not upload. Prints what would be sent. |
|
|
51
39
|
| `--verbose` | Print which files were discovered and how many records each contains. |
|
|
52
|
-
| `--no-daemon` | Skip the post-sync prompt to install the background watcher. (`TOKEN_RATS_NO_DAEMON=1` does the same globally.) |
|
|
53
40
|
| `--api-url <url>` | Override the API base URL (useful for local dev or staging). |
|
|
54
41
|
|
|
55
|
-
### Watch flags
|
|
56
|
-
|
|
57
|
-
```
|
|
58
|
-
token-rats watch [--install | --uninstall | --status]
|
|
59
|
-
token-rats watch [--interval <ms>] [--verbose]
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
| Flag | Description |
|
|
63
|
-
|---|---|
|
|
64
|
-
| `--install` | Install the background watcher. Idempotent. |
|
|
65
|
-
| `--uninstall` | Remove the background watcher. |
|
|
66
|
-
| `--status` | Print install + running state and the log path. |
|
|
67
|
-
| `--interval <ms>` | Debounce window for file-change uploads. Default: 2000. |
|
|
68
|
-
| `--verbose` | Print per-file change events and uploads. |
|
|
69
|
-
|
|
70
|
-
## Background watcher details
|
|
71
|
-
|
|
72
|
-
- **Sources watched:** Claude Code (`~/.claude/projects/**/*.jsonl`), Codex rollouts, and Cursor's per-workspace SQLite cache.
|
|
73
|
-
- **Cursor polling:** every 90s, `stat()`-first, capped to the 10 most-recently-modified workspaces. Idle CPU is near zero.
|
|
74
|
-
- **macOS:** `~/Library/LaunchAgents/com.tokenrats.watch.plist`. Auto-restarts on crash and runs at login.
|
|
75
|
-
- **Linux:** `~/.config/systemd/user/token-rats-watch.service`. Auto-restarts on crash. For the watcher to survive logout, run once: `sudo loginctl enable-linger $USER`. Without it, the watcher resumes at your next login.
|
|
76
|
-
- **Windows:** not yet supported. Use `token-rats sync` for now.
|
|
77
|
-
- **Logs:** `~/.config/token-rats/logs/watch.log` (or `~/Library/Application Support/token-rats/logs/` on macOS).
|
|
78
|
-
- **Auth expiry:** if your session expires, the watcher backs off 10 minutes instead of crashing. Run `token-rats login` to recover; the watcher picks up on its own.
|
|
79
|
-
- **Upgrades:** when you `npm update -g token-rats`, just run `token-rats sync` once — the daemon re-installs against the new binary path automatically.
|
|
80
|
-
|
|
81
42
|
## What data is collected
|
|
82
43
|
|
|
83
44
|
**Token Rats reads usage counts only.** It reads:
|
|
@@ -99,16 +60,12 @@ Reads `~/.claude/projects/**/*.jsonl` (macOS/Linux) or `%USERPROFILE%\.claude\pr
|
|
|
99
60
|
|
|
100
61
|
### Cursor
|
|
101
62
|
|
|
102
|
-
Reads
|
|
103
|
-
- **macOS:** `~/Library/Application Support
|
|
104
|
-
- **Linux:** `~/.config
|
|
105
|
-
- **Windows:** `%APPDATA
|
|
106
|
-
|
|
107
|
-
Cursor doesn't store token counts on disk for most sessions, so per-request tokens are estimated from request type. Numbers are comparable across Token Rats users but won't match cursor.com to the token. If the Cursor database isn't found or can't be read, the CLI skips it silently.
|
|
63
|
+
Reads the Cursor sqlite cache:
|
|
64
|
+
- **macOS:** `~/Library/Application Support/Cursor/User/globalStorage/state.vscdb`
|
|
65
|
+
- **Linux:** `~/.config/Cursor/User/globalStorage/state.vscdb`
|
|
66
|
+
- **Windows:** `%APPDATA%\Cursor\User\globalStorage\state.vscdb`
|
|
108
67
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Reads rollout JSONL files under `<codex-home>/sessions/YYYY/MM/DD/`. `<codex-home>` defaults to `~/.codex`; Snap and Flatpak distros are also probed.
|
|
68
|
+
If the Cursor database is not found or cannot be read, the CLI skips it silently and continues with Claude Code data.
|
|
112
69
|
|
|
113
70
|
## Auth
|
|
114
71
|
|
|
@@ -128,4 +85,20 @@ Authentication uses a device-code flow:
|
|
|
128
85
|
|
|
129
86
|
Token Rats is open source. The CLI source is in [`packages/cli/`](.) and the parsers are in [`packages/parsers/`](../parsers/). You can inspect exactly what is read from your disk and what is sent to the server.
|
|
130
87
|
|
|
131
|
-
**Privacy posture:** Token Rats reads usage counts only — never prompts or completions. The parser source is in `packages/parsers/`. We literally can't read what you typed.
|
|
88
|
+
**Privacy posture:** Token Rats reads usage counts only — never prompts or completions. The parser source is in `packages/parsers/`. We literally can't read what you typed.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
## Automatic tracking
|
|
92
|
+
|
|
93
|
+
`token-rats login` installs the background tracker. It reads Claude Code,
|
|
94
|
+
Codex, and Cursor records on startup, then checks for changes every 30 seconds.
|
|
95
|
+
Failed uploads are retried. Use `login --no-daemon` to use manual sync only.
|
|
96
|
+
Use `daemon-status` and `uninstall-daemon` to manage automatic tracking.
|
|
97
|
+
After an upgrade, run `install-daemon` to copy the new runtime into place.
|
|
98
|
+
Custom `--api-url` settings are passed to the installed tracker.
|
|
99
|
+
|
|
100
|
+
Open `/app/compare` on your Token Rats server to enter a subscription amount
|
|
101
|
+
for a month. Cursor counts are estimates. API estimates are not provider bills.
|
|
102
|
+
See the [counting method](https://github.com/hsalberti/token-rats/blob/main/docs/counting.md).
|
|
103
|
+
|
|
104
|
+
The CLI and its documentation are MIT licensed. The npm package includes LICENSE.
|