claudectx 1.1.1 → 1.1.3

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
@@ -80,12 +80,29 @@ claudectx convert --to cursor
80
80
 
81
81
  # Export your usage data for team-wide cost attribution
82
82
  claudectx teams export
83
+
84
+ # --- Safety: every command that modifies files backs up automatically ---
85
+
86
+ # See all automatic backups
87
+ claudectx revert --list
88
+
89
+ # Restore any backup (also backs up current file so you can undo the undo)
90
+ claudectx revert --id <id>
83
91
  ```
84
92
 
85
93
  ## Installation
86
94
 
87
95
  ```bash
96
+ # npm (recommended)
88
97
  npm install -g claudectx
98
+
99
+ # Homebrew
100
+ brew tap Horilla/claudectx
101
+ brew install claudectx
102
+
103
+ # pip (Python projects)
104
+ pip install claudectx-py
105
+ # then: npm install -g claudectx (the npm package is still required)
89
106
  ```
90
107
 
91
108
  ---
@@ -154,6 +171,8 @@ What it does:
154
171
  - **Cache advisor** — Finds date strings, timestamps, and other patterns that break prompt caching and comments them out.
155
172
  - **Hooks installer** — Installs a `PostToolUse` hook in `.claude/settings.local.json` so `claudectx watch` can track files in real time.
156
173
 
174
+ > **Safety:** `optimize` backs up your `CLAUDE.md` automatically before any changes. Run `claudectx revert --list` to restore.
175
+
157
176
  ---
158
177
 
159
178
  ### `claudectx watch` — Live token dashboard
@@ -214,6 +233,8 @@ claudectx compress --api-key <key> # Provide API key explicitly
214
233
 
215
234
  A typical 8,000-token session compresses to ~180 tokens — **97.8% reduction**.
216
235
 
236
+ > **Safety:** `compress --prune` asks for confirmation before deleting entries and backs up `MEMORY.md` first. Run `claudectx revert --list` to restore.
237
+
217
238
  ---
218
239
 
219
240
  ### `claudectx report` — Usage analytics
@@ -269,14 +290,17 @@ Output shows per-file token counts, cache hit likelihood (based on your recent r
269
290
  Start each session with a cache hit instead of a full miss. Sends a silent priming request to Anthropic so your CLAUDE.md is cached before Claude Code touches it.
270
291
 
271
292
  ```bash
272
- claudectx warmup --api-key $ANTHROPIC_API_KEY # 5-min cache TTL (default)
273
- claudectx warmup --ttl 60 --api-key $ANTHROPIC_API_KEY # 60-min extended TTL
274
- claudectx warmup --cron "0 9 * * 1-5" --api-key ... # Install as daily cron job
275
- claudectx warmup --json # Output result as JSON
293
+ claudectx warmup --api-key $ANTHROPIC_API_KEY # 5-min cache TTL (default)
294
+ claudectx warmup --ttl 60 --api-key $ANTHROPIC_API_KEY # 60-min extended TTL (2× write cost)
295
+ claudectx warmup --model sonnet --api-key $ANTHROPIC_API_KEY # use a specific model
296
+ claudectx warmup --cron "0 9 * * 1-5" # Install as weekday 9am cron job
297
+ claudectx warmup --json # JSON output for scripting
276
298
  ```
277
299
 
278
300
  Reports tokens warmed, write cost, savings per cache hit, and break-even request count.
279
301
 
302
+ > **Note on `--cron`:** The API key is **not** embedded in the cron job. At runtime, the job reads `ANTHROPIC_API_KEY` from your environment. Set it in `~/.profile` or `~/.zshenv` so cron can see it.
303
+
280
304
  ---
281
305
 
282
306
  ### `claudectx drift` — CLAUDE.md stays fresh, not stale
@@ -286,8 +310,9 @@ Over time CLAUDE.md accumulates dead references and sections nobody reads. `drif
286
310
  ```bash
287
311
  claudectx drift # Scan current project
288
312
  claudectx drift --days 14 # Use 14-day read window (default: 30)
289
- claudectx drift --fix # Interactively remove flagged lines
313
+ claudectx drift --fix # Interactively remove flagged lines (creates CLAUDE.md.bak first)
290
314
  claudectx drift --json # JSON output
315
+ claudectx drift --path /other/proj # Scan a different project directory
291
316
  ```
292
317
 
293
318
  Detects 4 types of drift:
@@ -306,20 +331,26 @@ Detects 4 types of drift:
306
331
  Install named, pre-configured hooks beyond the basic read logger.
307
332
 
308
333
  ```bash
309
- claudectx hooks list # Show all available hooks
310
- claudectx hooks add auto-compress --config apiKey=sk-... # Install a hook
311
- claudectx hooks remove slack-digest # Remove an installed hook
312
- claudectx hooks status # Show what's installed
334
+ claudectx hooks list # Show all available hooks
335
+ claudectx hooks add auto-compress # Install with default threshold (50k tokens)
336
+ claudectx hooks add auto-compress --config threshold=30000 # Custom token threshold
337
+ claudectx hooks add slack-digest --config webhookUrl=https://hooks.slack.com/...
338
+ claudectx hooks remove slack-digest # Remove an installed hook
339
+ claudectx hooks status # Show what's installed
313
340
  ```
314
341
 
315
342
  **Built-in hooks:**
316
343
 
317
- | Hook | Trigger | What it does |
318
- |---|---|---|
319
- | `auto-compress` | PostToolUse (Read) | Runs `claudectx compress` after each session |
320
- | `daily-budget` | PreToolUse | Checks token budget before each tool call |
321
- | `slack-digest` | Stop | Posts session report to a Slack webhook |
322
- | `session-warmup` | PostToolUse (Read) | Re-warms the cache after each read |
344
+ | Hook | Trigger | Config | What it does |
345
+ |---|---|---|---|
346
+ | `auto-compress` | PostToolUse (Read) | `threshold` (default: 50000) | Runs `claudectx compress` after each session |
347
+ | `daily-budget` | PreToolUse | _(none)_ | Reports today's spend before each tool call |
348
+ | `slack-digest` | Stop | `webhookUrl` (required) | Posts session report to a Slack webhook |
349
+ | `session-warmup` | PostToolUse (Read) | _(none)_ | Re-warms the cache; reads `ANTHROPIC_API_KEY` from env |
350
+
351
+ > **Security note:** Hooks that need an API key (`compress`, `warmup`) read `ANTHROPIC_API_KEY` from your environment — no secrets are stored in `.claude/settings.local.json`.
352
+
353
+ > **Safety:** `hooks remove` asks for confirmation and backs up `.claude/settings.local.json` before removing. Run `claudectx revert --list` to restore.
323
354
 
324
355
  ---
325
356
 
@@ -336,6 +367,8 @@ claudectx convert --to cursor --dry-run # Preview without writing
336
367
 
337
368
  Each `##` section in CLAUDE.md becomes a separate Cursor `.mdc` file with `alwaysApply: true` frontmatter. `@file` references are stripped for assistants that don't support them.
338
369
 
370
+ > **Safety:** `convert` backs up any existing target file before overwriting. Run `claudectx revert --list` to restore.
371
+
339
372
  ---
340
373
 
341
374
  ### `claudectx teams` — Multi-developer cost attribution
@@ -344,22 +377,68 @@ See where the money goes across your whole team — without sharing session cont
344
377
 
345
378
  ```bash
346
379
  # Step 1: each developer runs this on their own machine
347
- claudectx teams export
380
+ claudectx teams export # Default: last 30 days, sonnet pricing
381
+ claudectx teams export --days 7 --model haiku # Custom window and model
348
382
 
349
383
  # Step 2: collect the JSON files in a shared directory, then aggregate
350
384
  claudectx teams aggregate --dir ./reports/
385
+ claudectx teams aggregate --dir ./reports/ --anonymize # Replace names with Dev 1, Dev 2...
386
+ claudectx teams aggregate --dir ./reports/ --json # Machine-readable JSON
351
387
 
352
388
  # Optional: copy your export to a shared location
353
389
  claudectx teams share --to /shared/reports/
354
-
355
- # Anonymize for review
356
- claudectx teams aggregate --dir ./reports/ --anonymize
357
390
  ```
358
391
 
359
392
  Output shows per-developer spend, cache hit rate, avg request size, and top shared files. Exports are lightweight JSON — no session content, no prompts, just aggregated token counts.
360
393
 
361
394
  ---
362
395
 
396
+ ### `claudectx revert` — Restore any backup
397
+
398
+ Every command that modifies your files creates an automatic backup in `~/.claudectx/backups/` before touching anything. If something goes wrong — or you just changed your mind — you can always recover.
399
+
400
+ ```bash
401
+ claudectx revert --list # See all backups with timestamps and size
402
+ claudectx revert --id <id> # Restore a specific backup
403
+ claudectx revert # Interactive: pick from list
404
+ claudectx revert --file CLAUDE.md # Filter to backups of one file
405
+ ```
406
+
407
+ Example output of `claudectx revert --list`:
408
+
409
+ ```
410
+ claudectx — Backup History
411
+ ══════════════════════════════════════════════════════════════════
412
+ ID File Command When
413
+ ──────────────────────────────────────────────────────────────────
414
+ 20260412T083012m445-1842... CLAUDE.md optimize 2 hours ago
415
+ 20260411T211533m102-9913... MEMORY.md compress 1 day ago
416
+ 20260411T094201m773-3371... copilot-instr... convert 2 days ago
417
+ ```
418
+
419
+ When you restore, claudectx backs up the **current** file first — so you can undo the undo:
420
+
421
+ ```
422
+ ⚠ This will overwrite /path/to/CLAUDE.md with the backup from 2 hours ago.
423
+ Your current file will be backed up first (so you can undo this).
424
+ Restore? [y/N]
425
+ ```
426
+
427
+ **Safety:** Backups are kept for the 50 most recent operations, then auto-pruned. They are stored only on your local machine.
428
+
429
+ **Which commands create backups automatically:**
430
+
431
+ | Command | What gets backed up |
432
+ |---|---|
433
+ | `optimize --claudemd` | `CLAUDE.md` (before split) |
434
+ | `optimize --cache` | `CLAUDE.md` (before cache-busting lines are commented out) |
435
+ | `convert --to X` | Existing Cursor/Copilot/Windsurf config (if it exists) |
436
+ | `compress --prune` | `MEMORY.md` (before old entries are deleted) |
437
+ | `hooks remove` | `.claude/settings.local.json` (before hook is removed) |
438
+ | `drift --fix` | `CLAUDE.md.bak` (existing behaviour, now also in manifest) |
439
+
440
+ ---
441
+
363
442
  ## How it all fits together
364
443
 
365
444
  ```
@@ -379,7 +458,7 @@ End of session: End of session:
379
458
 
380
459
  ## Token Savings — Share Your Results
381
460
 
382
- Join the **[Token Savings Hall of Fame](https://github.com/Horilla/claudectx/discussions)** — share your before/after numbers.
461
+ Join the **[Token Savings Hall of Fame](HALL_OF_FAME.md)** — share your before/after numbers and see real results from other developers.
383
462
 
384
463
  ---
385
464
 
@@ -392,7 +471,7 @@ git clone https://github.com/Horilla/claudectx.git
392
471
  cd claudectx
393
472
  npm install
394
473
  npm run build
395
- npm test # 278 tests, should all pass
474
+ npm test # 293 tests, should all pass
396
475
  npm run lint # 0 errors expected
397
476
  ```
398
477