@statforge/claudestat 1.4.0 → 1.5.1

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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +130 -547
  3. package/dist/cost-projector.d.ts +24 -0
  4. package/dist/cost-projector.js +133 -0
  5. package/dist/daemon.js +2 -2
  6. package/dist/db.d.ts +4 -0
  7. package/dist/db.js +14 -6
  8. package/dist/enricher.d.ts +18 -26
  9. package/dist/enricher.js +113 -333
  10. package/dist/index.js +23 -2
  11. package/dist/insights.js +0 -2
  12. package/dist/meta-stats.js +1 -1
  13. package/dist/middleware/rate-limiter.js +1 -1
  14. package/dist/paths.d.ts +17 -0
  15. package/dist/paths.js +45 -1
  16. package/dist/quota-tracker.js +0 -1
  17. package/dist/roast.js +0 -2
  18. package/dist/routes/events.d.ts +0 -2
  19. package/dist/routes/events.js +7 -21
  20. package/dist/routes/helpers.d.ts +2 -0
  21. package/dist/routes/helpers.js +21 -0
  22. package/dist/routes/misc.js +3 -21
  23. package/dist/routes/projects.d.ts +0 -2
  24. package/dist/routes/projects.js +3 -17
  25. package/dist/routes/stream.d.ts +1 -1
  26. package/dist/routes/stream.js +3 -3
  27. package/dist/service.js +11 -7
  28. package/dist/watch.js +0 -1
  29. package/dist/watchdog.d.ts +5 -0
  30. package/dist/watchdog.js +6 -1
  31. package/dist/watchers/adapter.d.ts +37 -0
  32. package/dist/watchers/adapter.js +31 -0
  33. package/dist/watchers/amp.d.ts +8 -0
  34. package/dist/watchers/amp.js +42 -0
  35. package/dist/watchers/claude-code.d.ts +17 -0
  36. package/dist/watchers/claude-code.js +300 -0
  37. package/dist/watchers/codebuff.d.ts +8 -0
  38. package/dist/watchers/codebuff.js +42 -0
  39. package/dist/watchers/codex.d.ts +9 -0
  40. package/dist/watchers/codex.js +43 -0
  41. package/dist/watchers/droid.d.ts +8 -0
  42. package/dist/watchers/droid.js +42 -0
  43. package/dist/watchers/opencode.d.ts +9 -0
  44. package/dist/watchers/opencode.js +43 -0
  45. package/package.json +12 -3
package/README.md CHANGED
@@ -14,15 +14,19 @@ Works with Claude Pro, Max 5, and Max 20. Zero cloud dependencies. Pure Node.js.
14
14
  [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
15
15
  [![Node.js](https://img.shields.io/badge/node-%3E%3D22-brightgreen)](https://nodejs.org)
16
16
  [![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-brightgreen)]()
17
- [![Tests](https://img.shields.io/badge/tests-243%2F243-brightgreen)]()
17
+ [![CI](https://github.com/DeibyGS/claudestat/actions/workflows/ci.yml/badge.svg)](https://github.com/DeibyGS/claudestat/actions/workflows/ci.yml)
18
+ [![Download](https://img.shields.io/badge/download-binary-blue)](https://github.com/DeibyGS/claudestat/releases/latest)
18
19
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen)](CONTRIBUTING.md)
19
20
 
20
- [Installation](#installation) • [Quick Start](#quick-start) • [Commands](#commands) • [Dashboard](#dashboard) • [Contributing](#contributing)
21
+ [Installation](#installation) •
22
+ [Quick Start](#quick-start) •
23
+ [Commands](#commands) •
24
+ [Dashboard](#dashboard) •
25
+ [FAQ](#faq) •
26
+ [Contributing](#contributing)
21
27
 
22
28
  ![ClaudeStat banner](https://raw.githubusercontent.com/DeibyGS/claudestat/main/assets/banner.png)
23
29
 
24
- ---
25
-
26
30
  ### See it in action
27
31
 
28
32
  *Live dashboard · terminal trace · quota guard — all running in real time*
@@ -33,9 +37,29 @@ Works with Claude Pro, Max 5, and Max 20. Zero cloud dependencies. Pure Node.js.
33
37
 
34
38
  ---
35
39
 
40
+ ## Table of Contents
41
+
42
+ - [Why claudestat?](#why-claudestat)
43
+ - [Ask Claude about itself](#ask-claude-about-itself)
44
+ - [Features](#features)
45
+ - [Quick Start](#quick-start)
46
+ - [Requirements](#requirements)
47
+ - [Installation](#installation)
48
+ - [Commands](#commands)
49
+ - [Dashboard](#dashboard)
50
+ - [MCP Server](#mcp-server)
51
+ - [Configuration](#configuration)
52
+ - [Troubleshooting](#troubleshooting)
53
+ - [FAQ](#faq)
54
+ - [Uninstall](#uninstall)
55
+ - [Contributing](#contributing)
56
+ - [License](#license)
57
+
58
+ ---
59
+
36
60
  ## Why claudestat?
37
61
 
38
- Tools like ccusage are great for reviewing history. claudestat is for while you're coding.
62
+ Tools like ccusage are great for reviewing history. claudestat is for *while you're coding*.
39
63
 
40
64
  It taps into Claude Code's hook system to capture every event the moment it fires, stores everything locally in SQLite, and gives you a live dashboard, quota alerts, and an MCP server — not just a report.
41
65
 
@@ -48,16 +72,7 @@ It taps into Claude Code's hook system to capture every event the moment it fire
48
72
  | Loop detector | ✅ | ❌ |
49
73
  | MCP server (ask Claude about itself) | ✅ | ❌ |
50
74
  | Historical usage analysis | ✅ | ✅ |
51
-
52
- **What you get:**
53
-
54
- - Live tool trace — every call with duration and token cost as it runs
55
- - Quota guard — alerts at 70%, 85%, 95%; optional kill switch blocks new sessions at X%
56
- - Loop detector — flags context thrashing with estimated waste cost
57
- - Top tools — know which tools eat most of your budget
58
- - Web dashboard — session history, analytics, model breakdown, charts
59
- - MCP server — 7 tools so Claude can answer questions about its own usage
60
- - Weekly insights — pattern analysis with actionable tips
75
+ | Multi-CLI support (Codex, OpenCode, Amp, etc.) | ✅ | ✅ |
61
76
 
62
77
  > If claudestat is useful, give it a ⭐ — it helps other developers find it.
63
78
 
@@ -74,37 +89,38 @@ claude mcp add claudestat -s user -- claudestat-mcp
74
89
  Then just ask:
75
90
 
76
91
  ```
77
- > What's my current quota status?
78
92
  > How much did I spend this week?
79
93
  > What are my top 5 tools by cost?
80
94
  > Break down my usage by model
95
+ > What's my cost projection for next month?
81
96
  ```
82
97
 
83
- Claude reads your local SQLite data through the MCP server and answers in real time. No cloud, no API key, no extra setup. [Full MCP reference →](#mcp-server)
98
+ [Full MCP reference →](docs/MCP.md)
84
99
 
85
100
  ---
86
101
 
87
- ## How it works
102
+ ## Features
88
103
 
89
- ```
90
- Claude Code event
91
-
92
-
93
- Hook script (~/.claudestat/hooks/event.js)
94
- │ POST JSON to daemon
95
-
96
- Daemon (localhost:7337)
97
- │ stores events in SQLite
98
- │ enriches with JSONL token data
99
- │ runs pattern analyzer
100
-
101
- Dashboard (React + Vite, auto-refreshes)
102
-
103
-
104
- You see everything live
104
+ - **Live tool trace** — every call with duration and token cost as it runs
105
+ - **Quota guard** — alerts at 70%, 85%, 95%; optional kill switch blocks new sessions at X%
106
+ - **Loop detector** — flags context thrashing with estimated waste cost
107
+ - **Top tools** — know which tools eat most of your budget
108
+ - **Cost projection** — linear regression with trend, confidence intervals, R²
109
+ - **Web dashboard** — 6 tabs: Live, History, Projects, Analytics, Top, System
110
+ - **MCP server** — 7 tools so Claude can answer questions about its own usage
111
+ - **Weekly insights** — pattern analysis with actionable tips
112
+ - **Multi-CLI support** — works with Claude Code, Codex, OpenCode, and more
113
+
114
+ ---
115
+
116
+ ## Quick Start
117
+
118
+ ```bash
119
+ npm install -g @statforge/claudestat && claudestat setup
120
+ open http://localhost:7337
105
121
  ```
106
122
 
107
- > **Windows paths**: Claude Code stores its data in `~/.claude/` on all platforms (macOS, Linux, and Windows). ClaudeStat detects the correct path automatically.
123
+ Start a Claude Code session and watch the events flow in. That's it.
108
124
 
109
125
  ---
110
126
 
@@ -123,18 +139,14 @@ npm install -g @statforge/claudestat && claudestat setup
123
139
 
124
140
  `claudestat setup` installs the Claude Code hooks and registers the daemon as a system service (launchd on macOS, systemd on Linux) — no sudo required. The daemon starts automatically whenever you log in.
125
141
 
126
- > **Using NVM?** Make sure you're on your default Node version before installing to avoid stale binary conflicts:
142
+ > **Using NVM?** Make sure you're on your default Node version:
127
143
  > ```bash
128
- > nvm use default && npm install -g @statforge/claudestat
129
- > claudestat setup
144
+ > nvm use default && npm install -g @statforge/claudestat && claudestat setup
130
145
  > ```
131
- > Works with [nvm](https://github.com/nvm-sh/nvm) (macOS/Linux) and [nvm-windows](https://github.com/coreybutler/nvm-windows).
132
-
146
+ >
133
147
  > Restart Claude Code after setup so the hooks take effect.
134
148
 
135
- ### Manual setup (alternative)
136
-
137
- If you prefer to manage the daemon yourself:
149
+ ### Manual setup
138
150
 
139
151
  ```bash
140
152
  npm install -g @statforge/claudestat
@@ -144,464 +156,100 @@ claudestat start # start the daemon manually
144
156
 
145
157
  ---
146
158
 
147
- ## Quick Start
148
-
149
- ```bash
150
- # 1. Install and set up everything in one command
151
- npm install -g @statforge/claudestat && claudestat setup
152
-
153
- # 2. Open the dashboard in your browser
154
- # macOS:
155
- open http://localhost:7337
156
- # Windows / Linux:
157
- claudestat start # start daemon manually, then open http://localhost:7337
158
-
159
- # 3. Or watch a live terminal trace
160
- claudestat watch
161
- ```
162
-
163
- That's it. Start a Claude Code session and watch the events flow in.
164
-
165
- ---
166
-
167
159
  ## Commands
168
160
 
169
161
  | Command | Description |
170
- |---|---|
162
+ |---------|-------------|
171
163
  | `claudestat setup` | One-command setup: install hooks + register daemon as system service |
172
164
  | `claudestat setup --uninstall` | Remove hooks and system service |
173
- | `claudestat start` | Start the background daemon manually |
174
- | `claudestat stop` | Stop the daemon |
175
- | `claudestat restart` | Restart the daemon |
176
- | `claudestat install` | Install hooks into Claude Code |
177
- | `claudestat uninstall` | Remove hooks from Claude Code |
165
+ | `claudestat start` / `stop` / `restart` | Manage the background daemon |
166
+ | `claudestat install` / `uninstall` | Install or remove Claude Code hooks |
178
167
  | `claudestat watch` | Live terminal trace view |
179
168
  | `claudestat status` | Show quota, cost, and burn rate |
180
- | `claudestat config` | View or edit configuration |
181
169
  | `claudestat top` | Rank tools by cost, call count, or duration |
182
- | `claudestat weekly` | Weekly usage summary with actionable tips |
183
- | `claudestat insights` | Deep usage insights: cost breakdown, cache savings, efficiency, peak hours, model breakdown |
184
- | `claudestat roast` | Sarcastic usage analysis with roast jokes |
185
- | `claudestat roast --stats` | Raw stats with visual bars |
186
- | `claudestat version` | Show version and check for npm updates |
187
- | `claudestat export [format]` | Export session data to JSON or CSV |
170
+ | `claudestat weekly` | Weekly usage summary |
171
+ | `claudestat insights` | Deep usage insights: cost, cache, efficiency, models |
172
+ | `claudestat project` | Cost projection with linear regression |
173
+ | `claudestat config` | View or edit configuration |
188
174
  | `claudestat doctor` | Check installation health and diagnose issues |
175
+ | `claudestat export [format]` | Export session data to JSON or CSV |
176
+ | `claudestat roast` | Sarcastic usage analysis |
177
+ | `claudestat version` | Show version and check for updates |
189
178
 
190
- ### `claudestat watch`
191
-
192
- Live terminal trace — every tool call as it happens, with duration and token cost.
193
-
194
- ```
195
- claudestat watch
196
-
197
- ● Session a3f1bc · my-project · claude-sonnet-4-5
198
-
199
- 16:42:01 Bash 342ms 1,240 tok $0.0018
200
- 16:42:03 Read 89ms 420 tok $0.0006
201
- 16:42:05 Edit 124ms 890 tok $0.0013
202
- 16:42:08 Agent (haiku) 2.1s 3,200 tok $0.0024
203
- 16:42:11 Write 67ms 310 tok $0.0004
204
-
205
- Context: 42,800 / 200,000 (21%) │ Session cost: $0.0065 │ 🟢 healthy
206
- ```
207
-
208
- ### `claudestat top`
209
-
210
- Ranks your most-used tools by estimated cost, call count, or duration across all sessions.
211
-
212
- ```
213
- claudestat top
214
-
215
- 🏆 claudestat top by est. cost (last 30 days)
216
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
217
-
218
- 1 Edit ████████████████░░░░ $146.47 21%
219
- 2479 calls · 38.5m
220
- 2 Bash ███████████████░░░░░ $140.66 20%
221
- 2651 calls · 153.6m
222
- 3 Read ██████████████░░░░░░ $126.08 18%
223
- 2315 calls · 34.0m
224
- 4 Grep ████░░░░░░░░░░░░░░░░ $39.93 6%
225
- 699 calls · 9.3m
226
- 5 ToolSearch ██░░░░░░░░░░░░░░░░░░ $21.83 3%
227
- 469 calls · 7.4m
228
- 6 Glob ██░░░░░░░░░░░░░░░░░░ $13.96 2%
229
- 269 calls · 5.7m
230
- 7 Write █░░░░░░░░░░░░░░░░░░░ $12.93 2%
231
- 237 calls · 87.1m
232
- 8 mcp__plugin_engr… █░░░░░░░░░░░░░░░░░░░ $8.10 1%
233
- 149 calls · 2.6m
234
- 9 Agent █░░░░░░░░░░░░░░░░░░░ $8.09 1%
235
- 168 calls · 95.7m
236
- 10 WebFetch █░░░░░░░░░░░░░░░░░░░ $5.86 1%
237
- 106 calls · 9.9m
238
- Other — $184.79 26%
239
-
240
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
241
- ```
242
-
243
- Options: `--by cost|count|duration` · `--days 7|30|90` · `--limit N`
244
-
245
- ### `claudestat weekly`
246
-
247
- Weekly usage summary with an actionable tip. Detects patterns like Bash overuse, low efficiency, high session count, and loop frequency.
248
-
249
- ```
250
- claudestat weekly
251
-
252
- 📊 claudestat weekly May 8 – May 13
253
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
254
-
255
- 💰 $198.38 total · 40 sessions · 114 loops
256
-
257
- 🔧 Top tool Bash 22% of cost
258
-
259
- 📈 Efficiency ██████████████████░░ 91/100
260
-
261
- 💾 Cache hit ████████████████████ 100%
262
-
263
- 📦 Tokens 73K in + 1.2M out
264
-
265
- ⚡ Tip: 114 loops detected — consider using /compact earlier to prevent context thrashing
266
-
267
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
268
- ```
269
-
270
- Options: `--json` for machine-readable output.
271
-
272
- ### `claudestat status`
273
-
274
- Shows your current quota usage with visual progress bars, plan detection, and burn rate.
275
-
276
- ```
277
- claudestat status
278
-
279
- 📊 claudestat PRO plan
280
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
281
-
282
- 5h ████████████████████ 100% resets 4:10 AM
283
-
284
- Week ██████░░░░░░░░░░░░░░ 31% resets May 18
285
-
286
- 🔥 490 tok/min · 101 prompts used
287
-
288
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
289
- ```
290
-
291
- Options: `--json` for machine-readable output.
292
-
293
- ### `claudestat insights`
294
-
295
- Deep usage insights: cost breakdown by project, cache savings, output/input ratio, efficiency trend, peak activity hours, and model breakdown.
296
-
297
- ```
298
- claudestat insights
299
-
300
- 💡 claudestat insights last 7 days
301
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
302
-
303
- 💰 $4.96/session · 40 sessions · $198.38 total
304
-
305
- 🗂 Top projects
306
- no project █████████░░░░░░░░░░░ $93.69 47%
307
-
308
- claudestat ████████░░░░░░░░░░░░ $74.60 38%
309
-
310
- wodrival ███░░░░░░░░░░░░░░░░░ $24.95 13%
311
-
312
- aprendiendo-in ░░░░░░░░░░░░░░░░░░░░ $3.32 2%
313
-
314
- other ░░░░░░░░░░░░░░░░░░░░ $1.81 1%
315
-
316
- ⚡ Cache ~$1029.43 saved · 100% hit rate
317
-
318
- 📊 16× output/input · cache-heavy workload
319
-
320
- 📈 Efficiency 91/100 ↓ -2 vs prev period · 114 loops
321
-
322
- ⏰ Activity by time of day
323
- 🌙 00:00–05:59 ████████████████████ 18 sessions
324
-
325
- 🌅 06:00–11:59 ███████░░░░░░░░░░░░░ 6 sessions
326
-
327
- ☀️ 12:00–17:59 ███░░░░░░░░░░░░░░░░░ 3 sessions
328
-
329
- 🌆 18:00–23:59 ██████████████░░░░░░ 13 sessions
330
-
331
- 🤖 Models
332
- claude-sonnet-4-6 ████████████████████ $197.11 99% · 23 sessions
333
-
334
- claude-haiku-4-5-20251001 ░░░░░░░░░░░░░░░░░░░░ $1.26 1% · 15 sessions
335
-
336
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
337
- ```
338
-
339
- Options: `--days 7|14|30|90` · `--json` for machine-readable output.
340
-
341
- ### `claudestat config`
342
-
343
- ```
344
- claudestat config
345
-
346
- ⚙️ claudestat config
347
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
348
-
349
- Plan PRO
350
- Alerts enabled
351
-
352
- Kill switch OFF
353
- ████████████████████
354
-
355
- Cycle thresholds 70%, 85%, 95%
356
- yellow ████████░░ orange █████████░ red ██████████
357
-
358
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
359
- ```
360
-
361
- ```bash
362
- # Enable kill switch at 90% quota
363
- claudestat config --kill-switch true --threshold 90
364
-
365
- # Force plan detection
366
- claudestat config --plan max5 # pro | max5 | max20 | auto
367
-
368
- # Toggle daemon rate limit alerts
369
- claudestat config --alerts false
370
- ```
371
-
372
- Config is stored at `~/.claudestat/config.json` (macOS/Linux) or `%USERPROFILE%\.claudestat\config.json` (Windows).
373
-
374
- ### `claudestat roast`
375
-
376
- Get a sarcastic analysis of your Claude Code usage — humor with insights.
377
-
378
- ```bash
379
- claudestat roast
380
-
381
- 🔥 Your Claude Code Roast (30 days)
382
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
383
-
384
- Score ██████████████████░░ 92/100 ★★★★★
385
-
386
- Scorecard
387
- ┌─────────────────┬──────────────┬──────────────┐
388
- │ Metric │ Value │ Rating │
389
- ├─────────────────┼──────────────┼──────────────┤
390
- │ Sessions │ 47 │ normal │
391
- │ Total cost │ $12.40 │ frugal │
392
- │ Avg/session │ $0.26/session│ efficient │
393
- │ Bash calls │ 1240 │ 🔨 overload │
394
- │ Loops │ 8 │ clean │
395
- │ Efficiency │ 92/100 │ 🏆 elite │
396
- │ Tokens │ 4.2M │ — │
397
- │ Top tool │ Bash 38% │ — │
398
- └─────────────────┴──────────────┴──────────────┘
399
-
400
- Roast Cards
401
-
402
- ┌──────────────────────────────────────────────────┐
403
- │ 🖥️ BASH OVERLOAD │
404
- │ 1240 calls in 30d — once every 2.3 min │
405
- │ Are you okay? │
406
- └──────────────────────────────────────────────────┘
407
-
408
- ┌──────────────────────────────────────────────────┐
409
- │ 🔄 LOOP MONEY PIT │
410
- │ $4.20 wasted on loops — that's 14 coffees │
411
- │ Just saying. │
412
- └──────────────────────────────────────────────────┘
413
-
414
- Verdict
415
- You're a machine. Or maybe you're just not using Claude enough.
416
-
417
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
418
- github.com/DeibyGS/claudestat
419
- ```
420
-
421
- Options: `--stats` for raw stats with visual bars · `--months N` to look back N months.
422
-
423
- ### `claudestat doctor`
424
-
425
- Diagnoses common installation problems — useful if `claudestat start` fails or hooks are not firing.
426
-
427
- ```
428
- claudestat doctor
429
-
430
- 🩺 claudestat doctor
431
- ──────────────────────────────────────────────
432
- ✓ Node.js version (22.17.0)
433
- ✓ Claude Code installed
434
- ✓ Hooks installed in Claude Code
435
- ✓ ~/.claudestat/ data directory exists
436
- ✓ Hook script deployed (~/.claudestat/hooks/event.js)
437
- ✓ Daemon running (localhost:7337)
438
- ✓ Global CLI symlink valid
439
- ✓ No duplicate claudestat binaries in PATH
440
- ✓ Version match (installed: v1.3.0)
441
- ✓ NVM prefix matches active binary
442
- ✓ MCP server registered in Claude Code
443
- ──────────────────────────────────────────────
444
- All checks passed — claudestat is healthy!
445
- ```
446
-
447
- If a check fails, `doctor` prints the exact fix command to run.
179
+ [Full command reference with output examples →](docs/COMMANDS.md)
448
180
 
449
181
  ---
450
182
 
451
- ### `claudestat version`
452
-
453
- Shows the current version and checks npm for updates.
454
-
455
- ```bash
456
- claudestat version
457
-
458
- 1.3.0
459
- latest ✓
460
- ```
461
-
462
- If a newer version is available, it shows: `latest: 1.4.0 — run npm update`.
183
+ ## Dashboard
463
184
 
464
- ### `claudestat export`
185
+ The dashboard lives at `http://localhost:7337` and has six tabs: **Live** (real-time trace), **History** (sessions by date), **Projects** (grid with stats), **Analytics** (KPIs + charts), **Top** (tool rankings), and **System** (daemon health).
465
186
 
466
- Export session data to JSON or CSV. Supports date and project filters.
187
+ ![Live tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225605/My%20portfolio%7D/live_oeucqs.png)
467
188
 
468
- ```bash
469
- # Export all sessions as JSON to stdout
470
- claudestat export
189
+ ![History tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225605/My%20portfolio%7D/history_gy4tpb.png)
471
190
 
472
- # Export as CSV to a file
473
- claudestat export csv --output ~/sessions.csv
191
+ ![Projects tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225606/My%20portfolio%7D/projects_yeftby.png)
474
192
 
475
- # Filter by date range
476
- claudestat export json --from 2025-05-01 --to 2025-05-31
193
+ ![Analytics KPIs](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225605/My%20portfolio%7D/analitycsOne_yx9tcp.png)
477
194
 
478
- # Filter by project name (case-insensitive substring match)
479
- claudestat export csv --project myapp --output myapp-sessions.csv
195
+ ![Analytics charts](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225604/My%20portfolio%7D/analitycsTwo_wzjsf2.png)
480
196
 
481
- # Multiple filters combined
482
- claudestat export json --from 2025-05-01 --project claudestat --output may-claudestat.json
483
- ```
197
+ ![Top tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225606/My%20portfolio%7D/top_pybyxy.png)
484
198
 
485
- **Options:** `--from YYYY-MM-DD` · `--to YYYY-MM-DD` · `--project <name>` · `--output <path>`
199
+ ![System tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225606/My%20portfolio%7D/system_ixurjb.png)
486
200
 
487
- Each row includes: `id`, `started_at`, `cwd`, `project_path`, `total_cost_usd`, `total_input_tokens`, `total_output_tokens`, `efficiency_score`, `loops_detected`.
201
+ [Dashboard details →](docs/DASHBOARD.md)
488
202
 
489
203
  ---
490
204
 
491
205
  ## MCP Server
492
206
 
493
- claudestat includes an MCP (Model Context Protocol) server that lets Claude Code query its own usage stats Claude can tell you its quota, session cost, and top tools in real time.
494
-
495
- ### Tools exposed
496
-
497
- | Tool | Description |
498
- |------|------------|
499
- | `get_quota_status` | 5h cycle usage %, plan, weekly hours, burn rate (with on-demand API refresh + disk cache) |
500
- | `get_current_session` | Latest session: cost, tokens, efficiency, loops |
501
- | `get_session_stats` | Aggregated stats for N days |
502
- | `get_top_tools` | Top 10 tools by cost/count/duration (default 30 days) |
503
- | `get_usage_insights` | Deep insights: cost per project, cache savings, efficiency trend, peak hours, model breakdown |
504
- | `get_model_breakdown` | Cost and session count broken down by Claude model (Sonnet, Haiku, Opus) |
505
- | `get_weekly_insight` | Weekly summary with actionable tip |
506
-
507
- ### Register with Claude Code
207
+ claudestat includes an MCP server with 7 tools for querying usage stats. Register once:
508
208
 
509
209
  ```bash
510
210
  claude mcp add claudestat -s user -- claudestat-mcp
511
211
  ```
512
212
 
513
- Once registered, ask Claude things like:
514
- - *"What's my current quota status?"*
515
- - *"Show me my latest session cost"*
516
- - *"What are my top 5 tools by cost this week?"*
517
- - *"Give me usage insights for the last 14 days"*
518
- - *"Break down my usage by model"*
213
+ Then ask Claude: *"What's my quota status?"*, *"Show me my latest session"*, *"Top 5 tools by cost"*.
519
214
 
520
215
  ![claudestat MCP demo](https://raw.githubusercontent.com/DeibyGS/claudestat/main/assets/mcp-demo.gif)
521
216
 
522
- Zero extra dependencies — stdio JSON-RPC. Works without the daemon running (reads SQLite directly), but will warn you to start it if it's not active: `claudestat start`. Uses on-demand API refresh with shared disk cache for accurate quota data.
217
+ [MCP tools reference →](docs/MCP.md)
523
218
 
524
219
  ---
525
220
 
526
- ## Dashboard
527
-
528
- The dashboard lives at `http://localhost:7337` and has six tabs:
221
+ ## Configuration
529
222
 
530
- ### Live
531
- Real-time stream of every tool call in the active session. Shows tool name, duration, and token cost. Agent sub-calls expand into nested traces; Skill invocations collapse into labeled containers.
223
+ Config is stored at `~/.claudestat/config.json`. View it with `claudestat config` or edit the file directly.
532
224
 
533
- ![Live tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225605/My%20portfolio%7D/live_oeucqs.png)
534
-
535
- ### History
536
- All past sessions sorted by date. Each card shows total tokens (input + cache read + output), USD cost, efficiency score, and detected loops. Click any session to open its full tool trace, DAG view, and a compare panel.
537
-
538
- ![History tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225605/My%20portfolio%7D/history_gy4tpb.png)
539
-
540
- ### Projects
541
- Grid of every project you've worked on. Shows last active date, total sessions, cost, model usage breakdown (Sonnet / Haiku), and an efficiency progress bar.
542
-
543
- ![Projects tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225606/My%20portfolio%7D/projects_yeftby.png)
544
-
545
- ### Analytics
546
- - 6 KPIs: total cost, tokens, cache savings, hidden loop waste, avg efficiency, session count
547
- - Token/cost trend charts (7 / 30 / 90 days)
548
- - Hours by project
549
- - AI-generated weekly reports (auto-scheduled or on demand)
550
-
551
- ![Analytics KPIs](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225605/My%20portfolio%7D/analitycsOne_yx9tcp.png)
552
-
553
- ![Analytics charts](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225604/My%20portfolio%7D/analitycsTwo_wzjsf2.png)
554
-
555
- ### Top
556
- Tool rankings across all your sessions. Sortable by estimated cost, call count, or duration — with a time filter (7 / 30 / 90 days). Also shows projected weekly and monthly spend based on your recent burn rate.
557
-
558
- ![Top tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225606/My%20portfolio%7D/top_pybyxy.png)
559
-
560
- ### System
561
- Daemon health, DB size, Node version, config file paths, and memory context.
562
-
563
- ![System tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225606/My%20portfolio%7D/system_ixurjb.png)
564
-
565
- ---
566
-
567
- ## Configuration reference
568
-
569
- Config is stored at `~/.claudestat/config.json` (macOS/Linux) or `%USERPROFILE%\.claudestat\config.json` (Windows) and created automatically on first run.
570
-
571
- ```json
572
- {
573
- "killSwitchEnabled": false,
574
- "killSwitchThreshold": 95,
575
- "warnThresholds": [70, 85, 95],
576
- "plan": null,
577
- "alertsEnabled": true,
578
- "reportsEnabled": false,
579
- "reportFrequency": "weekly",
580
- "reportDay": 1,
581
- "reportTime": "09:00"
582
- }
225
+ ```bash
226
+ claudestat config --kill-switch true --threshold 90
227
+ claudestat config --plan max5
228
+ claudestat config --alerts false
583
229
  ```
584
230
 
585
- | Key | Default | Description |
586
- |---|---|---|
587
- | `killSwitchEnabled` | `false` | Enable the quota kill switch. When `true`, new Claude Code sessions are blocked once your quota reaches the threshold. |
588
- | `killSwitchThreshold` | `95` | Quota percentage (0–100) at which the kill switch activates. Only relevant when `killSwitchEnabled` is `true`. |
589
- | `warnThresholds` | `[70, 85, 95]` | Three quota percentages for yellow, orange, and red warnings in the dashboard and daemon alerts. |
590
- | `plan` | `null` | Force plan detection. Valid values: `"pro"`, `"max5"`, `"max20"`. Leave `null` to auto-detect. |
591
- | `alertsEnabled` | `true` | Enable daemon rate limit alerts — polls quota every 60s and logs a warning (with optional desktop notification) when thresholds are crossed. |
592
- | `reportsEnabled` | `false` | Enable automatic AI-generated usage reports on a schedule. |
593
- | `reportFrequency` | `"weekly"` | How often to generate reports. Valid values: `"weekly"`, `"biweekly"`, `"monthly"`. |
594
- | `reportDay` | `1` | Day of week for reports (0=Sun, 1=Mon … 6=Sat). |
595
- | `reportTime` | `"09:00"` | Time of day (HH:MM) when the report is generated. |
231
+ [Full configuration reference →](docs/CONFIG.md)
596
232
 
597
- You can edit the file directly or use the CLI:
233
+ ---
598
234
 
599
- ```bash
600
- # Enable kill switch at 90% quota
601
- claudestat config --kill-switch true --threshold 90
235
+ ## How it works
602
236
 
603
- # Force plan (useful if auto-detect is wrong)
604
- claudestat config --plan max5
237
+ ```
238
+ Claude Code event
239
+
240
+
241
+ Hook script (~/.claudestat/hooks/event.js)
242
+ │ POST JSON to daemon
243
+
244
+ Daemon (localhost:7337)
245
+ │ stores events in SQLite
246
+ │ enriches with JSONL token data
247
+ │ runs pattern analyzer
248
+
249
+ Dashboard (React + Vite, auto-refreshes)
250
+
251
+
252
+ You see everything — live
605
253
  ```
606
254
 
607
255
  ---
@@ -609,136 +257,71 @@ claudestat config --plan max5
609
257
  ## Troubleshooting
610
258
 
611
259
  **`claudestat start` hangs for ~5 seconds**
612
- Normal — `require('express')` takes a few seconds on first load. The daemon is starting.
260
+ Normal — `require('express')` takes a few seconds on first load.
613
261
 
614
262
  **Hooks are not firing / dashboard shows no events**
615
263
  Run `claudestat doctor` — it checks every component and prints the exact fix command.
616
- If hooks were installed before upgrading, run `claudestat uninstall && claudestat install` to refresh.
617
264
 
618
265
  **`claudestat` command not found after install**
619
266
  If using NVM, the binary may point to the wrong Node version:
620
267
  ```bash
621
- nvm use default && npm install -g @statforge/claudestat
622
- hash -r claudestat # macOS/Linux — refresh shell binary cache
268
+ nvm use default && npm install -g @statforge/claudestat && hash -r claudestat
623
269
  ```
624
270
 
625
- **Working with multiple projects**
626
- claudestat tracks every project automatically. The Projects tab groups sessions by working directory. Use `claudestat export --project <name>` to export data for a specific project.
271
+ **Kill switch is blocking new sessions**
272
+ Disable with `claudestat config --kill-switch false`, or wait for the 5h quota window to reset.
627
273
 
628
274
  **Approaching rate limit**
629
- When the daemon is running, it polls quota every 60s and logs a warning to stderr when you cross 70%, 85%, or 95%. On macOS and Linux you also get a desktop notification at the `killSwitchThreshold`.
630
- To see current quota at any time: `claudestat status`
275
+ The daemon polls quota every 60s and logs warnings at 70%, 85%, and 95%. Check anytime with `claudestat status`.
631
276
 
632
- **Kill switch is blocking new sessions**
633
- The kill switch only activates when `killSwitchEnabled: true` AND `cyclePct >= killSwitchThreshold`.
634
- To disable: `claudestat config --kill-switch false`
635
- Or wait for the 5h quota window to reset (check time remaining with `claudestat status`).
636
-
637
- **`node:sqlite` experimental warning**
638
- Expected on Node 22+. claudestat suppresses it automatically — you won't see it in normal use.
277
+ **Working with multiple projects**
278
+ claudestat tracks every project automatically. The Projects tab groups sessions by working directory.
639
279
 
640
280
  ---
641
281
 
642
- ## Roadmap
282
+ ## FAQ
283
+
284
+ **What is claudestat? How is it different from ccusage?**
285
+ claudestat is a real-time monitor for Claude Code — not a log reader. It hooks into every tool call as it fires, tracks token usage and cost live, guards your quota with configurable alerts, and exposes an MCP server. ccusage reads JSONL history after sessions end; claudestat runs while you code.
286
+
287
+ **How do I track Claude Code costs?**
288
+ Install with `npm install -g @statforge/claudestat && claudestat setup`, then open `http://localhost:7337` for the live dashboard. Use `claudestat status` for a quick summary or `claudestat export` for full data export.
643
289
 
644
- Planned for upcoming versions:
290
+ **Does claudestat work with Claude Pro, Max 5, and Max 20?**
291
+ Yes. claudestat auto-detects your plan. You can also force it with `claudestat config --plan max5`.
645
292
 
646
- - **Multi-account support** track usage across multiple Claude accounts
647
- - **Slack / webhook alerts** get notified when quota reaches warning thresholds
648
- - **VS Code extension** — sidebar panel with live stats inside the editor
293
+ **Is my data sent to any server?**
294
+ No. All data is stored locally in SQLite at `~/.claudestat/`. Zero cloud dependencies.
649
295
 
650
- Have an idea? [Open an issue](https://github.com/DeibyGS/claudestat/issues) or submit a PR.
296
+ **Does claudestat work on Windows?**
297
+ Yes — macOS, Linux, and Windows are all supported.
651
298
 
652
299
  ---
653
300
 
654
301
  ## Uninstall
655
302
 
656
303
  ```bash
657
- # Full uninstall (hooks + system service + daemon):
658
- claudestat setup --uninstall
659
-
660
- # Then remove the data directory:
661
- # macOS / Linux:
662
- rm -rf ~/.claudestat
663
-
664
- # Windows (PowerShell):
665
- Remove-Item -Recurse -Force "$env:USERPROFILE\.claudestat"
304
+ claudestat setup --uninstall # remove hooks + system service
305
+ rm -rf ~/.claudestat # macOS / Linux
306
+ Remove-Item -Recurse -Force "$env:USERPROFILE\.claudestat" # Windows (PowerShell)
666
307
  ```
667
308
 
668
- > If you installed manually (without `setup`), use `claudestat uninstall` to remove only the hooks.
309
+ > If you installed manually, use `claudestat uninstall` to remove only the hooks.
669
310
 
670
311
  ---
671
312
 
672
313
  ## Contributing
673
314
 
674
- **claudestat is open source and PRs are welcome.**
675
-
676
- Whether you want to fix a bug, improve a dashboard view, add a new pattern to the analyzer, or support a new provider — contributions are encouraged.
677
-
678
- ### How to contribute
679
-
680
- 1. Fork the repository
681
- 2. Create a branch: `git checkout -b feat/your-feature`
682
- 3. Make your changes
683
- 4. Run the test suite: `node --require tsx/cjs tests/index.ts` (243 tests)
684
- 5. Open a PR with a clear description of what you changed and why
685
-
686
- ### Good first areas
687
-
688
- - **Pattern analyzer** (`src/pattern-analyzer.ts`) — add new usage patterns or improve thresholds
689
- - **Dashboard components** (`dashboard/src/components/`) — UI improvements, new charts, accessibility
690
- - **New commands** — ideas like `claudestat compare`
691
- - **Bug reports** — open an issue with steps to reproduce and your Node/OS version
692
-
693
- ### Running locally
315
+ PRs are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for full guidelines.
694
316
 
695
317
  ```bash
696
318
  git clone https://github.com/YOUR_USERNAME/claudestat
697
319
  cd claudestat
698
320
  npm install
699
- npm run dev:full # starts daemon + dashboard hot-reload together
700
321
  node --require tsx/cjs tests/index.ts # run all tests
701
322
  ```
702
323
 
703
- See [CONTRIBUTING.md](CONTRIBUTING.md) for full guidelines.
704
-
705
- This project follows the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md).
706
-
707
- ---
708
-
709
- ## Contributors
710
-
711
- Thanks to everyone who has contributed to claudestat:
712
-
713
- [Deiby Gorrin](https://github.com/DeibyGS) — creator and maintainer
714
-
715
- Want to appear here? Pick a [good-first-issue](https://github.com/DeibyGS/claudestat/labels/good-first-issue) and open a PR.
716
-
717
- ---
718
-
719
- ## FAQ
720
-
721
- **What is claudestat? How is it different from ccusage?**
722
- claudestat is a real-time monitor for Claude Code — not a log reader. It hooks into every tool call as it fires, tracks token usage and cost live, guards your quota with configurable alerts, and exposes an MCP server so Claude can answer questions about its own usage. ccusage reads JSONL history after sessions end; claudestat runs while you code.
723
-
724
- **How do I monitor Claude Code token usage?**
725
- Install with `npm install -g @statforge/claudestat && claudestat setup`, then open `http://localhost:7337` for the live dashboard. The daemon starts automatically on login after setup.
726
-
727
- **How do I track Claude Code costs?**
728
- claudestat records every session's token usage and estimates API cost per tool call.
729
- Use `claudestat status` for a quick summary or `claudestat export` for full data export.
730
-
731
- **How do I get alerted when Claude Code hits the rate limit?**
732
- claudestat polls your quota every 60 seconds and sends desktop notifications when you cross 70%, 85%, or 95%. Configure with `claudestat config --alerts true`.
733
-
734
- **Does claudestat work with Claude Pro, Max 5, and Max 20?**
735
- Yes. claudestat auto-detects your plan. You can also force it with `claudestat config --plan max5`.
736
-
737
- **Is my data sent to any server?**
738
- No. All data is stored locally in SQLite at `~/.claudestat/`. Zero cloud dependencies.
739
-
740
- **Does claudestat work on Windows?**
741
- Yes — macOS, Linux, and Windows are all supported.
324
+ Good first areas: pattern analyzer (`src/pattern-analyzer.ts`), dashboard components (`dashboard/src/components/`), new commands.
742
325
 
743
326
  ---
744
327