claude-rpc 1.5.4 → 1.6.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/README.md CHANGED
@@ -142,13 +142,18 @@ The web dashboard pushes updates via SSE; the TUI refreshes on a 3-second tick.
142
142
 
143
143
  ### beyond your machine
144
144
 
145
- Shields-style badges and a poster-style summary card you can paste into a README or a Discord message. The fastest path is one command:
145
+ Stat cards and badges for a README, a site or a Discord message, all from one command. Run it bare for a menu: pick a card, then a **live link** (paste once, it refreshes itself), a **PNG** or an **SVG**:
146
146
 
147
147
  ```sh
148
- claude-rpc readme # prints paste-ready README badge markdown
149
- claude-rpc readme --raw | pbcopy # straight to your clipboard
148
+ claude-rpc statcards # menu: card → link / PNG / SVG
149
+ claude-rpc statcards stats --link --md | pbcopy # README markdown, straight to the clipboard
150
+ claude-rpc statcards poster --png # ./claude-poster.png, 2× for Discord / X
151
+ claude-rpc statcards badge --metric streak --svg # ./claude-badge-streak.svg
152
+ claude-rpc statcards list # every card and where it can go
150
153
  ```
151
154
 
155
+ Cards: `stats` (totals + year heatmap), `profile`, `badge`, `heatmap`, `poster`, `session`, `wrapped`. PNGs are drawn by whatever the machine already has (rsvg-convert, or Chrome / Edge / Brave / Chromium headless; Edge ships with Windows), so there is still nothing to install. The link option prints the URL, Markdown and an `<img>` tag, and copies the Markdown.
156
+
152
157
  **Live stats + year heatmap, paste once.** With a public profile (`claude-rpc profile set --handle <you> && claude-rpc profile on`), the community worker serves an always-current stats card with your last 12 months as a heatmap. You don't need `gh` or a gist, and there's nothing to re-run:
153
158
 
154
159
  ```md
@@ -171,27 +176,16 @@ The smaller card and badges are still there:
171
176
 
172
177
  The card shows tokens, sessions, active hours and streak; badge `metric=` is one of `tokens · sessions · hours · streak` (optional `&label=` to retitle). Both refresh themselves as the daemon flushes your profile (~every 30 min). Your profile page at `/u/<you>` has a one-click "copy" for the whole block.
173
178
 
174
- Prefer to render locally? `badge`/`card`/`calendar`/`github-stat` all write SVG, and `--gist` self-hosts a live one:
175
-
176
- ```sh
177
- claude-rpc badge --metric hours --range 7d --out claude-hours.svg
178
- claude-rpc badge --metric streak --out claude-streak.svg
179
- claude-rpc badge --metric hours --gist # publish to a gist (live README badge)
180
- claude-rpc card --range year --out year-on-claude.svg
181
- claude-rpc calendar --metric tokens --out heatmap.svg # year heatmap (hours by default)
182
- claude-rpc calendar --card --out stats.svg # stats + heatmap, offline
183
- ```
179
+ No public profile? Every card except `wrapped` also renders offline from your local stats, as PNG or SVG (`statcards <card> --png` / `--svg`). The older one-card commands (`badge`, `card`, `calendar`, `github-stat`, `session-card`, `readme`) still work, including `--gist`.
184
180
 
185
181
  <div align="center">
186
182
  <img src="site/examples/week-on-claude.svg" width="270" alt="Week-on-claude summary card" />
187
183
  <img src="site/examples/month-on-claude.svg" width="270" alt="Month-on-claude summary card" />
188
184
  <img src="site/examples/year-on-claude.svg" width="270" alt="Year-on-claude summary card — hours, prompts, tokens, lines, cost, daily activity strip" />
189
185
  <br/>
190
- <sub><code>card --range week · month · year</code> (also <code>all</code>) — live at <code>/api/card.svg</code> while <code>claude-rpc serve</code> is running</sub>
186
+ <sub><code>statcards poster --range week · month · year</code> (also <code>all</code>) — live at <code>/api/card.svg</code> while <code>claude-rpc serve</code> is running</sub>
191
187
  </div>
192
188
 
193
- `badge --gist` writes the SVG to your own GitHub gist (creates one on first run, updates it after — id remembered in `config.json`). The URL printed back is README-ready and updates every time you re-run the command. Uses `gh` if available, else `GH_TOKEN` with `gist` scope.
194
-
195
189
  Live equivalents while `claude-rpc serve` is running (the local dashboard server — the daemon itself serves no HTTP):
196
190
 
197
191
  - `http://127.0.0.1:47474/api/badge.svg?metric=hours&range=7d`
@@ -253,9 +247,9 @@ Per-project, runtime, or auto-detected — whichever fits how you work.
253
247
  Or from the command line, in any project:
254
248
 
255
249
  ```sh
256
- claude-rpc private # add cwd to ~/.claude-rpc/private-list.json
257
- claude-rpc public # remove cwd
258
- claude-rpc privacy # show the resolved visibility for the current dir
250
+ claude-rpc private # hide this folder (adds it to ~/.claude-rpc/private-list.json)
251
+ claude-rpc private off # show it again
252
+ claude-rpc private status # what Discord sees for this folder, and why
259
253
  ```
260
254
 
261
255
  Or globally, in `config.json`:
@@ -306,7 +300,9 @@ It's a thin bootstrapper — on the first session it just runs `npx claude-rpc@l
306
300
 
307
301
  ## commands
308
302
 
309
- `claude-rpc --help` lists them all — and after `setup` you rarely need any.
303
+ `claude-rpc help` lists them all, grouped; `claude-rpc help <command>` (or `<command> --help`) shows one command's options and examples. After `setup` you rarely need any.
304
+
305
+ **Tab completion:** `claude-rpc completion install` turns it on for bash, zsh, fish or PowerShell (setup offers it too). `claude-rpc re<Tab>` → `recap` / `restart`, `claude-rpc scan --<Tab>` → `--force`, and flag values, project names and files complete as well. A typo gets a "did you mean".
310
306
 
311
307
  <details>
312
308
  <summary><b>full command reference</b></summary>
@@ -315,43 +311,47 @@ It's a thin bootstrapper — on the first session it just runs `npx claude-rpc@l
315
311
 
316
312
  | Command | What it does |
317
313
  | ---------------- | ------------ |
318
- | `setup` (or `install`) | Install Claude Code hooks + login autostart, seed config, start the daemon (test-fires one synthetic SessionStart to prove the pipe works). `--link <code>` also links this machine to your verified profile |
319
- | `uninstall` | Remove Claude Code hooks + the login-autostart entry (keeps your data) |
320
- | `upgrade-config` | Re-run idempotent migrations on `config.json` |
321
- | `start` / `stop` / `restart` | Lifecycle for the detached daemon |
322
- | `status` | Interactive TUI — heatmap, hour histogram, leaderboards (`--dump`, or `dump`, for plain output) |
323
- | `today` / `week` | Focused views (today's stats, weekday breakdown) |
324
- | `compare` | This week vs last week, side by side |
325
- | `projects` / `project <name>` | Every project ranked by active time (`--limit N`) / one project's full record + recent daily rhythm |
326
- | `usage` | Subscription limits — session + weekly %, the same numbers `/usage` shows |
327
- | `serve` | Open the local web dashboard (port 47474) |
328
- | `preview` | Render every rotation frame against real state |
329
- | `vars` | Dump the full template-var list as JSON |
330
- | `scan` / `rescan`| Incremental / forced re-parse of `~/.claude/projects` |
331
- | `backfill <dir>` | Import transcripts from any folder (backup, other machine) |
332
- | `insights` | Print 3–5 auto-generated lines about your week |
333
- | `recap` | Standup summary — yesterday's work, paste-ready (`today\|week\|date`, `--md`) |
334
- | `export` | Dump the aggregate as JSON, or daily rows as CSV (`--csv` `--out`) |
335
- | `badge` | Shields-style SVG (`--metric` `--range` `--out` `--gist`) |
336
- | `card` | Poster-style SVG (`--range year\|month\|week\|all`) |
337
- | `github-stat` | Embeddable profile stat card (`--handle` `--out` `--gist`) |
338
- | `calendar` | Year activity heatmap SVG (`--metric hours\|tokens` `--card` `--out` `--gist`) |
339
- | `session-card` | Recap card for the current session (`--out`) |
340
- | `readme` | Paste-ready README badge markdown for your profile (`--raw` to pipe) |
314
+ | **Get started** | |
315
+ | `setup` | Install Claude Code hooks + login autostart, seed config, start the daemon. `--link <code>` also links this machine to your verified profile (`--wrapped` publishes your year too) |
316
+ | `completion` | Tab completion: `install`, `uninstall`, or print the `bash` / `zsh` / `fish` / `powershell` script |
317
+ | `uninstall` | Remove hooks, login autostart, PATH entry and tab completion (keeps your data) |
318
+ | **Your stats** | |
319
+ | `status` | Interactive TUI: heatmap, hour histogram, leaderboards (`--dump` for plain output) |
320
+ | `today` | Today's stats + when in the day you code |
321
+ | `week` | This week day by day; `--compare` puts it next to last week |
322
+ | `projects [name]`| Every project ranked by active time (`--limit N`), or one project's full record + recent daily rhythm |
323
+ | `usage` | Subscription limits: session + weekly %, the same numbers `/usage` shows |
324
+ | `recap` | Standup summary, yesterday by default (`today\|week\|YYYY-MM-DD`, `--md`, `--json`) |
325
+ | `insights` | 3–5 auto-generated lines about your history |
326
+ | `wrapped` | Your animated year in review; `--publish` puts it on `claude-rpc.com/wrapped/<handle>` |
327
+ | `serve` | The local web dashboard (port 47474) |
328
+ | `export` | The aggregate as JSON, or daily rows as CSV (`--csv` `--out`) |
329
+ | **Share** | |
330
+ | `statcards [card]` | Cards and badges as a live link, PNG or SVG: `stats` `profile` `badge` `heatmap` `poster` `session` `wrapped` (`--link` `--png [file]` `--svg [file]` `--md` `--html` `--metric` `--range` `--copy`; bare = menu) |
341
331
  | `statusline` | One-line status for tmux/shell prompts (`--template`) |
342
- | `mcp install` / `mcp uninstall` | Wire / remove the stats MCP server in Claude Code (one command) |
343
- | `mcp` | Run the MCP server (stdio) for Claude Code |
344
- | `wrapped` | Open your animated year-in-review (Claude Wrapped); `--publish` puts it on `claude-rpc.com/wrapped/<handle>` |
345
- | `pause` / `resume` | Snooze the Discord card everywhere (`pause [30m\|2h]`, default 1h; `pause status`, `pause off`); `unpause` = `resume` |
346
- | `private` / `public` / `privacy` | Per-cwd visibility toggles + status |
347
- | `community` | Anonymous community totals, on by default for fresh installs — `status` \| `off` \| `on` \| `report` |
348
- | `profile` | Opt-in public leaderboard profile — `status` \| `set` \| `on` \| `off` \| `publish` \| `verify` |
349
- | `squad` | Private mini-leaderboards with friends — `status` \| `create <name>` \| `join <code>` \| `leave [id]` |
350
- | `link` | One profile across machines: `link` mints a code on your verified machine, `link <code>` claims it on the new one |
332
+ | `mcp` | The stats MCP server (stdio); `mcp install` / `mcp uninstall` wire it into Claude Code |
333
+ | **Privacy** | |
334
+ | `private [on\|off\|status]` | Hide this folder from Discord, show it again, or see how it resolves |
335
+ | `pause [30m\|2h\|off\|status]` | Hide the card everywhere for a while (default 1h) |
336
+ | **Online** | |
337
+ | `profile` | Opt-in public leaderboard profile: `status` \| `set` \| `on` \| `off` \| `publish` \| `verify` |
338
+ | `squad` | Private mini-leaderboards with friends: `status` \| `create <name>` \| `join <code>` \| `leave [id]` |
339
+ | `link [code]` | One profile across machines: `link` mints a code on your verified machine, `link <code>` claims it on the new one |
340
+ | `community` | Anonymous community totals, on by default for fresh installs: `status` \| `off` \| `on` \| `report` |
341
+ | **Daemon** | |
342
+ | `start` / `stop` / `restart` | Lifecycle for the detached daemon |
343
+ | `logs` | Follow the daemon log |
344
+ | **Troubleshoot** | |
351
345
  | `doctor` | Diagnostic checklist with one-line fix hints (`--fix` to auto-repair) |
352
- | `tail` / `logs` / `log` | Tail the daemon log |
346
+ | `scan` | Re-count your history from `~/.claude/projects` (`--force` re-parses everything) |
347
+ | `backfill <dir>` | Import transcripts from any folder (backup, other machine) |
348
+ | `preview` | Render every rotation frame against real state |
349
+ | `vars` | The full template-variable list as JSON |
350
+ | `upgrade-config` | Re-run idempotent migrations on `config.json` |
353
351
  | `daemon` | Run the daemon in the foreground (debugging) |
354
352
 
353
+ Older names still work and always will within 1.x: `install` (setup), `dump` (status --dump), `compare` (week --compare), `project <name>` (projects <name>), `rescan` (scan --force), `resume` / `unpause` (pause off), `public` (private off), `privacy` (private status), `tail` / `log` (logs), and `badge`, `card`, `github-stat`, `calendar`, `session-card`, `readme` (statcards).
354
+
355
355
  Exit codes: `0` ok · `1` user error · `2` system error · `3` wrong state. `--version` and `--help` work as expected.
356
356
 
357
357
  </details>
@@ -395,9 +395,9 @@ rm -rf ~/.claude-rpc # stats; plus the per-OS config dir if you want it g
395
395
 
396
396
  <br/>
397
397
 
398
- - **Discord doesn't show anything.** Discord *desktop* must be running. The browser client doesn't expose the local IPC bridge. `claude-rpc tail` shows what the daemon is actually doing.
398
+ - **Discord doesn't show anything.** Discord *desktop* must be running. The browser client doesn't expose the local IPC bridge. `claude-rpc logs` shows what the daemon is actually doing.
399
399
  - **Hooks don't fire.** `claude-rpc setup` re-registers them and now test-fires a synthetic `SessionStart` end-to-end, so a broken hook command surfaces immediately. Restart Claude Code afterwards so it re-reads its hook config.
400
- - **Config error.** Bad JSON in `config.json` no longer crashes anything — the daemon logs one line and falls back to baked defaults. `claude-rpc tail` shows the parse error verbatim.
400
+ - **Config error.** Bad JSON in `config.json` no longer crashes anything — the daemon logs one line and falls back to baked defaults. `claude-rpc logs` shows the parse error verbatim.
401
401
  - **Old binary path baked into hooks.** Common after manual exe replacement. `claude-rpc setup` rewrites hook entries to point at the canonical install location.
402
402
 
403
403
  </details>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-rpc",
3
- "version": "1.5.4",
3
+ "version": "1.6.0",
4
4
  "description": "Discord Rich Presence for Claude Code — live model, project, tokens, and lifetime stats driven by Claude Code's hook system.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,6 +32,7 @@
32
32
  "dist:mac": "npm run build:exe && npm run prep:dashboard && npm --prefix dashboard run dist:mac",
33
33
  "dist:win": "npm run build:exe && npm run prep:dashboard && npm --prefix dashboard run dist:win",
34
34
  "test": "node ./scripts/run-tests.mjs",
35
+ "release": "node ./scripts/release.mjs",
35
36
  "lint": "eslint src test vscode-extension",
36
37
  "format": "prettier --write \"src/**/*.js\" \"test/**/*.js\"",
37
38
  "format:check": "prettier --check \"src/**/*.js\" \"test/**/*.js\"",
package/src/cli.js CHANGED
@@ -5,7 +5,7 @@ import './safe-stdio.js';
5
5
  import { readFileSync, writeFileSync, existsSync, watchFile, unlinkSync } from 'node:fs';
6
6
  import process from 'node:process';
7
7
  import { basename, join } from 'node:path';
8
- import { DAEMON_SCRIPT, STATE_PATH, STATE_DIR, LOG_PATH, AGGREGATE_PATH, CONFIG_PATH, IS_PACKAGED, IS_NPX, EXE_PATH } from './paths.js';
8
+ import { DAEMON_SCRIPT, STATE_PATH, STATE_DIR, LOG_PATH, AGGREGATE_PATH, CONFIG_PATH, USER_CONFIG_DIR, IS_PACKAGED, IS_NPX, EXE_PATH } from './paths.js';
9
9
  import { VERSION } from './version.js';
10
10
  import { c, fail, tailLines, heat, sparkline, fmtDelta, topPercentile, EX_USER_ERROR, EX_BAD_STATE, EX_SYS_ERROR } from './ui.js';
11
11
  import * as lb from './leaderboard.js';
@@ -693,14 +693,14 @@ function showProjects(argv = []) {
693
693
  });
694
694
  if (ranked.length > limit) lines.push(`${c.dim}… ${ranked.length - limit} more — --limit ${ranked.length} to see all${c.reset}`);
695
695
  box('projects', lines, 76);
696
- console.log(`\n ${c.dim}drill in: ${c.reset}${c.cyan}claude-rpc project <name>${c.reset}\n`);
696
+ console.log(`\n ${c.dim}drill in: ${c.reset}${c.cyan}claude-rpc projects <name>${c.reset}\n`);
697
697
  }
698
698
 
699
699
  // `project <name>` — one project's full record + its recent daily rhythm
700
700
  // (attributed per-day since scan cache v5).
701
701
  function showProject(rawName) {
702
702
  if (!rawName) {
703
- console.log(`\n Usage: ${c.cyan}claude-rpc project <name>${c.reset} (see ${c.cyan}claude-rpc projects${c.reset})\n`);
703
+ console.log(`\n Usage: ${c.cyan}claude-rpc projects <name>${c.reset} (see ${c.cyan}claude-rpc projects${c.reset})\n`);
704
704
  process.exitCode = EX_USER_ERROR;
705
705
  return;
706
706
  }
@@ -1238,13 +1238,7 @@ function doReadme(argv) {
1238
1238
  }
1239
1239
 
1240
1240
  console.log('');
1241
- console.log(` ${c.dim}── self-host on a GitHub gist instead (works without a profile) ──${c.reset}`);
1242
- console.log(` ${c.cyan}claude-rpc badge --metric hours --gist${c.reset} ${c.dim}# prints README markdown${c.reset}`);
1243
- console.log('');
1244
- console.log(` ${c.dim}Shareable cards:${c.reset}`);
1245
- console.log(` ${c.cyan}claude-rpc card --range year --out year.svg${c.reset} ${c.dim}# poster${c.reset}`);
1246
- console.log(` ${c.cyan}claude-rpc calendar --gist${c.reset} ${c.dim}# live year heatmap${c.reset}`);
1247
- console.log(` ${c.cyan}claude-rpc github-stat --gist${c.reset} ${c.dim}# profile stat card${c.reset}`);
1241
+ console.log(` ${c.dim}Every card as a link, PNG or SVG, from a menu:${c.reset} ${c.cyan}claude-rpc statcards${c.reset}`);
1248
1242
  console.log('');
1249
1243
  }
1250
1244
 
@@ -1335,7 +1329,7 @@ async function doPrivacy() {
1335
1329
  for (const p of list) console.log(` ${p === cwd ? c.cyan + '●' + c.reset : ' '} ${p}`);
1336
1330
  }
1337
1331
  console.log('');
1338
- console.log(` ${c.dim}toggle: claude-rpc private / claude-rpc public${c.reset}`);
1332
+ console.log(` ${c.dim}toggle: claude-rpc private / claude-rpc private off${c.reset}`);
1339
1333
  console.log(` ${c.dim}per-proj: drop a {"private": true} into .claude-rpc.json at the repo root${c.reset}`);
1340
1334
  console.log('');
1341
1335
  }
@@ -1369,7 +1363,7 @@ async function doPause(argv) {
1369
1363
  }
1370
1364
  const until = setPause(ms);
1371
1365
  console.log(` ${c.green}✓${c.reset} presence paused until ${c.cyan}${fmtClock(until)}${c.reset}`);
1372
- console.log(` ${c.dim}the daemon clears the card within seconds — resume early with ${c.reset}${c.cyan}claude-rpc resume${c.reset}`);
1366
+ console.log(` ${c.dim}the daemon clears the card within seconds — resume early with ${c.reset}${c.cyan}claude-rpc pause off${c.reset}`);
1373
1367
  }
1374
1368
 
1375
1369
  async function doResume() {
@@ -2292,81 +2286,103 @@ function overview() {
2292
2286
  console.log('');
2293
2287
  }
2294
2288
 
2295
- function help() {
2296
- const cmds = [
2297
- ['setup', 'Install Claude Code hooks + login autostart (Run key / LaunchAgent / systemd --user)'],
2298
- ['install', 'Same as setup'],
2299
- ['setup --link <code>', 'One-liner onboarding: install + verify via a claude-rpc.com code (+ --wrapped publishes your year)'],
2300
- ['uninstall', 'Remove Claude Code hooks + the login autostart entry'],
2301
- ['upgrade-config', 'Re-run idempotent migrations on an existing config.json'],
2302
- ['start', 'Start the Discord RPC daemon (detached)'],
2303
- ['stop', 'Stop the daemon'],
2304
- ['restart', 'Stop then start the daemon'],
2305
- ['status', 'Interactive stats TUI; --dump (or piped) prints static text'],
2306
- ['dump', 'Same as status --dump'],
2307
- ['today', 'Focus view: today\'s stats + 24h activity histogram'],
2308
- ['week', 'Focus view: this week, daily breakdown'],
2309
- ['compare', 'This week vs last week — the full side-by-side diff'],
2310
- ['projects', 'Every project ranked by active time (--limit N)'],
2311
- ['project', 'One project\'s full record + recent daily rhythm'],
2312
- ['usage', 'Subscription limits — session + weekly % (what /usage shows)'],
2313
- ['serve', 'Open a live web dashboard in your browser'],
2314
- ['preview', 'Show how each rotation frame renders right now'],
2315
- ['vars', 'Print every template variable and its live value (JSON)'],
2316
- ['scan', 'Incrementally scan ~/.claude/projects for all-time totals'],
2317
- ['rescan', 'Force re-parse every transcript (ignores cache)'],
2318
- ['backfill', 'Import transcripts from any folder (e.g. a backup)'],
2319
- ['insights', 'Auto-generated insights from your history'],
2320
- ['recap', 'Standup summary (yesterday by default; today|week|date, --md for markdown)'],
2321
- ['badge', 'Render a Shields-style SVG (--metric --range --out --gist)'],
2322
- ['card', 'Render a poster-style SVG summary (--range year|month|week|all)'],
2323
- ['github-stat', 'Render an embeddable profile stat card (--handle --out --gist)'],
2324
- ['statusline', 'One-line status for tmux/shell prompts (--template)'],
2325
- ['calendar', 'Year activity heatmap SVG (--metric hours|tokens --card --out --gist)'],
2326
- ['session-card', 'Recap card for the current session (--out)'],
2327
- ['readme', 'Paste-ready README card + badges for your profile (--raw to pipe)'],
2328
- ['mcp install', 'Wire the stats MCP server into Claude Code (one command)'],
2329
- ['mcp uninstall', 'Remove the stats MCP server from Claude Code'],
2330
- ['mcp', 'Run the MCP server (stdio) — exposes your stats to Claude'],
2331
- ['wrapped', 'Open your animated year-in-review (Claude Wrapped)'],
2332
- ['wrapped --publish', 'Put your Wrapped on the web at claude-rpc.com/wrapped/<handle>'],
2333
- ['pause', 'Snooze the Discord card globally (pause [30m|2h], default 1h)'],
2334
- ['pause status|off', 'Show whether presence is paused / lift a pause early'],
2335
- ['resume', 'Lift a pause early'],
2336
- ['unpause', 'Same as resume'],
2337
- ['export', 'Dump the aggregate as JSON, or daily rows as CSV (--csv --out)'],
2338
- ['private', 'Mark the current directory as private (hide from Discord)'],
2339
- ['public', 'Un-mark the current directory'],
2340
- ['privacy', 'Show resolved visibility for the current directory'],
2341
- ['community', 'Opt in/out of anonymous community totals (on|off|status|report)'],
2342
- ['profile', 'Public leaderboard identity (status|set|on|off|publish|verify)'],
2343
- ['squad', 'Private mini-leaderboards with friends (create|join|leave|status)'],
2344
- ['link', 'Link machines into one profile (mints a code; `link <code>` claims it)'],
2345
- ['doctor', 'Run a diagnostic checklist — common-failure triage (--fix to auto-repair)'],
2346
- ['tail', 'Tail the daemon log file'],
2347
- ['logs', 'Same as tail (also: log)'],
2348
- ['daemon', 'Run daemon in foreground (debug)'],
2349
- ];
2350
- const colW = cmds.reduce((m, [name]) => Math.max(m, name.length), 0);
2351
- console.log('');
2352
- console.log(` ${c.bold}${c.magenta}◆ claude-rpc${c.reset} ${c.dim}— Discord Rich Presence for Claude Code${c.reset}`);
2353
- console.log('');
2354
- console.log(` ${c.dim}Commands:${c.reset}`);
2355
- for (const [name, desc] of cmds) {
2356
- console.log(` ${c.cyan}${name.padEnd(colW)}${c.reset} ${desc}`);
2289
+ async function help(name) {
2290
+ const { renderHelp, renderCommandHelp } = await import('./help.js');
2291
+ if (!name) { console.log(renderHelp()); return; }
2292
+ const page = renderCommandHelp(name);
2293
+ if (page) { console.log(page); return; }
2294
+ const { suggestCommand } = await import('./commands.js');
2295
+ const guess = suggestCommand(name);
2296
+ fail(`no command called \`${name}\``, {
2297
+ hint: guess ? `did you mean \`claude-rpc help ${guess}\`?` : 'claude-rpc help lists them all',
2298
+ code: EX_USER_ERROR,
2299
+ });
2300
+ }
2301
+
2302
+ // `__complete <words…>` — candidates for the shell scripts in completion.js,
2303
+ // one per line. Never prints errors: a broken <Tab> must stay silent.
2304
+ async function doComplete(words) {
2305
+ const { complete } = await import('./commands.js');
2306
+ if (process.env.CLAUDE_RPC_COMP_CUR !== undefined) words = [...words, process.env.CLAUDE_RPC_COMP_CUR];
2307
+ const projects = () => {
2308
+ try { return Object.keys(JSON.parse(readFileSync(AGGREGATE_PATH, 'utf8')).projects || {}); } catch { return []; }
2309
+ };
2310
+ try {
2311
+ const out = complete(words, { projects });
2312
+ if (out.length) process.stdout.write(out.join('\n') + '\n');
2313
+ } catch { /* stay silent */ }
2314
+ }
2315
+
2316
+ // `completion [install|uninstall|<shell>]`
2317
+ async function doCompletion(argv) {
2318
+ const comp = await import('./completion.js');
2319
+ const { SHELLS } = await import('./commands.js');
2320
+ const sub = argv[0] || '';
2321
+ if (SHELLS.includes(sub)) { process.stdout.write(comp.scriptFor(sub)); return; }
2322
+ const shell = (sub === 'install' && argv[1]) || comp.detectShell();
2323
+ if (sub === 'install' && !SHELLS.includes(shell)) {
2324
+ return fail(`unknown shell: ${shell}`, { hint: `one of: ${SHELLS.join(', ')}`, code: EX_USER_ERROR });
2325
+ }
2326
+ const opts = { configDir: USER_CONFIG_DIR, profilePath: shell === 'powershell' ? await comp.powershellProfile() : undefined };
2327
+ if (sub === 'install') {
2328
+ let r;
2329
+ try { r = comp.install(shell, opts); } catch (e) { return fail(e.message, { code: EX_SYS_ERROR }); }
2330
+ if (!r.changed) { console.log(` ${c.green}✓${c.reset} tab completion already on for ${c.bold}${shell}${c.reset}`); return; }
2331
+ console.log(` ${c.green}✓${c.reset} tab completion on for ${c.bold}${shell}${c.reset} ${c.dim}${shortPath(r.rc || r.script)}${c.reset}`);
2332
+ const reload = shell === 'fish' ? 'works in new fish sessions'
2333
+ : shell === 'powershell' ? 'open a new PowerShell window'
2334
+ : `open a new terminal, or: ${c.reset}${c.cyan}source ${shortPath(r.rc)}${c.reset}${c.dim}`;
2335
+ console.log(` ${c.dim}${reload} — then try ${c.reset}${c.cyan}claude-rpc st<Tab>${c.reset}`);
2336
+ return;
2357
2337
  }
2338
+ if (sub === 'uninstall') {
2339
+ const touched = comp.uninstall(opts);
2340
+ console.log(touched.length
2341
+ ? ` ${c.green}✓${c.reset} tab completion removed ${c.dim}${touched.map(shortPath).join(', ')}${c.reset}`
2342
+ : ` ${c.cyan}·${c.reset} tab completion wasn't installed`);
2343
+ return;
2344
+ }
2345
+ if (sub) return fail(`unknown option: ${sub}`, { hint: 'claude-rpc completion [install|uninstall|bash|zsh|fish|powershell]', code: EX_USER_ERROR });
2346
+ const on = comp.isInstalled(shell, opts);
2358
2347
  console.log('');
2359
- console.log(` ${c.dim}First-time setup:${c.reset}`);
2360
- console.log(` 1. ${c.cyan}claude-rpc setup${c.reset} — wires hooks, seeds config, starts the daemon.`);
2361
- console.log(` 2. Open Claude Code and send a prompt — the card appears in Discord.`);
2362
- console.log(` 3. ${c.dim}(optional)${c.reset} Use your own Discord app: set ${c.cyan}clientId${c.reset} in ${c.cyan}config.json${c.reset} and upload art under Rich Presence → Art Assets: ${c.cyan}claude${c.reset}, ${c.cyan}working${c.reset}, ${c.cyan}idle${c.reset}, ${c.cyan}thinking${c.reset}.`);
2363
- console.log('');
2364
- console.log(` ${c.dim}Tip: ${c.reset}edit ${c.cyan}config.json${c.reset} to customize rotation frames. Run ${c.cyan}claude-rpc preview${c.reset} to see the result without Discord.`);
2348
+ console.log(` ${c.bold}${c.magenta}◆ Tab completion${c.reset} ${c.dim}— ${shell}${c.reset} ${on ? `${c.green}● on${c.reset}` : `${c.yellow}○ off${c.reset}`}`);
2365
2349
  console.log('');
2366
- console.log(` ${c.dim}Exit codes:${c.reset} ${c.dim}0 ok · 1 user error · 2 system error · 3 wrong state${c.reset}`);
2350
+ if (!on) console.log(` ${c.cyan}claude-rpc completion install${c.reset} ${c.dim}turn it on for ${shell}${c.reset}`);
2351
+ else console.log(` ${c.cyan}claude-rpc completion uninstall${c.reset} ${c.dim}turn it off${c.reset}`);
2352
+ console.log(` ${c.cyan}claude-rpc completion <shell>${c.reset} ${c.dim}print the script (${SHELLS.join(', ')})${c.reset}`);
2367
2353
  console.log('');
2368
2354
  }
2369
2355
 
2356
+ // Offer tab completion once during a first setup, on a terminal only.
2357
+ async function setupCompletionOffer() {
2358
+ if (!process.stdin.isTTY || !process.stdout.isTTY || process.env.CLAUDE_RPC_NO_COMPLETION) return;
2359
+ const comp = await import('./completion.js');
2360
+ const shell = comp.detectShell();
2361
+ const profilePath = shell === 'powershell' ? await comp.powershellProfile() : undefined;
2362
+ const opts = { configDir: USER_CONFIG_DIR, profilePath };
2363
+ if (shell === 'powershell' && !profilePath) return;
2364
+ if (comp.isInstalled(shell, opts)) return;
2365
+ const answer = (await prompt(` tab completion for ${shell}? ${c.dim}[Y/n]${c.reset} `)).trim().toLowerCase();
2366
+ if (answer && answer !== 'y' && answer !== 'yes') return;
2367
+ try {
2368
+ const r = comp.install(shell, opts);
2369
+ console.log(` ${c.green}✓${c.reset} ${'tab completion'.padEnd(16)}${c.dim}${shell} · ${shortPath(r.rc || r.script)} (new terminals)${c.reset}`);
2370
+ } catch (e) {
2371
+ console.log(` ${c.yellow}!${c.reset} ${'tab completion'.padEnd(16)}${c.dim}${e.message}${c.reset}`);
2372
+ }
2373
+ }
2374
+
2375
+ async function doStatcards(argv) {
2376
+ const { runStatcards } = await import('./statcards.js');
2377
+ await runStatcards(argv, {
2378
+ config: loadConfig(),
2379
+ aggregate: () => aggregateOr('render'),
2380
+ liveVars: () => liveVars().vars,
2381
+ prompt,
2382
+ enableProfile: () => profileEnable(true),
2383
+ });
2384
+ }
2385
+
2370
2386
  // Packaged exe: `claude-rpc.exe` with no args → first-run install + start.
2371
2387
  // `claude-rpc.exe hook PreToolUse` → handle hook.
2372
2388
  // Dev mode keeps the original `help` fallback so behavior is unchanged.
@@ -2395,7 +2411,12 @@ process.on('unhandledRejection', (e) => {
2395
2411
  // Fast-exit commands touch none of the core graph (they import their own
2396
2412
  // module, if any); daemon control needs only ensure-daemon. Everything else
2397
2413
  // loads the core once up front, so its bindings are set for every handler.
2398
- const FAST_PATHS = new Set(['--version', '-V', '-v', '--help', '-h', 'help', 'hook', 'mcp', 'daemon', 'serve', 'wrapped', 'scan-worker', 'tail', 'logs', 'log', 'pause', 'resume', 'unpause']);
2414
+ const FAST_PATHS = new Set(['--version', '-V', '-v', '--help', '-h', 'help', '__complete', 'hook', 'mcp', 'daemon', 'serve', 'wrapped', 'scan-worker', 'tail', 'logs', 'log', 'pause', 'resume', 'unpause']);
2415
+ // `<command> --help` → that command's page (before it runs at all).
2416
+ if (cmd && (args.includes('--help') || args.includes('-h')) && !['hook', 'scan-worker', '__complete'].includes(cmd)) {
2417
+ const { findCommand } = await import('./commands.js');
2418
+ if (findCommand(cmd)) { await help(cmd); return; }
2419
+ }
2399
2420
  if (['start', 'stop', 'restart'].includes(cmd)) await loadDaemonCtl();
2400
2421
  else if (!FAST_PATHS.has(cmd)) await loadCore();
2401
2422
  switch (cmd) {
@@ -2404,7 +2425,10 @@ process.on('unhandledRejection', (e) => {
2404
2425
  case '-v': console.log(`claude-rpc ${VERSION}`); break;
2405
2426
  case '--help':
2406
2427
  case '-h':
2407
- case 'help': help(); break;
2428
+ case 'help': await help(cmd === 'help' ? args[0] : undefined); break;
2429
+ case '__complete': await doComplete(args); break;
2430
+ case 'completion': await doCompletion(args); break;
2431
+ case 'statcards': await doStatcards(args); break;
2408
2432
  // `setup` and `install` are aliases as of v0.7: both register hooks AND
2409
2433
  // the login autostart entry (Windows Run key, macOS LaunchAgent, Linux
2410
2434
  // systemd --user unit). Older behavior split them (setup = no startup,
@@ -2489,11 +2513,17 @@ process.on('unhandledRejection', (e) => {
2489
2513
  // Optional GitHub connect — one explicit y/N, asked at most once ever.
2490
2514
  // The --link path above IS a connect, so it never double-asks.
2491
2515
  if (!linkCode) await setupGhConnect();
2516
+ if (changed) await setupCompletionOffer();
2492
2517
  }
2493
2518
  setupOutro(target, changed, cli);
2494
2519
  break;
2495
2520
  }
2496
- case 'uninstall': await (await import('./install.js')).uninstall(); break;
2521
+ case 'uninstall': {
2522
+ const { uninstall: completionOff } = await import('./completion.js');
2523
+ try { completionOff({ configDir: USER_CONFIG_DIR, profilePath: process.platform === 'win32' ? await (await import('./completion.js')).powershellProfile() : undefined }); } catch { /* best-effort */ }
2524
+ await (await import('./install.js')).uninstall();
2525
+ break;
2526
+ }
2497
2527
  case 'upgrade-config':
2498
2528
  if (!(await import('./install.js')).migrateConfig()) console.log(` ${c.green}✓${c.reset} config already current — nothing to migrate`);
2499
2529
  break;
@@ -2508,15 +2538,20 @@ process.on('unhandledRejection', (e) => {
2508
2538
  }
2509
2539
  case 'dump': await showStatus(); break;
2510
2540
  case 'today': await showToday(); break;
2511
- case 'week': await showWeek(); break;
2512
- case 'projects': showProjects(args); break;
2541
+ case 'week': if (args.includes('--compare')) showCompare(); else await showWeek(); break;
2542
+ case 'projects': {
2543
+ // `projects <name>` drills into one project (was `project <name>`).
2544
+ const name = args.find((a, i) => !a.startsWith('-') && args[i - 1] !== '--limit');
2545
+ if (name) showProject(name); else showProjects(args);
2546
+ break;
2547
+ }
2513
2548
  case 'project': showProject(args[0]); break;
2514
2549
  case 'compare': showCompare(); break;
2515
2550
  case 'usage': await showUsage(); break;
2516
2551
  case 'serve': await import('./server/index.js'); break;
2517
2552
  case 'preview': showPreview(); break;
2518
2553
  case 'vars': dumpVars(); break;
2519
- case 'scan': doScan(false); break;
2554
+ case 'scan': doScan(args.includes('--force') || args.includes('-f')); break;
2520
2555
  case 'rescan': doScan(true); break;
2521
2556
  case 'backfill': doBackfill(args); break;
2522
2557
  case 'insights': await showInsights(); break;
@@ -2542,7 +2577,14 @@ process.on('unhandledRejection', (e) => {
2542
2577
  case 'resume':
2543
2578
  case 'unpause': await doResume(); break;
2544
2579
  case 'export': await doExport(args); break;
2545
- case 'private': await doPrivate(); break;
2580
+ case 'private': {
2581
+ const sub = args[0] || 'on';
2582
+ if (sub === 'on') await doPrivate();
2583
+ else if (sub === 'off') await doPublic();
2584
+ else if (sub === 'status') await doPrivacy();
2585
+ else fail(`unknown option: ${sub}`, { hint: 'claude-rpc private [on|off|status]', code: EX_USER_ERROR });
2586
+ break;
2587
+ }
2546
2588
  case 'public': await doPublic(); break;
2547
2589
  case 'privacy': await doPrivacy(); break;
2548
2590
  case 'community': await doCommunity(args); break;
@@ -2652,9 +2694,11 @@ process.on('unhandledRejection', (e) => {
2652
2694
  : IS_NPX ? `npx claude-rpc@latest ${cmd}`
2653
2695
  : /[\\/]Cellar[\\/]/.test(DAEMON_SCRIPT) ? 'brew upgrade claude-rpc'
2654
2696
  : 'npm install -g claude-rpc@latest';
2697
+ const { suggestCommand } = await import('./commands.js');
2698
+ const guess = suggestCommand(cmd);
2655
2699
  fail(`unknown command: ${cmd}`, {
2656
- hint: [
2657
- 'run `claude-rpc --help` for the full command list',
2700
+ hint: guess ? `did you mean \`claude-rpc ${guess}\`?` : [
2701
+ 'run `claude-rpc help` for the full command list',
2658
2702
  `this install is v${VERSION} — if the docs mention \`${cmd}\`, update first: ${update}`,
2659
2703
  ],
2660
2704
  code: EX_USER_ERROR,