@statforge/claudestat 1.0.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 (80) hide show
  1. package/README.md +437 -0
  2. package/dashboard/dist/assets/AnalyticsView-BApcOGsD.js +8 -0
  3. package/dashboard/dist/assets/HistoryView-B331k5oL.js +1 -0
  4. package/dashboard/dist/assets/ProjectsView-DUleaXsP.js +6 -0
  5. package/dashboard/dist/assets/SystemView-BGe__vl1.js +1 -0
  6. package/dashboard/dist/assets/TopView-CXggyydU.js +1 -0
  7. package/dashboard/dist/assets/index-CB01c5lb.js +84 -0
  8. package/dashboard/dist/assets/vendor-lucide-Cym0q5l_.js +344 -0
  9. package/dashboard/dist/assets/vendor-react-B_Jzs0gY.js +24 -0
  10. package/dashboard/dist/index.html +21 -0
  11. package/dist/cache/projects-cache.d.ts +9 -0
  12. package/dist/cache/projects-cache.js +51 -0
  13. package/dist/claude-auth.d.ts +38 -0
  14. package/dist/claude-auth.js +133 -0
  15. package/dist/claude-stats.d.ts +32 -0
  16. package/dist/claude-stats.js +98 -0
  17. package/dist/config.d.ts +43 -0
  18. package/dist/config.js +110 -0
  19. package/dist/daemon.d.ts +15 -0
  20. package/dist/daemon.js +247 -0
  21. package/dist/db.d.ts +134 -0
  22. package/dist/db.js +546 -0
  23. package/dist/doctor.d.ts +1 -0
  24. package/dist/doctor.js +191 -0
  25. package/dist/enricher.d.ts +34 -0
  26. package/dist/enricher.js +394 -0
  27. package/dist/export.d.ts +8 -0
  28. package/dist/export.js +82 -0
  29. package/dist/git.d.ts +22 -0
  30. package/dist/git.js +57 -0
  31. package/dist/github.d.ts +27 -0
  32. package/dist/github.js +62 -0
  33. package/dist/index.d.ts +8 -0
  34. package/dist/index.js +319 -0
  35. package/dist/install.d.ts +14 -0
  36. package/dist/install.js +202 -0
  37. package/dist/intelligence.d.ts +45 -0
  38. package/dist/intelligence.js +105 -0
  39. package/dist/meta-stats.d.ts +28 -0
  40. package/dist/meta-stats.js +137 -0
  41. package/dist/middleware/rate-limiter.d.ts +2 -0
  42. package/dist/middleware/rate-limiter.js +30 -0
  43. package/dist/notifier.d.ts +1 -0
  44. package/dist/notifier.js +22 -0
  45. package/dist/paths.d.ts +79 -0
  46. package/dist/paths.js +134 -0
  47. package/dist/pattern-analyzer.d.ts +35 -0
  48. package/dist/pattern-analyzer.js +123 -0
  49. package/dist/project-scanner.d.ts +71 -0
  50. package/dist/project-scanner.js +619 -0
  51. package/dist/quota-tracker.d.ts +45 -0
  52. package/dist/quota-tracker.js +320 -0
  53. package/dist/render.d.ts +55 -0
  54. package/dist/render.js +229 -0
  55. package/dist/routes/events.d.ts +18 -0
  56. package/dist/routes/events.js +272 -0
  57. package/dist/routes/history.d.ts +1 -0
  58. package/dist/routes/history.js +65 -0
  59. package/dist/routes/misc.d.ts +1 -0
  60. package/dist/routes/misc.js +280 -0
  61. package/dist/routes/projects.d.ts +15 -0
  62. package/dist/routes/projects.js +153 -0
  63. package/dist/routes/reports.d.ts +11 -0
  64. package/dist/routes/reports.js +205 -0
  65. package/dist/routes/stream.d.ts +8 -0
  66. package/dist/routes/stream.js +70 -0
  67. package/dist/routes/top.d.ts +1 -0
  68. package/dist/routes/top.js +30 -0
  69. package/dist/session-state.d.ts +35 -0
  70. package/dist/session-state.js +50 -0
  71. package/dist/summarizer.d.ts +18 -0
  72. package/dist/summarizer.js +137 -0
  73. package/dist/watch.d.ts +8 -0
  74. package/dist/watch.js +157 -0
  75. package/dist/watchdog.d.ts +11 -0
  76. package/dist/watchdog.js +75 -0
  77. package/dist/weekly.d.ts +13 -0
  78. package/dist/weekly.js +39 -0
  79. package/hooks/event.js +80 -0
  80. package/package.json +78 -0
package/README.md ADDED
@@ -0,0 +1,437 @@
1
+ <div align="center">
2
+
3
+ # claudestat
4
+
5
+ **Real-time execution trace and cost intelligence for Claude Code**
6
+
7
+ Hook into every tool call, token, and dollar — as it happens.
8
+ Works with Claude Pro, Max 5, and Max 20. Zero cloud dependencies. Pure Node.js. Runs on macOS, Linux, and Windows.
9
+
10
+ [![npm version](https://img.shields.io/npm/v/@statforge/claudestat?color=blue)](https://www.npmjs.com/package/@statforge/claudestat)
11
+ [![npm downloads](https://img.shields.io/npm/dw/@statforge/claudestat?color=blue)](https://www.npmjs.com/package/@statforge/claudestat)
12
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green)](LICENSE)
13
+ [![Node.js](https://img.shields.io/badge/node-%3E%3D22-brightgreen)](https://nodejs.org)
14
+ [![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Linux%20%7C%20Windows-brightgreen)]()
15
+ [![Tests](https://img.shields.io/badge/tests-208%2F208-brightgreen)]()
16
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen)](CONTRIBUTING.md)
17
+
18
+ [Installation](#installation) • [Quick Start](#quick-start) • [Commands](#commands) • [Dashboard](#dashboard) • [Contributing](#contributing)
19
+
20
+ ![ClaudeStat dashboard](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225605/My%20portfolio%7D/ClaudeStat_vnfmup.png)
21
+
22
+ ---
23
+
24
+ ### See it in action
25
+
26
+ *Live dashboard · terminal trace · quota guard — all running in real time*
27
+
28
+ ![claudestat demo](https://raw.githubusercontent.com/DeibyGS/claudestat/main/assets/demoClaudestat.gif)
29
+
30
+ </div>
31
+
32
+ ---
33
+
34
+ ## Why?
35
+
36
+ Claude Code is powerful — but it's a black box while it runs. You can't see what it's spending, how deep the context is, whether it's looping, or if you're about to hit your quota limit.
37
+
38
+ **claudestat fixes that.** It taps into Claude Code's hook system to capture every event, stores it locally in SQLite, and shows you everything in a live dashboard or terminal trace.
39
+
40
+ - Live tool trace with duration and token cost per call
41
+ - Quota guard with configurable kill switch (block new sessions at X%)
42
+ - Pattern analyzer: detects loops, Bash overuse, low cache reuse, and more
43
+ - Per-session cost breakdown + cache savings + burn rate
44
+ - AI-generated weekly usage reports
45
+
46
+ ---
47
+
48
+ ## How it works
49
+
50
+ ```
51
+ Claude Code event
52
+
53
+
54
+ Hook script (~/.claudestat/hooks/event.js)
55
+ │ POST JSON to daemon
56
+
57
+ Daemon (localhost:7337)
58
+ │ stores events in SQLite
59
+ │ enriches with JSONL token data
60
+ │ runs pattern analyzer
61
+
62
+ Dashboard (React + Vite, auto-refreshes)
63
+
64
+
65
+ You see everything — live
66
+ ```
67
+
68
+ > **Windows paths**: Claude Code stores its data in `~/.claude/` on all platforms (macOS, Linux, and Windows). ClaudeStat detects the correct path automatically.
69
+
70
+ ---
71
+
72
+ ## Requirements
73
+
74
+ - **Node.js >= 22** (required for `node:sqlite`)
75
+ - **Claude Code** installed (`npm install -g @anthropic-ai/claude-code`)
76
+
77
+ ---
78
+
79
+ ## Installation
80
+
81
+ ```bash
82
+ npm install -g @statforge/claudestat
83
+ ```
84
+
85
+ > **Using NVM?** Make sure you're on your default Node version before installing to avoid stale binary conflicts:
86
+ > ```bash
87
+ > nvm use default && npm install -g @statforge/claudestat
88
+ > ```
89
+ > Works with [nvm](https://github.com/nvm-sh/nvm) (macOS/Linux) and [nvm-windows](https://github.com/coreybutler/nvm-windows).
90
+
91
+ Then wire up the hooks into Claude Code:
92
+
93
+ ```bash
94
+ claudestat install
95
+ ```
96
+
97
+ This modifies `~/.claude/settings.json` to add `SessionStart`, `PreToolUse`, `PostToolUse`, and `Stop` hooks. A backup is created before any change.
98
+
99
+ > Restart Claude Code after installing so the hooks take effect.
100
+
101
+ ---
102
+
103
+ ## Quick Start
104
+
105
+ ```bash
106
+ # 1. Start the background daemon
107
+ claudestat start
108
+
109
+ # 2. Open the dashboard in your browser
110
+ # macOS:
111
+ open http://localhost:7337
112
+ # Windows:
113
+ start http://localhost:7337
114
+ # Linux:
115
+ xdg-open http://localhost:7337
116
+
117
+ # 3. Or watch a live terminal trace
118
+ claudestat watch
119
+ ```
120
+
121
+ That's it. Start a Claude Code session and watch the events flow in.
122
+
123
+ ---
124
+
125
+ ## Commands
126
+
127
+ | Command | Description |
128
+ |---|---|
129
+ | `claudestat start` | Start the background daemon |
130
+ | `claudestat stop` | Stop the daemon |
131
+ | `claudestat restart` | Restart the daemon |
132
+ | `claudestat install` | Install hooks into Claude Code |
133
+ | `claudestat uninstall` | Remove hooks from Claude Code |
134
+ | `claudestat watch` | Live terminal trace view |
135
+ | `claudestat status` | Show quota, cost, and burn rate |
136
+ | `claudestat config` | View or edit configuration |
137
+ | `claudestat top` | Rank tools by cost, call count, or duration |
138
+ | `claudestat export [format]` | Export session data to JSON or CSV |
139
+ | `claudestat doctor` | Check installation health and diagnose issues |
140
+
141
+ ### `claudestat watch`
142
+
143
+ Live terminal trace — every tool call as it happens, with duration and token cost.
144
+
145
+ ```
146
+ claudestat watch
147
+
148
+ ● Session a3f1bc · my-project · claude-sonnet-4-5
149
+
150
+ 16:42:01 Bash 342ms 1,240 tok $0.0018
151
+ 16:42:03 Read 89ms 420 tok $0.0006
152
+ 16:42:05 Edit 124ms 890 tok $0.0013
153
+ 16:42:08 Agent (haiku) 2.1s 3,200 tok $0.0024
154
+ 16:42:11 Write 67ms 310 tok $0.0004
155
+
156
+ Context: 42,800 / 200,000 (21%) │ Session cost: $0.0065 │ 🟢 healthy
157
+ ```
158
+
159
+ ### `claudestat top`
160
+
161
+ Ranks your most-used tools by estimated cost, call count, or duration across all sessions.
162
+
163
+ ```
164
+ claudestat top
165
+
166
+ 🏆 claudestat top — by est. cost (last 30 days)
167
+
168
+ # Tool Calls Duration Est. Cost %
169
+ ── ───────────────── ──────── ───────────── ───────── ────
170
+ 1 Bash 1,240 18.3m $1.24 38%
171
+ 2 Read 890 4.1m $0.87 27%
172
+ 3 Edit 430 2.8m $0.61 19%
173
+ 4 Agent (haiku) 120 9.2m $0.38 12%
174
+ 5 Write 210 1.1m $0.12 4%
175
+ ```
176
+
177
+ Options: `--by cost|count|duration` · `--days 7|30|90` · `--limit N`
178
+
179
+ ### `claudestat status`
180
+
181
+ ```
182
+ claudestat status
183
+
184
+ Quota 5h 45/50 prompts (90%) | reset in 22m
185
+ Plan MAX5
186
+ Sonnet 3.2h / 5h this week
187
+ Burn rate 1,240 tok/min
188
+ ```
189
+
190
+ ### `claudestat doctor`
191
+
192
+ Diagnoses common installation problems — useful if `claudestat start` fails or hooks are not firing.
193
+
194
+ ```
195
+ claudestat doctor
196
+
197
+ 🩺 claudestat doctor
198
+ ──────────────────────────────────────────────
199
+ ✓ Node.js version (22.17.0)
200
+ ✓ Claude Code installed
201
+ ✓ Hooks installed in Claude Code
202
+ ✓ ~/.claudestat/ data directory exists
203
+ ✓ Hook script deployed (~/.claudestat/hooks/event.js)
204
+ ✓ Daemon running (localhost:7337)
205
+ ✓ Global CLI symlink valid
206
+ ──────────────────────────────────────────────
207
+ All checks passed — claudestat is healthy!
208
+ ```
209
+
210
+ If a check fails, `doctor` prints the exact fix command to run.
211
+
212
+ ---
213
+
214
+ ### `claudestat export`
215
+
216
+ Export session data to JSON or CSV. Supports date and project filters.
217
+
218
+ ```bash
219
+ # Export all sessions as JSON to stdout
220
+ claudestat export
221
+
222
+ # Export as CSV to a file
223
+ claudestat export csv --output ~/sessions.csv
224
+
225
+ # Filter by date range
226
+ claudestat export json --from 2025-05-01 --to 2025-05-31
227
+
228
+ # Filter by project name (case-insensitive substring match)
229
+ claudestat export csv --project myapp --output myapp-sessions.csv
230
+
231
+ # Multiple filters combined
232
+ claudestat export json --from 2025-05-01 --project claudestat --output may-claudestat.json
233
+ ```
234
+
235
+ **Options:** `--from YYYY-MM-DD` · `--to YYYY-MM-DD` · `--project <name>` · `--output <path>`
236
+
237
+ Each row includes: `id`, `started_at`, `cwd`, `project_path`, `total_cost_usd`, `total_input_tokens`, `total_output_tokens`, `efficiency_score`, `loops_detected`.
238
+
239
+ ---
240
+
241
+ ### `claudestat config`
242
+
243
+ ```bash
244
+ # Enable kill switch — block new sessions when quota exceeds 95%
245
+ claudestat config --kill-switch true --threshold 95
246
+
247
+ # Force plan detection instead of auto
248
+ claudestat config --plan max5 # pro | max5 | max20 | auto
249
+
250
+ # Disable daemon rate limit alerts
251
+ claudestat config --alerts false
252
+ ```
253
+
254
+ Config is stored at `~/.claudestat/config.json` (macOS/Linux) or `%USERPROFILE%\.claudestat\config.json` (Windows).
255
+
256
+ ---
257
+
258
+ ## Dashboard
259
+
260
+ The dashboard lives at `http://localhost:7337` and has six tabs:
261
+
262
+ ### Live
263
+ 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.
264
+
265
+ ![Live tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225605/My%20portfolio%7D/live_oeucqs.png)
266
+
267
+ ### History
268
+ 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.
269
+
270
+ ![History tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225605/My%20portfolio%7D/history_gy4tpb.png)
271
+
272
+ ### Projects
273
+ 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.
274
+
275
+ ![Projects tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225606/My%20portfolio%7D/projects_yeftby.png)
276
+
277
+ ### Analytics
278
+ - 6 KPIs: total cost, tokens, cache savings, hidden loop waste, avg efficiency, session count
279
+ - Token/cost trend charts (7 / 30 / 90 days)
280
+ - Hours by project
281
+ - AI-generated weekly reports (auto-scheduled or on demand)
282
+
283
+ ![Analytics KPIs](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225605/My%20portfolio%7D/analitycsOne_yx9tcp.png)
284
+
285
+ ![Analytics charts](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225604/My%20portfolio%7D/analitycsTwo_wzjsf2.png)
286
+
287
+ ### Top
288
+ 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.
289
+
290
+ ![Top tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225606/My%20portfolio%7D/top_pybyxy.png)
291
+
292
+ ### System
293
+ Daemon health, DB size, Node version, config file paths, and memory context.
294
+
295
+ ![System tab](https://res.cloudinary.com/dgscloudinary/image/upload/v1778225606/My%20portfolio%7D/system_ixurjb.png)
296
+
297
+ ---
298
+
299
+ ## Configuration reference
300
+
301
+ Config is stored at `~/.claudestat/config.json` (macOS/Linux) or `%USERPROFILE%\.claudestat\config.json` (Windows) and created automatically on first run.
302
+
303
+ ```json
304
+ {
305
+ "killSwitchEnabled": false,
306
+ "killSwitchThreshold": 95,
307
+ "warnThresholds": [70, 85, 95],
308
+ "plan": null,
309
+ "alertsEnabled": true,
310
+ "reportsEnabled": false,
311
+ "reportFrequency": "weekly",
312
+ "reportDay": 1,
313
+ "reportTime": "09:00"
314
+ }
315
+ ```
316
+
317
+ | Key | Default | Description |
318
+ |---|---|---|
319
+ | `killSwitchEnabled` | `false` | Enable the quota kill switch. When `true`, new Claude Code sessions are blocked once your quota reaches the threshold. |
320
+ | `killSwitchThreshold` | `95` | Quota percentage (0–100) at which the kill switch activates. Only relevant when `killSwitchEnabled` is `true`. |
321
+ | `warnThresholds` | `[70, 85, 95]` | Three quota percentages for yellow, orange, and red warnings in the dashboard and daemon alerts. |
322
+ | `plan` | `null` | Force plan detection. Valid values: `"pro"`, `"max5"`, `"max20"`. Leave `null` to auto-detect. |
323
+ | `alertsEnabled` | `true` | Enable daemon rate limit alerts — polls quota every 60s and logs a warning (with optional desktop notification) when thresholds are crossed. |
324
+ | `reportsEnabled` | `false` | Enable automatic AI-generated usage reports on a schedule. |
325
+ | `reportFrequency` | `"weekly"` | How often to generate reports. Valid values: `"weekly"`, `"biweekly"`, `"monthly"`. |
326
+ | `reportDay` | `1` | Day of week for reports (0=Sun, 1=Mon … 6=Sat). |
327
+ | `reportTime` | `"09:00"` | Time of day (HH:MM) when the report is generated. |
328
+
329
+ You can edit the file directly or use the CLI:
330
+
331
+ ```bash
332
+ # Enable kill switch at 90% quota
333
+ claudestat config --kill-switch true --threshold 90
334
+
335
+ # Force plan (useful if auto-detect is wrong)
336
+ claudestat config --plan max5
337
+ ```
338
+
339
+ ---
340
+
341
+ ## Troubleshooting
342
+
343
+ **`claudestat start` hangs for ~5 seconds**
344
+ Normal — `require('express')` takes a few seconds on first load. The daemon is starting.
345
+
346
+ **Hooks are not firing / dashboard shows no events**
347
+ Run `claudestat doctor` — it checks every component and prints the exact fix command.
348
+ If hooks were installed before upgrading, run `claudestat uninstall && claudestat install` to refresh.
349
+
350
+ **`claudestat` command not found after install**
351
+ If using NVM, the binary may point to the wrong Node version:
352
+ ```bash
353
+ nvm use default && npm install -g @statforge/claudestat
354
+ hash -r claudestat # macOS/Linux — refresh shell binary cache
355
+ ```
356
+
357
+ **Working with multiple projects**
358
+ 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.
359
+
360
+ **Approaching rate limit**
361
+ 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`.
362
+ To see current quota at any time: `claudestat status`
363
+
364
+ **Kill switch is blocking new sessions**
365
+ The kill switch only activates when `killSwitchEnabled: true` AND `cyclePct >= killSwitchThreshold`.
366
+ To disable: `claudestat config --kill-switch false`
367
+ Or wait for the 5h quota window to reset (check time remaining with `claudestat status`).
368
+
369
+ **`node:sqlite` experimental warning**
370
+ Expected on Node 22+. claudestat suppresses it automatically — you won't see it in normal use.
371
+
372
+ ---
373
+
374
+ ## Roadmap
375
+
376
+ Planned for upcoming versions:
377
+
378
+ - **Multi-account support** — track usage across multiple Claude accounts
379
+ - **Slack / webhook alerts** — get notified when quota reaches warning thresholds
380
+ - **VS Code extension** — sidebar panel with live stats inside the editor
381
+
382
+ Have an idea? [Open an issue](https://github.com/DeibyGS/claudestat/issues) or submit a PR.
383
+
384
+ ---
385
+
386
+ ## Uninstall
387
+
388
+ ```bash
389
+ claudestat uninstall # removes hooks from Claude Code settings
390
+
391
+ # macOS / Linux:
392
+ rm -rf ~/.claudestat # removes DB, config, and PID file
393
+
394
+ # Windows (PowerShell):
395
+ Remove-Item -Recurse -Force "$env:USERPROFILE\.claudestat"
396
+ ```
397
+
398
+ ---
399
+
400
+ ## Contributing
401
+
402
+ **claudestat is open source and PRs are welcome.**
403
+
404
+ 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.
405
+
406
+ ### How to contribute
407
+
408
+ 1. Fork the repository
409
+ 2. Create a branch: `git checkout -b feat/your-feature`
410
+ 3. Make your changes
411
+ 4. Run the test suite: `npm test` (208 tests)
412
+ 5. Open a PR with a clear description of what you changed and why
413
+
414
+ ### Good first areas
415
+
416
+ - **Pattern analyzer** (`src/pattern-analyzer.ts`) — add new usage patterns or improve thresholds
417
+ - **Dashboard components** (`dashboard/src/components/`) — UI improvements, new charts, accessibility
418
+ - **New commands** — ideas like `claudestat compare`
419
+ - **Bug reports** — open an issue with steps to reproduce and your Node/OS version
420
+
421
+ ### Running locally
422
+
423
+ ```bash
424
+ git clone https://github.com/YOUR_USERNAME/claudestat
425
+ cd claudestat
426
+ npm install
427
+ npm run dev:full # starts daemon + dashboard hot-reload together
428
+ npm test # run all tests
429
+ ```
430
+
431
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for full guidelines.
432
+
433
+ ---
434
+
435
+ ## License
436
+
437
+ MIT — use it, fork it, ship it.