claude-token-saver 2.5.0 → 2.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
@@ -12,7 +12,7 @@
12
12
  **Why I built this.** I'm on the Max plan. On Opus 4.6 I never hit the *current-session* cap. After Opus 4.7 rolled out, I started hitting it on the same workflow — repeatedly. The official token statistics didn't match what I was actually feeling, and Claude Code's UI doesn't show prompt-cache health. This tool is what let me see *why*: low cache hit rate, 5m TTL writes that should have been 1h, 1M context auto-promoted in the background.
13
13
 
14
14
  v2.1 (2026-04) adds the workflow that follows the diagnosis:
15
- - **`claude-token-saver install`** — one command writes a Claude Code Skill (auto-activates when you mention "cache hit rate" / "1M context" / etc.) and a `/token-monitor` slash command.
15
+ - **`claude-token-saver install`** — one command writes a Claude Code Skill that auto-activates when you mention "cache hit rate" / "1M context" / "5H cap" no slash command needed.
16
16
  - **`claude-token-saver history`** — every warning chip transition is auto-logged to a daily Markdown file, so you can answer "when did this start" without grepping logs.
17
17
  - **Cross-platform paths** — Windows (`%APPDATA%`), macOS (`~/Library/Application Support`), Linux (`~/.config` / XDG) all handled.
18
18
 
@@ -208,11 +208,12 @@ One command wires up everything else this README mentions:
208
208
  claude-token-saver install
209
209
  ```
210
210
 
211
- This writes two files under your Claude user dir:
212
- - `~/.claude/skills/claude-token-saver/SKILL.md` — auto-activates whenever you mention chip wording ("⚠ 1M ON", "cache miss", etc.) or ask about token usage. Claude Code will then know to read history, drill into the table report, and explain the warning.
213
- - `~/.claude/commands/token-monitor.md` — adds a `/token-monitor` slash command that runs `claude-token-saver history` + a fresh report and summarizes both for you.
211
+ This writes one file under your Claude user dir:
212
+ - `~/.claude/skills/claude-token-saver/SKILL.md` — auto-activates whenever you mention chip wording ("⚠ 1M ON", "cache miss", "5H cap", etc.) or ask for a token report. Claude Code will then read `claude-token-saver last`, drill into history if needed, and explain the warning.
214
213
 
215
- Re-run with `--force` to overwrite. Install only one piece with `install --skill` or `install --command`.
214
+ If you previously installed v2.5.x or earlier, `install` also removes the now-redundant legacy `~/.claude/commands/token-monitor.md` slash command — its workflow is fully absorbed into the skill (same behavior, triggered by intent rather than typing `/token-monitor`).
215
+
216
+ Re-run with `--force` to overwrite the skill file.
216
217
 
217
218
  ## Warning history (`history`) — new in v2.1
218
219
 
@@ -286,7 +287,7 @@ That writes `./HANDOFF-YYYY-MM-DD-HHMM.md` in the current directory with:
286
287
  Read the most recent HANDOFF-*.md in this directory and continue the work.
287
288
  ```
288
289
 
289
- The handoff write is also recorded in history (`📝 handoff written: …`), so `/token-monitor` and `claude-token-saver history` show both the cap-warn and the backup event next to each other.
290
+ The handoff write is also recorded in history (`📝 handoff written: …`), so `claude-token-saver history` and the auto-skill show both the cap-warn and the backup event next to each other.
290
291
 
291
292
  ## Hook Setup
292
293
 
package/bin/cli.js CHANGED
@@ -201,9 +201,9 @@ function findLatestWarning(historyEntries, chipToCodes) {
201
201
 
202
202
  async function main() {
203
203
  // Subcommand: last — print the most recent warning + how to handle it.
204
- // Designed for the /token-monitor slash command and the auto-skill so the
205
- // user immediately sees "what just fired and how to fix it" without having
206
- // to read the whole history file.
204
+ // Designed for the auto-trigger skill so the user immediately sees
205
+ // "what just fired and how to fix it" without having to read the whole
206
+ // history file.
207
207
  // claude-token-saver last # search last 1 day
208
208
  // claude-token-saver last --days 7 # widen the lookback
209
209
  if (args[0] === 'last') {
@@ -329,38 +329,31 @@ async function main() {
329
329
  return;
330
330
  }
331
331
 
332
- // Subcommand: install — write the Claude Code Skill and slash command so
333
- // /token-monitor and the auto-trigger skill become available without any
334
- // manual file editing. Cross-platform (uses node:path + node:fs).
335
- // claude-token-saver install # install both
336
- // claude-token-saver install --skill # only the skill
337
- // claude-token-saver install --command # only the slash command
338
- // claude-token-saver install --force # overwrite existing files
332
+ // Subcommand: install — write the Claude Code auto-trigger skill so the
333
+ // user can just mention chip wording and Claude responds. v2.6.0 dropped
334
+ // the redundant /token-monitor slash command in favor of the skill alone;
335
+ // a legacy command file is removed automatically. Cross-platform.
336
+ // claude-token-saver install # install/update the skill
337
+ // claude-token-saver install --force # overwrite existing skill file
339
338
  if (args[0] === 'install') {
340
- const { installSkill, installCommand, installAll } = await import('../src/installer.js');
339
+ const { installAll } = await import('../src/installer.js');
341
340
  const force = hasFlag('--force');
342
- const onlySkill = hasFlag('--skill');
343
- const onlyCommand = hasFlag('--command');
344
341
  const print = (kind, r) => {
345
342
  const verb = r.action === 'exists' ? 'already exists' : r.action;
346
343
  console.log(` ${kind}: ${r.path} (${verb})`);
347
344
  };
348
- if (onlySkill && !onlyCommand) {
349
- print('skill', installSkill({ force }));
350
- } else if (onlyCommand && !onlySkill) {
351
- print('command', installCommand({ force }));
352
- } else {
353
- const r = installAll({ force });
354
- print('skill', r.skill);
355
- print('command', r.command);
345
+ const r = installAll({ force });
346
+ print('skill', r.skill);
347
+ if (r.legacy.action === 'removed') {
348
+ print('legacy /token-monitor', r.legacy);
349
+ console.log(' (consolidated into the skill — same workflow, triggered by intent)');
356
350
  }
357
351
  console.log('');
358
- console.log('Open Claude Code in any directory and try:');
359
- console.log(' /token-monitor');
360
- console.log('Or just mention "cache hit rate" / "1M context" — the skill auto-activates.');
352
+ console.log('Open Claude Code in any directory and just mention:');
353
+ console.log(' "cache hit rate" / "1M context" / "5H cap" — the skill auto-activates.');
361
354
  if (!force) {
362
355
  console.log('');
363
- console.log('Tip: re-run with --force to overwrite existing files.');
356
+ console.log('Tip: re-run with --force to overwrite the existing skill file.');
364
357
  }
365
358
  return;
366
359
  }
@@ -562,8 +555,8 @@ async function main() {
562
555
  // refresh. Pull rate_limits + model out of it so we can surface cap-warn
563
556
  // (>=90%) chips, always-on usage segments, the model chip, record cap
564
557
  // transitions, and seed the table view's warning box. The table path falls
565
- // back to the most-recent cached snapshot so the /token-monitor slash
566
- // command (which doesn't pipe stdin) still has the data.
558
+ // back to the most-recent cached snapshot so the table view (which
559
+ // doesn't pipe stdin) still has the data.
567
560
  const stdinJson = readStdinJson();
568
561
  let caps = extractCaps(stdinJson);
569
562
  let model = extractModel(stdinJson);
@@ -616,7 +609,7 @@ async function main() {
616
609
  }
617
610
  }
618
611
  // Persist transitions to ~/.config/claude-token-saver/history/YYYY-MM-DD.md
619
- // so /token-monitor and `claude-token-saver history` can replay them.
612
+ // so `claude-token-saver history` and the auto-skill can replay them.
620
613
  try {
621
614
  const { recordChip, recordCapTransition } = await import('../src/history.js');
622
615
  recordChip(spikeChip, { detail: chipDetail });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-token-saver",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "Save tokens on Claude Code — spike diagnosis, 1M-context detection, TTL countdown, statusline. (formerly claude-cache-monitor)",
5
5
  "type": "module",
6
6
  "bin": {
package/src/caps-cache.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Statusline snapshot cache — the rate-limit numbers and model name only flow
3
3
  * through stdin from Claude Code's statusline contract, but we want the table
4
- * view (e.g. invoked by `/token-monitor`) to surface the same data. So
4
+ * view (`claude-token-saver --days N`) to surface the same data. So
5
5
  * whenever the statusline path sees them it writes them here, and the table
6
6
  * path reads them back if its own stdin was empty.
7
7
  *
package/src/installer.js CHANGED
@@ -1,7 +1,11 @@
1
1
  /**
2
- * Installs the Claude Code integration assets:
2
+ * Installs the Claude Code integration asset:
3
3
  * - Skill: ~/.claude/skills/claude-token-saver/SKILL.md
4
- * - Slash: ~/.claude/commands/token-monitor.md
4
+ *
5
+ * v2.6.0 consolidates `/token-monitor` into the skill (was redundant with the
6
+ * auto-trigger). On install we actively remove a legacy
7
+ * ~/.claude/commands/token-monitor.md if present so users don't see two
8
+ * overlapping entry points.
5
9
  *
6
10
  * All paths are resolved with node:path so Windows backslashes and POSIX
7
11
  * forward-slashes are both handled. Directories are created with
@@ -9,7 +13,7 @@
9
13
  * exist on every platform.
10
14
  */
11
15
 
12
- import { writeFileSync, mkdirSync, existsSync } from 'node:fs';
16
+ import { writeFileSync, mkdirSync, existsSync, unlinkSync } from 'node:fs';
13
17
  import { join } from 'node:path';
14
18
  import { claudeUserDir } from './paths.js';
15
19
 
@@ -36,6 +40,9 @@ countdown, savings, and (when relevant) a leading warning chip.
36
40
  \`claude-token-saver handoff\`).
37
41
  - The user wants to see the token-usage history file or asks for a summary
38
42
  of recent warnings.
43
+ - The user asks for a quick token report or "current state" check (the
44
+ skill replaces the legacy \`/token-monitor\` slash command — same workflow,
45
+ triggered by intent rather than a typed slash).
39
46
 
40
47
  ## What to do
41
48
 
@@ -97,41 +104,6 @@ History files live under the OS-appropriate user-data dir:
97
104
  Each day's file is plain Markdown — safe to open in any editor.
98
105
  `;
99
106
 
100
- const COMMAND_BODY = `---
101
- description: Show recent claude-token-saver warning history and a fresh report.
102
- ---
103
-
104
- You are responding to the \`/token-monitor\` slash command. The user wants a
105
- quick read of their Claude Code token usage and any active warnings — most
106
- importantly: **what just happened, and how do I handle it?**
107
-
108
- Steps:
109
-
110
- 1. **Lead with the most recent warning.** Run \`claude-token-saver last\`
111
- first and surface its output verbatim (or lightly summarized) at the top
112
- of your reply. This returns the latest warning event (chip + detail +
113
- timestamp) followed by the full advice block. If \`last\` says no recent
114
- warnings, mention that and skip ahead — you can stop here unless the user
115
- asked for more.
116
- 2. Run \`claude-token-saver history --days 7\` and capture the output. Use it
117
- only to add context — e.g. "this is the 3rd cache miss today" — not to
118
- re-print the whole file. Each entry is bilingual and includes a \`💡\`
119
- action tip inline.
120
- 3. Run \`claude-token-saver --days 1\` and capture the output for any extra
121
- color you want to add: TTL breakdown, cost impact, daily trend, or active
122
- spikes. Skip if step 1 already covered what the user needs.
123
- 4. Summarize for the user:
124
- - **What just fired** — the chip + the time + a sentence on what caused it
125
- (from \`last\`).
126
- - **What to do** — the action tip from \`last\`. For cap-warn (\`🚨 5H/7D NN%\`),
127
- surface \`claude-token-saver handoff\` prominently so they can back up
128
- state before the cap blocks them.
129
- - **Today's pattern** (optional) — when warnings cluster in time, mention it.
130
-
131
- Keep the summary to ~10 lines. The user can re-run the underlying commands
132
- themselves for the full output.
133
- `;
134
-
135
107
  function writeIfNeeded(file, body, force) {
136
108
  const existed = existsSync(file);
137
109
  if (existed && !force) return { path: file, action: 'exists' };
@@ -146,16 +118,18 @@ export function installSkill({ force = false } = {}) {
146
118
  return writeIfNeeded(file, SKILL_BODY, force);
147
119
  }
148
120
 
149
- export function installCommand({ force = false } = {}) {
150
- const dir = join(claudeUserDir(), 'commands');
151
- const file = join(dir, 'token-monitor.md');
152
- mkdirSync(dir, { recursive: true });
153
- return writeIfNeeded(file, COMMAND_BODY, force);
121
+ // Removes the legacy /token-monitor slash command from prior versions.
122
+ // v2.6.0 consolidated it into the skill — the file would otherwise linger.
123
+ export function removeLegacyCommand() {
124
+ const file = join(claudeUserDir(), 'commands', 'token-monitor.md');
125
+ if (!existsSync(file)) return { path: file, action: 'absent' };
126
+ unlinkSync(file);
127
+ return { path: file, action: 'removed' };
154
128
  }
155
129
 
156
130
  export function installAll({ force = false } = {}) {
157
131
  return {
158
132
  skill: installSkill({ force }),
159
- command: installCommand({ force }),
133
+ legacy: removeLegacyCommand(),
160
134
  };
161
135
  }