token-usage-insights 0.9.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.en.md +770 -0
- package/README.ja.md +770 -0
- package/README.ko.md +770 -0
- package/README.md +797 -0
- package/README.zh-CN.md +770 -0
- package/npm/cli.cjs +30 -0
- package/npm/install.cjs +232 -0
- package/npm/prepublish-check.cjs +133 -0
- package/package.json +47 -0
package/README.en.md
ADDED
|
@@ -0,0 +1,770 @@
|
|
|
1
|
+
# Token War Room
|
|
2
|
+
|
|
3
|
+
**Token War Room is a local-first dashboard for AI coding-agent token usage and session reconstruction.** It reads local records from Google Antigravity CLI, GitHub Copilot CLI, GitHub Copilot Chat (VS Code), Codex Desktop, Codex CLI, Claude Code, Grok Build, Pi Coding Agent, and OMP, presenting daily, monthly, and yearly token consumption, cache usage, reasoning tokens, estimated costs, model distribution, project-directory distribution, and complete session timelines in one place.
|
|
4
|
+
|
|
5
|
+
This project does not call AI provider APIs on your behalf. Its core data sources are local logs, Status Line collector files, and local SQLite.
|
|
6
|
+
|
|
7
|
+
> System support: native PowerShell on Windows 10/11, macOS, Linux, and WSL.
|
|
8
|
+
|
|
9
|
+
Language: [繁體中文](README.md) · [简体中文](README.zh-CN.md) · [English](README.en.md) · [日本語](README.ja.md) · [한국어](README.ko.md)
|
|
10
|
+
|
|
11
|
+
* * *
|
|
12
|
+
|
|
13
|
+
## Quickest path to get started
|
|
14
|
+
|
|
15
|
+
### 1. Start or install the dashboard with one command
|
|
16
|
+
|
|
17
|
+
If Node.js 18.18 or newer is installed, run the dashboard directly without creating a global npm command:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx --yes token-usage-insights
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
To install a persistent system command, use the installer for your platform.
|
|
24
|
+
|
|
25
|
+
Linux / macOS:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
curl -fsSL https://raw.githubusercontent.com/doggy8088/TokenUsageInsights/main/scripts/get.sh | bash && "$HOME/.local/bin/token-usage-insights"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Windows PowerShell:
|
|
32
|
+
|
|
33
|
+
```powershell
|
|
34
|
+
irm https://raw.githubusercontent.com/doggy8088/TokenUsageInsights/main/scripts/get.ps1 | iex; & "$HOME\bin\token-usage-insights.cmd"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Both `npx` and the installers download the compiled version for the current platform. Rust, Cargo, WSL, and manual extraction are not required. The dashboard runs locally after the command starts.
|
|
38
|
+
|
|
39
|
+
Open:
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
http://localhost:3003
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Check whether your tool needs additional setup
|
|
46
|
+
|
|
47
|
+
| Tool | Additional setup | Default data source | Description |
|
|
48
|
+
| --- | --- | --- | --- |
|
|
49
|
+
| Google Antigravity CLI | Required | `~/.gemini/antigravity-cli/usage/usage-YYYY-MM-DD.jsonl` | Collects token data through `statusline-token.sh` or the Windows `statusline-token.ps1` |
|
|
50
|
+
| GitHub Copilot CLI | Required | `~/.copilot/usage/usage-YYYY-MM-DD.jsonl` | Collects token data through `statusline-token.sh` or the Windows `statusline-token.ps1` |
|
|
51
|
+
| GitHub Copilot Chat (VS Code) | Not required | VS Code `workspaceStorage/chatSessions` | The dashboard scans local chat sessions from VS Code Stable and Insiders directly |
|
|
52
|
+
| Codex Desktop / CLI | Not required | `~/.codex/sessions`, `~/.codex/archived_sessions` | The dashboard scans active and archived local Codex sessions directly |
|
|
53
|
+
| Claude Code | Not required | `~/.claude/projects` | The dashboard scans local Claude Code project sessions directly |
|
|
54
|
+
| Grok Build | Not required | `~/.grok/sessions` | The dashboard scans the `updates.jsonl` session streams saved automatically by Grok Build |
|
|
55
|
+
| Pi Coding Agent | Not required | `~/.pi/agent/sessions` | The dashboard scans the local session JSONL files saved automatically by Pi Coding Agent |
|
|
56
|
+
| OMP | Not required | `~/.omp/agent/sessions` | The dashboard scans the local session JSONL files saved automatically by OMP |
|
|
57
|
+
|
|
58
|
+
**If you only use VS Code Copilot, Codex Desktop, Codex CLI, Claude Code, Grok Build, Pi Coding Agent, or OMP, run the one-line installation command and open the dashboard.**
|
|
59
|
+
|
|
60
|
+
### Native Windows usage
|
|
61
|
+
|
|
62
|
+
The Windows one-line installer creates `%USERPROFILE%\bin\token-usage-insights.cmd`; no Rust MSVC toolchain, Visual Studio Build Tools, WSL, Git Bash, or `jq` is required.
|
|
63
|
+
|
|
64
|
+
Windows uses the following native paths by default:
|
|
65
|
+
|
|
66
|
+
| Purpose | Windows default path |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| SQLite | `%LOCALAPPDATA%\TokenUsageInsights\token_usage_insights.db` |
|
|
69
|
+
| Antigravity | `%USERPROFILE%\.gemini\antigravity-cli` |
|
|
70
|
+
| Copilot | `%USERPROFILE%\.copilot` |
|
|
71
|
+
| Codex | `%USERPROFILE%\.codex` |
|
|
72
|
+
| Claude Code | `%USERPROFILE%\.claude` |
|
|
73
|
+
| Cursor | `%USERPROFILE%\.cursor` |
|
|
74
|
+
| Grok Build | `%USERPROFILE%\.grok` |
|
|
75
|
+
| Pi Coding Agent | `%USERPROFILE%\.pi` |
|
|
76
|
+
| OMP | `%USERPROFILE%\.omp` |
|
|
77
|
+
|
|
78
|
+
The dashboard's setup guide shows PowerShell copy, configuration, and diagnostic commands on Windows. The PowerShell collector uses .NET JSON and file APIs and does not depend on Bash, `jq`, `sed`, or `awk`.
|
|
79
|
+
|
|
80
|
+
Drive letters, paths containing spaces or non-ASCII characters, and UNC paths are handled by native path APIs. Keeping the SQLite database on a local disk is still recommended to avoid differences in network-share locking semantics.
|
|
81
|
+
|
|
82
|
+
* * *
|
|
83
|
+
|
|
84
|
+
## Features
|
|
85
|
+
|
|
86
|
+
### Data analysis
|
|
87
|
+
|
|
88
|
+
- Daily, monthly, and yearly token statistics
|
|
89
|
+
- Breakdown of input, output, cache read, cache write, and reasoning tokens
|
|
90
|
+
- Local cost estimates based on `pricing.csv`
|
|
91
|
+
- Session count, request count, and API duration statistics
|
|
92
|
+
- Model usage rankings
|
|
93
|
+
- Cursor sessions can be attributed to specific models from local `state.vscdb` `agentKv` records; unmatched sessions remain `Unknown Model`
|
|
94
|
+
- Project working-directory statistics
|
|
95
|
+
- Sortable session list
|
|
96
|
+
- Automatically reads GitHub Copilot App (desktop app) `~/.copilot/data.db` and `session-store.db`
|
|
97
|
+
|
|
98
|
+
### Session reconstruction
|
|
99
|
+
|
|
100
|
+
- Session timeline in a right-side drawer
|
|
101
|
+
- User prompts, assistant replies, reasoning content, and tool-call steps
|
|
102
|
+
- Tool-call arguments, exit codes, stdout, and stderr
|
|
103
|
+
- Codex subagent fields such as parent session, agent nickname, and agent role
|
|
104
|
+
- Markdown response rendering and content sanitization
|
|
105
|
+
|
|
106
|
+
### Interface
|
|
107
|
+
|
|
108
|
+
- Switch between five CLI badges
|
|
109
|
+
- Daily, monthly, and yearly views
|
|
110
|
+
- Quick date, month, and year switching
|
|
111
|
+
- Automatic live refresh every 5, 10, or 30 seconds
|
|
112
|
+
- Manually sync local logs to SQLite
|
|
113
|
+
- Dark and light themes
|
|
114
|
+
- Traditional Chinese and English interface
|
|
115
|
+
- Model pricing table viewer
|
|
116
|
+
|
|
117
|
+
* * *
|
|
118
|
+
|
|
119
|
+
## URL parameters (deep links)
|
|
120
|
+
|
|
121
|
+
The dashboard supports URL query parameters for opening a specific state directly, making it easy to bookmark, share links, or jump in from other tools. When you switch agent, view, date, working directory, or chart type on the dashboard, the URL is automatically updated to reflect the current state.
|
|
122
|
+
|
|
123
|
+
| Parameter | Applies to | Values | Description |
|
|
124
|
+
| --- | --- | --- | --- |
|
|
125
|
+
| `agent` | All views | `antigravity`, `copilot`, `codex`, `claude`, `cursor`, `grok`, `pi`, `omp` | Selects the coding agent to display. Aliases such as `claude-code`, `grok-build`, and `pi-coding-agent` are also supported |
|
|
126
|
+
| `tab` | All views | `daily`, `monthly`, `yearly` | Selects the daily, monthly, or yearly view |
|
|
127
|
+
| `date` | All views | `daily`: `YYYY-MM-DD`; `monthly`: `YYYY-MM`; `yearly`: `YYYY` | Selects the date, month, or year to display; the format follows `tab` automatically |
|
|
128
|
+
| `dir` | `daily` | Full path, `~`-prefixed home path, or a unique path suffix (e.g. `TokenUsageInsights`) | Filters the daily view by working directory. Windows paths are case-insensitive; if no directory matches, all directories are shown |
|
|
129
|
+
| `chart` | `daily` | `kline`, `trend` | Selects the daily chart type: candlestick (K-line) or trend chart |
|
|
130
|
+
|
|
131
|
+
Examples (`http://localhost:3003` is the default URL; adjust to your actual `HOST`/`PORT`):
|
|
132
|
+
|
|
133
|
+
```text
|
|
134
|
+
http://localhost:3003/?agent=copilot&tab=monthly&date=2026-08
|
|
135
|
+
http://localhost:3003/?agent=codex&tab=yearly&date=2026
|
|
136
|
+
http://localhost:3003/?agent=claude&tab=daily&date=2026-08-09&chart=trend
|
|
137
|
+
http://localhost:3003/?agent=copilot&tab=daily&date=2026-08-09&dir=~/projects/TokenUsageInsights
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
> URL-encode paths that contain `~`, spaces, or non-ASCII characters (`~` can be encoded as `%7E`). Parameters that are not provided fall back to the state from your last visit (Cookie / localStorage).
|
|
141
|
+
|
|
142
|
+
* * *
|
|
143
|
+
|
|
144
|
+
## Google Antigravity CLI setup
|
|
145
|
+
|
|
146
|
+
Antigravity CLI requires connecting this project's Status Line script to `settings.json`. The script writes cumulative and incremental tokens after each conversation to:
|
|
147
|
+
|
|
148
|
+
```text
|
|
149
|
+
~/.gemini/antigravity-cli/usage/usage-YYYY-MM-DD.jsonl
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### 1. Install the collector script
|
|
153
|
+
|
|
154
|
+
After the one-line installation, run:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
mkdir -p ~/.gemini/antigravity-cli && cp ~/.local/share/token-usage-insights/shell/antigravity/statusline-token.sh ~/.gemini/antigravity-cli/statusline-token.sh && chmod +x ~/.gemini/antigravity-cli/statusline-token.sh
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
If you use a custom installation location, replace `~/.local/share/token-usage-insights` in the command with the location specified by `TOKEN_USAGE_INSIGHTS_INSTALL_DIR`.
|
|
161
|
+
|
|
162
|
+
### 2. Configure `~/.gemini/antigravity-cli/settings.json`
|
|
163
|
+
|
|
164
|
+
If the file does not exist, you can create it with the following content. If it already exists, merge only the `statusLine` block; do not overwrite the existing settings.
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"statusLine": {
|
|
169
|
+
"type": "command",
|
|
170
|
+
"command": "/ABSOLUTE/HOME/.gemini/antigravity-cli/statusline-token.sh",
|
|
171
|
+
"padding": 1
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Replace `/ABSOLUTE/HOME` with the actual home-directory path shown by `echo $HOME`, such as `/Users/will` or `/home/will`.
|
|
177
|
+
|
|
178
|
+
### 3. Verify
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
echo '{}' | ~/.gemini/antigravity-cli/statusline-token.sh
|
|
182
|
+
jq . ~/.gemini/antigravity-cli/settings.json
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Afterward, re-enter an Antigravity CLI session. The status line will output a format similar to:
|
|
186
|
+
|
|
187
|
+
```text
|
|
188
|
+
model-name • #3 • input 12.3k • cache 4.5k/0 • output 1.2k • reasoning 500 • total 18.5k
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
* * *
|
|
192
|
+
|
|
193
|
+
## GitHub Copilot CLI setup
|
|
194
|
+
|
|
195
|
+
Like Antigravity CLI, Copilot CLI requires connecting this project's Status Line script to `settings.json`. The script writes token data to:
|
|
196
|
+
|
|
197
|
+
```text
|
|
198
|
+
~/.copilot/usage/usage-YYYY-MM-DD.jsonl
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### 1. Install the collector script
|
|
202
|
+
|
|
203
|
+
After the one-line installation, run:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
mkdir -p ~/.copilot && cp ~/.local/share/token-usage-insights/shell/copilot/statusline-token.sh ~/.copilot/statusline-token.sh && chmod +x ~/.copilot/statusline-token.sh
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
If you use a custom installation location, replace `~/.local/share/token-usage-insights` in the command with the location specified by `TOKEN_USAGE_INSIGHTS_INSTALL_DIR`.
|
|
210
|
+
|
|
211
|
+
### 2. Configure `~/.copilot/settings.json`
|
|
212
|
+
|
|
213
|
+
If the file does not exist, you can create it with the following content. If it already exists, merge only the `statusLine` block; do not overwrite the existing settings.
|
|
214
|
+
|
|
215
|
+
```json
|
|
216
|
+
{
|
|
217
|
+
"statusLine": {
|
|
218
|
+
"type": "command",
|
|
219
|
+
"command": "/ABSOLUTE/HOME/.copilot/statusline-token.sh",
|
|
220
|
+
"padding": 1
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Replace `/ABSOLUTE/HOME` with the actual home-directory path shown by `echo $HOME`.
|
|
226
|
+
|
|
227
|
+
### 3. Verify
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
echo '{}' | ~/.copilot/statusline-token.sh
|
|
231
|
+
jq . ~/.copilot/settings.json
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Afterward, re-enter a Copilot CLI session. The status line will begin outputting and accumulating token data.
|
|
235
|
+
|
|
236
|
+
* * *
|
|
237
|
+
|
|
238
|
+
## GitHub Copilot App (desktop app)
|
|
239
|
+
|
|
240
|
+
**Copilot App (Tauri desktop app) requires no setup.** The dashboard automatically reads local `~/.copilot/data.db` and `~/.copilot/session-store.db`, then combines App session token usage with CLI / VS Code usage on the Copilot page. The session list labels the source as `App`, distinct from `CLI` and `VS Code`.
|
|
241
|
+
|
|
242
|
+
- During each background sync (every 5 seconds), the dashboard checks both SQLite databases and incrementally syncs with a composite `(created_at, id)` cursor. This avoids duplicate upserts for multiple events with the same timestamp, and the same `(session_id, turn_index)` is never written twice.
|
|
243
|
+
- App `assistant_usage_events` has per-API-call granularity. The dashboard aggregates by session, turn, agent, and model, preserves multi-model attribution within the same turn, and uses per-turn statistics for the timeline.
|
|
244
|
+
- Session titles come from `data.db.sessions.title`.
|
|
245
|
+
|
|
246
|
+
If App and CLI use separate directories, or if you use a non-default directory, set the environment variable:
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
COPILOT_APP_DIR="/path/to/copilot-app-data" token-usage-insights
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`COPILOT_APP_DIR` takes precedence over `COPILOT_DIR` and falls back to `~/.copilot` when unset.
|
|
253
|
+
|
|
254
|
+
* * *
|
|
255
|
+
|
|
256
|
+
## GitHub Copilot Chat (VS Code) setup
|
|
257
|
+
|
|
258
|
+
**VS Code Copilot Chat requires no Status Line, hook, or additional collector script.** The dashboard reads chat sessions in local `workspaceStorage` directly and combines them with Copilot CLI data; the session list labels the source as `VS Code` or `CLI`.
|
|
259
|
+
|
|
260
|
+
VS Code Stable and Insiders are supported:
|
|
261
|
+
|
|
262
|
+
| Platform | Stable | Insiders |
|
|
263
|
+
| --- | --- | --- |
|
|
264
|
+
| Windows | `%APPDATA%\Code\User\workspaceStorage` | `%APPDATA%\Code - Insiders\User\workspaceStorage` |
|
|
265
|
+
| macOS | `~/Library/Application Support/Code/User/workspaceStorage` | `~/Library/Application Support/Code - Insiders/User/workspaceStorage` |
|
|
266
|
+
| Linux | `~/.config/Code/User/workspaceStorage` | `~/.config/Code - Insiders/User/workspaceStorage` |
|
|
267
|
+
|
|
268
|
+
Usage:
|
|
269
|
+
|
|
270
|
+
1. Use GitHub Copilot Chat in VS Code to create at least one chat session.
|
|
271
|
+
2. Start the dashboard or click the sync button in the upper-right corner.
|
|
272
|
+
3. View the combined statistics and session timeline on the Copilot page.
|
|
273
|
+
|
|
274
|
+
The dashboard fully backfills existing `chatSessions` files and resynchronizes them when file size or modification time changes. Chat sessions without token fields are still shown with a token count of 0. Only local chat files are read; cloud sessions, Remote SSH hosts, and `state.vscdb` are not included.
|
|
275
|
+
|
|
276
|
+
If VS Code uses `--user-data-dir` or Portable Mode, specify a custom data root for the dashboard:
|
|
277
|
+
|
|
278
|
+
macOS / Linux:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
VSCODE_USER_DATA_DIR="/path/to/vscode-user-data" token-usage-insights
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Windows PowerShell:
|
|
285
|
+
|
|
286
|
+
```powershell
|
|
287
|
+
$env:VSCODE_USER_DATA_DIR = "C:\path\to\vscode-user-data"; & "$HOME\bin\token-usage-insights.cmd"
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
`VSCODE_USER_DATA_DIR` should point to the VS Code user-data directory containing `User/workspaceStorage`. If the environment variable points to the `data` directory in Portable Mode, use `VSCODE_PORTABLE_DATA_DIR` instead; the dashboard checks both `data/user-data/User/workspaceStorage` and `data/User/workspaceStorage`.
|
|
291
|
+
|
|
292
|
+
* * *
|
|
293
|
+
|
|
294
|
+
## Codex setup
|
|
295
|
+
|
|
296
|
+
**Neither Codex Desktop nor Codex CLI requires hooks, a Status Line, or an additional collector script.**
|
|
297
|
+
|
|
298
|
+
The dashboard scans these directories directly:
|
|
299
|
+
|
|
300
|
+
```text
|
|
301
|
+
~/.codex/sessions
|
|
302
|
+
~/.codex/archived_sessions
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Usage:
|
|
306
|
+
|
|
307
|
+
1. Use Codex Desktop or Codex CLI normally to create at least one session.
|
|
308
|
+
2. Start this project.
|
|
309
|
+
3. Select Codex on the left.
|
|
310
|
+
4. Click the sync button in the upper-right corner, or wait for background sync.
|
|
311
|
+
|
|
312
|
+
Notes:
|
|
313
|
+
|
|
314
|
+
- Codex credentials continue to be managed by Codex itself.
|
|
315
|
+
- The dashboard only reads local session records for analysis.
|
|
316
|
+
- Each session displays a `Desktop` or `CLI` source label based on the transcript `originator`; old formats that cannot be identified remain uncategorized.
|
|
317
|
+
- If API quota information is shown, it comes from the latest local session log, not a real-time online query.
|
|
318
|
+
|
|
319
|
+
* * *
|
|
320
|
+
|
|
321
|
+
## Claude Code setup
|
|
322
|
+
|
|
323
|
+
**Claude Code requires no hooks, a Status Line, or an additional collector script.**
|
|
324
|
+
|
|
325
|
+
The dashboard scans this directory directly:
|
|
326
|
+
|
|
327
|
+
```text
|
|
328
|
+
~/.claude/projects
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Usage:
|
|
332
|
+
|
|
333
|
+
1. Use Claude Code normally to create at least one project session.
|
|
334
|
+
2. Start this project.
|
|
335
|
+
3. Select Claude Code on the left.
|
|
336
|
+
4. Click the sync button in the upper-right corner, or wait for background sync.
|
|
337
|
+
|
|
338
|
+
Notes:
|
|
339
|
+
|
|
340
|
+
- Claude Code credentials continue to be managed by Claude Code itself.
|
|
341
|
+
- The dashboard only reads local project session records for analysis.
|
|
342
|
+
- If `~/.claude/projects` does not exist, the Claude Code page shows no data.
|
|
343
|
+
|
|
344
|
+
* * *
|
|
345
|
+
|
|
346
|
+
## Grok Build setup
|
|
347
|
+
|
|
348
|
+
**Grok Build requires no hooks, a Status Line, or an additional collector script.** The dashboard scans this directory directly:
|
|
349
|
+
|
|
350
|
+
```text
|
|
351
|
+
~/.grok/sessions
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
It uses the Session stream saved internally by Grok Build; it does not read the old-format
|
|
355
|
+
`~/.Grok/build/usage/usage-YYYY-MM-DD.jsonl`, nor does it require
|
|
356
|
+
`statusLine` in `~/.Grok/build/settings.json`.
|
|
357
|
+
|
|
358
|
+
Usage:
|
|
359
|
+
|
|
360
|
+
1. Use Grok Build normally to create at least one session.
|
|
361
|
+
2. Start this project.
|
|
362
|
+
3. Select Grok Build on the left.
|
|
363
|
+
4. Click the sync button in the upper-right corner, or wait for background sync.
|
|
364
|
+
|
|
365
|
+
A Grok Build session may provide only a context token snapshot, or may also include provider usage and cost. The dashboard prioritizes provider usage/cost; when only a context snapshot is available, cost is estimated using the xAI API prices in `pricing.csv` and the session list labels it `Context`. This does not represent the weekly quota of SuperGrok or other subscription plans.
|
|
366
|
+
|
|
367
|
+
* * *
|
|
368
|
+
|
|
369
|
+
## Pi Coding Agent setup
|
|
370
|
+
|
|
371
|
+
**Pi Coding Agent requires no hooks, a Status Line, or an additional collector script.** The dashboard scans this directory directly:
|
|
372
|
+
|
|
373
|
+
```text
|
|
374
|
+
~/.pi/agent/sessions
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
Pi Coding Agent automatically saves sessions as local JSONL files in a tree-structured directory layout, and the dashboard reads those session records directly.
|
|
378
|
+
|
|
379
|
+
Usage:
|
|
380
|
+
|
|
381
|
+
1. Use Pi Coding Agent normally to create at least one session.
|
|
382
|
+
2. Start or refresh the dashboard.
|
|
383
|
+
3. Select Pi Coding Agent on the left.
|
|
384
|
+
4. Click the sync button in the upper-right corner, or wait for background sync.
|
|
385
|
+
|
|
386
|
+
Pi Coding Agent cost is always read directly from each session's own per-turn `usage.cost` and related usage data. Unlike Grok Build, there is no context-snapshot estimation fallback because Pi natively reports authoritative token and cost usage per turn.
|
|
387
|
+
|
|
388
|
+
* * *
|
|
389
|
+
|
|
390
|
+
## OMP setup
|
|
391
|
+
|
|
392
|
+
**OMP requires no hooks, a Status Line, or an additional collector script.** The dashboard scans this directory directly:
|
|
393
|
+
|
|
394
|
+
```text
|
|
395
|
+
~/.omp/agent/sessions
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
OMP is an open-source fork of Pi Coding Agent (<https://github.com/can1357/oh-my-pi>) and persists sessions using the identical JSONL format. The dashboard reads those local session records directly.
|
|
399
|
+
|
|
400
|
+
Usage:
|
|
401
|
+
|
|
402
|
+
1. Use OMP normally to create at least one session.
|
|
403
|
+
2. Start or refresh the dashboard.
|
|
404
|
+
3. Select OMP on the left.
|
|
405
|
+
4. Click the sync button in the upper-right corner, or wait for background sync.
|
|
406
|
+
|
|
407
|
+
OMP cost is always read directly from each session's own per-turn `usage.cost` and related usage data. Unlike Grok Build, there is no context-snapshot estimation fallback because OMP natively reports authoritative token and cost usage per turn.
|
|
408
|
+
|
|
409
|
+
* * *
|
|
410
|
+
|
|
411
|
+
## Local data synchronization
|
|
412
|
+
|
|
413
|
+
When the service starts, the backend initializes local SQLite and performs an immediate data sync. After startup, it also syncs in the background every 5 seconds.
|
|
414
|
+
|
|
415
|
+
Default SQLite location:
|
|
416
|
+
|
|
417
|
+
```text
|
|
418
|
+
~/.token-usage-insights/token_usage_insights.db
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
The sync button in the upper-right corner of the frontend calls:
|
|
422
|
+
|
|
423
|
+
```text
|
|
424
|
+
GET /api/:assistant/sync
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
This triggers a full incremental sync of local logs.
|
|
428
|
+
|
|
429
|
+
## Import / export (cross-machine aggregation)
|
|
430
|
+
|
|
431
|
+
**For normal use, use the export and import buttons in the upper-right corner of the dashboard.** The installed version needs only a browser to aggregate data across machines and supports import files up to 200 MB.
|
|
432
|
+
|
|
433
|
+
The dashboard and CLI now share the `token-usage-insights` executable. Run it without arguments to start the dashboard, or use `export`, `export-all`, or `import`. The main command and subcommands support `--help` and `-h`. This integration will be included in the next release; older installations need an update or a source build.
|
|
434
|
+
|
|
435
|
+
`--agent` specifies the assistant (`antigravity` / `copilot` / `codex` / `claude` / `cursor` / `grok` / `pi` / `omp`).
|
|
436
|
+
|
|
437
|
+
### Use the CLI from source
|
|
438
|
+
|
|
439
|
+
Build it once:
|
|
440
|
+
|
|
441
|
+
```bash
|
|
442
|
+
cargo build --release --bin token-usage-insights
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
```bash
|
|
446
|
+
# 匯出日、月或年資料(輸出 JSON,含匯入唯一 id)
|
|
447
|
+
./target/release/token-usage-insights export --agent codex --date 2026-07 --out monthly-codex-2026-07.json
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
```bash
|
|
451
|
+
# 匯入檔案中的所有資料;每筆資料依 timestamp 決定日期
|
|
452
|
+
./target/release/token-usage-insights import --agent codex --file monthly-codex-2026-07.json
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
```bash
|
|
456
|
+
# 取得 CLI usage 說明
|
|
457
|
+
./target/release/token-usage-insights --help
|
|
458
|
+
./target/release/token-usage-insights export --help
|
|
459
|
+
./target/release/token-usage-insights import --help
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
The data format matches the frontend and contains these fields:
|
|
463
|
+
|
|
464
|
+
- `version`
|
|
465
|
+
- `assistant`
|
|
466
|
+
- `date`
|
|
467
|
+
- `exported_at`
|
|
468
|
+
- `records` (each record has `import_source_id`)
|
|
469
|
+
|
|
470
|
+
`import_source_id` forms a unique key together with `assistant_type`. Re-importing the same record is detected as a duplicate and skipped automatically, so it is not written to the database twice.
|
|
471
|
+
|
|
472
|
+
* * *
|
|
473
|
+
|
|
474
|
+
## Environment variables
|
|
475
|
+
|
|
476
|
+
Paths specified by environment variables are authoritative and do not need to be created in advance; `INSIGHTS_DIR` is created automatically at startup. Native absolute/relative paths are supported, as are common forms beginning with `~`, `$HOME`, `%USERPROFILE%`, `%LOCALAPPDATA%`, or `%APPDATA%`.
|
|
477
|
+
|
|
478
|
+
| Variable | Default | Purpose |
|
|
479
|
+
| --- | --- | --- |
|
|
480
|
+
| `HOST` | `0.0.0.0` | IPv4 or IPv6 address to which the dashboard service binds |
|
|
481
|
+
| `PORT` | `3003` | Dashboard service port |
|
|
482
|
+
| `INSIGHTS_DIR` | Windows: `%LOCALAPPDATA%\TokenUsageInsights`; other platforms: `~/.token-usage-insights` | SQLite database directory |
|
|
483
|
+
| `ANTIGRAVITY_DIR` | `~/.gemini/antigravity-cli` | Antigravity CLI data directory |
|
|
484
|
+
| `COPILOT_DIR` | `~/.copilot` | Copilot CLI data directory |
|
|
485
|
+
| `COPILOT_APP_DIR` | Same as `COPILOT_DIR` | Copilot App (desktop app) data directory; should contain `data.db` and `session-store.db` |
|
|
486
|
+
| `VSCODE_USER_DATA_DIR` | Auto-detected by platform | VS Code user-data directory; should contain `User/workspaceStorage` |
|
|
487
|
+
| `VSCODE_PORTABLE_DATA_DIR` | Not set | VS Code Portable Mode `data` directory |
|
|
488
|
+
| `CODEX_DIR` | `~/.codex` | Shared data directory for Codex Desktop and Codex CLI |
|
|
489
|
+
| `CLAUDE_DIR` | `~/.claude` | Claude Code data directory |
|
|
490
|
+
| `CURSOR_DIR` | `~/.cursor` | Cursor data directory |
|
|
491
|
+
| `CURSOR_STATE_DB` | Auto-detected by platform | Cursor `User/globalStorage/state.vscdb` path, used to read `agentKv` model information in read-only mode |
|
|
492
|
+
| `GROK_DIR` | `~/.grok` | Grok Build data directory |
|
|
493
|
+
| `PI_DIR` | `~/.pi` | Pi Coding Agent data directory |
|
|
494
|
+
| `OMP_DIR` | `~/.omp` | OMP data directory |
|
|
495
|
+
| `CORS_ALLOWED_ORIGINS` | `http://localhost:<PORT>,http://127.0.0.1:<PORT>` | Comma-separated allowed CORS origins |
|
|
496
|
+
|
|
497
|
+
> **The default binding is `0.0.0.0`, so other devices on the same local network may connect to the dashboard. For local-only browsing, set `HOST` to `127.0.0.1`.**
|
|
498
|
+
|
|
499
|
+
Example:
|
|
500
|
+
|
|
501
|
+
```bash
|
|
502
|
+
HOST="127.0.0.1" INSIGHTS_DIR="/tmp/token-usage-insights" PORT="3010" "$HOME/.local/bin/token-usage-insights"
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
Windows PowerShell example:
|
|
506
|
+
|
|
507
|
+
```powershell
|
|
508
|
+
$env:HOST = '127.0.0.1'; $env:INSIGHTS_DIR = 'D:\Token Usage Insights\資料庫'; $env:CODEX_DIR = "$env:USERPROFILE\.codex"; $env:PORT = '3010'; & "$HOME\bin\token-usage-insights.cmd"
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
* * *
|
|
512
|
+
|
|
513
|
+
## Background service
|
|
514
|
+
|
|
515
|
+
### Linux: install and enable the systemd user service with one command
|
|
516
|
+
|
|
517
|
+
```bash
|
|
518
|
+
curl -fsSL https://raw.githubusercontent.com/doggy8088/TokenUsageInsights/main/scripts/get.sh | bash -s -- --service
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
This downloads the installed version and immediately enables `token-usage-insights.service`; you do not need to build or edit a systemd file yourself.
|
|
522
|
+
|
|
523
|
+
### Manage the service
|
|
524
|
+
|
|
525
|
+
```bash
|
|
526
|
+
systemctl --user status token-usage-insights.service
|
|
527
|
+
journalctl --user -u token-usage-insights.service -n 50 -f
|
|
528
|
+
systemctl --user restart token-usage-insights.service
|
|
529
|
+
systemctl --user stop token-usage-insights.service
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
* * *
|
|
533
|
+
|
|
534
|
+
## Installation options and manual installation
|
|
535
|
+
|
|
536
|
+
GitHub Releases provide compiled executables for Linux, macOS, and Windows. Rust or Cargo is not required for installation or execution.
|
|
537
|
+
|
|
538
|
+
### Optional one-line installer parameters
|
|
539
|
+
|
|
540
|
+
`scripts/get.sh` (Linux / macOS) and `scripts/get.ps1` (Windows) automatically detect the platform and CPU architecture, download the matching archive from the latest (or specified) Release, extract it, and call the packaged `install.sh` / `install.ps1`; no manual download or extraction is required:
|
|
541
|
+
|
|
542
|
+
Linux / macOS:
|
|
543
|
+
|
|
544
|
+
```bash
|
|
545
|
+
curl -fsSL https://raw.githubusercontent.com/doggy8088/TokenUsageInsights/main/scripts/get.sh | bash
|
|
546
|
+
```
|
|
547
|
+
|
|
548
|
+
To install and enable the systemd user service at the same time on Linux:
|
|
549
|
+
|
|
550
|
+
```bash
|
|
551
|
+
curl -fsSL https://raw.githubusercontent.com/doggy8088/TokenUsageInsights/main/scripts/get.sh | bash -s -- --service
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
Windows PowerShell:
|
|
555
|
+
|
|
556
|
+
```powershell
|
|
557
|
+
irm https://raw.githubusercontent.com/doggy8088/TokenUsageInsights/main/scripts/get.ps1 | iex
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
After installation, run (on Linux/macOS, confirm that `bin_dir` is on `PATH`; Windows creates a `.cmd` shim):
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
token-usage-insights
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
Environment variables can control the version and installation paths (all optional):
|
|
567
|
+
|
|
568
|
+
| Variable | Platforms | Description |
|
|
569
|
+
| --- | --- | --- |
|
|
570
|
+
| `TOKEN_USAGE_INSIGHTS_VERSION` | Linux / macOS / Windows | Release tag to install, such as `v0.6.2`; defaults to `latest` |
|
|
571
|
+
| `TOKEN_USAGE_INSIGHTS_INSTALL_DIR` | Linux / macOS | Installation directory, passed to `install.sh` |
|
|
572
|
+
| `TOKEN_USAGE_INSIGHTS_BIN_DIR` | Linux / macOS | Executable-link directory, passed to `install.sh` |
|
|
573
|
+
|
|
574
|
+
To customize the installation location, bin directory, and port on Windows, first download the script and then run it with parameters (`iex` pipelines do not support parameters):
|
|
575
|
+
|
|
576
|
+
```powershell
|
|
577
|
+
Invoke-WebRequest -Uri https://raw.githubusercontent.com/doggy8088/TokenUsageInsights/main/scripts/get.ps1 -OutFile get.ps1
|
|
578
|
+
.\get.ps1 -InstallDir 'D:\Apps\Token Usage Insights' -Port 3010
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
### Manual download and installation
|
|
582
|
+
|
|
583
|
+
If you do not want to execute a remote script directly, download the archive for your platform manually and run the installation script included in the package. Each Release archive contains:
|
|
584
|
+
|
|
585
|
+
- A single-platform executable
|
|
586
|
+
- Frontend assets in `static/`
|
|
587
|
+
- The model pricing table `pricing.csv`
|
|
588
|
+
- Status Line and service scripts in `shell/`
|
|
589
|
+
- The `scripts/` directory (including `install.sh`, `install.ps1`, `get.sh`, and `get.ps1`)
|
|
590
|
+
- README, LICENSE, and VERSION
|
|
591
|
+
|
|
592
|
+
Linux or macOS:
|
|
593
|
+
|
|
594
|
+
```bash
|
|
595
|
+
tar -xzf token-usage-insights-<tag>-<target>.tar.gz
|
|
596
|
+
cd token-usage-insights-<tag>-<target>
|
|
597
|
+
./install.sh
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
To install and enable the systemd user service on Linux:
|
|
601
|
+
|
|
602
|
+
```bash
|
|
603
|
+
./install.sh --service
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
Windows:
|
|
607
|
+
|
|
608
|
+
```powershell
|
|
609
|
+
Expand-Archive token-usage-insights-<tag>-x86_64-pc-windows-msvc.zip
|
|
610
|
+
cd token-usage-insights-<tag>-x86_64-pc-windows-msvc
|
|
611
|
+
powershell -ExecutionPolicy Bypass -File .\install.ps1
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
Custom Windows installation location and port:
|
|
615
|
+
|
|
616
|
+
```powershell
|
|
617
|
+
.\install.ps1 -InstallDir 'D:\Apps\Token Usage Insights' -BinDir "$HOME\bin" -Port 3010
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
### CI verification
|
|
621
|
+
|
|
622
|
+
The `Release` workflow runs the corresponding installation script (`install.sh` / `install.ps1`) on Linux, macOS, and Windows for every build, then starts the executable and verifies that:
|
|
623
|
+
|
|
624
|
+
- The service responds to `/api/<assistant>/pricing` on the specified port
|
|
625
|
+
- The response actually loads the `pricing.csv` packaged with the application
|
|
626
|
+
- A new `INSIGHTS_DIR` is created and an SQLite database is generated
|
|
627
|
+
|
|
628
|
+
`get.sh` and `get.ps1` also undergo syntax checks (`bash -n` and PowerShell AST parsing) before every build, ensuring the version published to the Release can run correctly.
|
|
629
|
+
|
|
630
|
+
### Maintainer release
|
|
631
|
+
|
|
632
|
+
After pushing a Git tag, GitHub Actions automatically creates the corresponding Release:
|
|
633
|
+
|
|
634
|
+
```bash
|
|
635
|
+
git tag vX.Y.Z
|
|
636
|
+
git push origin vX.Y.Z
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
* * *
|
|
640
|
+
|
|
641
|
+
## Legacy data migration
|
|
642
|
+
|
|
643
|
+
If you previously used any of the following standalone projects, this project automatically attempts to migrate the old SQLite data at startup:
|
|
644
|
+
|
|
645
|
+
- `~/.gemini/antigravity-cli/antigravity_cli_token_insights.db`
|
|
646
|
+
- `~/.copilot/copilot_cli_token_insights.db`
|
|
647
|
+
- `~/.codex/codex_cli_token_insights.db`
|
|
648
|
+
|
|
649
|
+
After a successful migration, the old database is renamed with a `.bak` suffix.
|
|
650
|
+
|
|
651
|
+
Once you have confirmed that migration is complete, you can disable the old services:
|
|
652
|
+
|
|
653
|
+
```bash
|
|
654
|
+
systemctl --user stop copilot-cli-token-insights.service
|
|
655
|
+
systemctl --user disable copilot-cli-token-insights.service
|
|
656
|
+
systemctl --user stop antigravity-cli-token-insights.service
|
|
657
|
+
systemctl --user disable antigravity-cli-token-insights.service
|
|
658
|
+
systemctl --user stop codex-cli-token-insights.service
|
|
659
|
+
systemctl --user disable codex-cli-token-insights.service
|
|
660
|
+
|
|
661
|
+
rm -f ~/.config/systemd/user/copilot-cli-token-insights.service
|
|
662
|
+
rm -f ~/.config/systemd/user/antigravity-cli-token-insights.service
|
|
663
|
+
rm -f ~/.config/systemd/user/codex-cli-token-insights.service
|
|
664
|
+
|
|
665
|
+
systemctl --user daemon-reload
|
|
666
|
+
systemctl --user reset-failed
|
|
667
|
+
```
|
|
668
|
+
|
|
669
|
+
* * *
|
|
670
|
+
|
|
671
|
+
## Troubleshooting
|
|
672
|
+
|
|
673
|
+
### Dashboard has no data
|
|
674
|
+
|
|
675
|
+
Check whether the data source exists for each tool:
|
|
676
|
+
|
|
677
|
+
```bash
|
|
678
|
+
ls ~/.gemini/antigravity-cli/usage
|
|
679
|
+
ls ~/.copilot/usage
|
|
680
|
+
ls ~/.codex/sessions
|
|
681
|
+
ls ~/.codex/archived_sessions
|
|
682
|
+
ls ~/.claude/projects
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
Antigravity CLI and Copilot CLI also require `settings.json` to define `statusLine` and the scripts to have execute permission.
|
|
686
|
+
|
|
687
|
+
On Windows PowerShell, inspect the native data directories directly:
|
|
688
|
+
|
|
689
|
+
```powershell
|
|
690
|
+
Get-ChildItem "$env:USERPROFILE\.gemini\antigravity-cli\usage"
|
|
691
|
+
Get-ChildItem "$env:USERPROFILE\.copilot\usage"
|
|
692
|
+
Get-ChildItem "$env:USERPROFILE\.codex\sessions"
|
|
693
|
+
Get-ChildItem "$env:USERPROFILE\.codex\archived_sessions"
|
|
694
|
+
Get-ChildItem "$env:USERPROFILE\.claude\projects"
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
### Status Line script cannot run
|
|
698
|
+
|
|
699
|
+
```bash
|
|
700
|
+
command -v jq
|
|
701
|
+
chmod +x ~/.gemini/antigravity-cli/statusline-token.sh
|
|
702
|
+
chmod +x ~/.copilot/statusline-token.sh
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
The Status Line scripts depend on `jq` to parse the JSON passed by the CLI.
|
|
706
|
+
|
|
707
|
+
The `jq` requirement above applies only to `.sh` collectors. You can test the Windows `.ps1` collector with the following command; it natively handles backslashes and paths containing spaces:
|
|
708
|
+
|
|
709
|
+
```powershell
|
|
710
|
+
Write-Output '{}' | powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.gemini\antigravity-cli\statusline-token.ps1" -Assistant antigravity
|
|
711
|
+
```
|
|
712
|
+
|
|
713
|
+
### Configuration file has invalid JSON
|
|
714
|
+
|
|
715
|
+
```bash
|
|
716
|
+
jq . ~/.gemini/antigravity-cli/settings.json
|
|
717
|
+
jq . ~/.copilot/settings.json
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
If you already have other settings, merge the `statusLine` object instead of replacing the entire file with an array or plain string.
|
|
721
|
+
|
|
722
|
+
### Cannot connect to `localhost:3003`
|
|
723
|
+
|
|
724
|
+
```bash
|
|
725
|
+
PORT=3010 "$HOME/.local/bin/token-usage-insights"
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
If you use another port, open the corresponding URL, for example:
|
|
729
|
+
|
|
730
|
+
```text
|
|
731
|
+
http://localhost:3010
|
|
732
|
+
```
|
|
733
|
+
|
|
734
|
+
* * *
|
|
735
|
+
|
|
736
|
+
## Development commands
|
|
737
|
+
|
|
738
|
+
This section is for developers who need to modify or build the project from source. For normal use, use the one-line installation command above.
|
|
739
|
+
|
|
740
|
+
```bash
|
|
741
|
+
git clone https://github.com/doggy8088/TokenUsageInsights.git
|
|
742
|
+
cd TokenUsageInsights
|
|
743
|
+
cargo fmt
|
|
744
|
+
cargo test
|
|
745
|
+
cargo clippy --all-targets --all-features
|
|
746
|
+
cargo build --release
|
|
747
|
+
./target/release/token-usage-insights
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
* * *
|
|
751
|
+
|
|
752
|
+
## Project files
|
|
753
|
+
|
|
754
|
+
```text
|
|
755
|
+
src/ Rust 後端、API、SQLite 同步、價格與時間軸解析
|
|
756
|
+
static/ 前端 HTML、JavaScript、CSS 與圖片資產
|
|
757
|
+
shell/ Bash/PowerShell Status Line collector 與 systemd 服務範本
|
|
758
|
+
scripts/ Linux/macOS、Windows 安裝與 Windows smoke test
|
|
759
|
+
pricing.csv 模型價格表,本地估算費用依此檔案載入
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
* * *
|
|
763
|
+
|
|
764
|
+
## Screenshots
|
|
765
|
+
|
|
766
|
+

|
|
767
|
+
|
|
768
|
+

|
|
769
|
+
|
|
770
|
+

|