claude-slim 2.14.0 → 2.14.2

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
@@ -7,6 +7,7 @@
7
7
  [![CI](https://github.com/iops-leo/claude-slim/actions/workflows/ci.yml/badge.svg)](https://github.com/iops-leo/claude-slim/actions/workflows/ci.yml)
8
8
  [![node](https://img.shields.io/node/v/claude-slim.svg)](https://nodejs.org)
9
9
  [![license](https://img.shields.io/npm/l/claude-slim.svg)](./LICENSE)
10
+ [![skills.sh](https://skills.sh/b/iops-leo/claude-slim)](https://skills.sh/iops-leo/claude-slim)
10
11
 
11
12
  **Your Claude Code session burns thousands of tokens before you even say "hello."**
12
13
 
@@ -20,6 +20,7 @@ import { scanPluginSurfaces } from './plugin-surfaces.js';
20
20
  import { computePluginBreakdown } from './plugin-breakdown.js';
21
21
  import { computePluginCosts } from './plugin-cost.js';
22
22
  import { scanUserSurfaces } from './user-surfaces.js';
23
+ import { sanitizeScanResult } from './untrusted.js';
23
24
  const DEFAULT_LOOKBACK_DAYS = 60;
24
25
  export async function scan(opts = {}) {
25
26
  const lookbackDays = opts.lookbackDays ?? DEFAULT_LOOKBACK_DAYS;
@@ -149,7 +150,10 @@ export async function scan(opts = {}) {
149
150
  pluginSkillListingTokens.set(c.pluginName, (pluginSkillListingTokens.get(c.pluginName) ?? 0) + c.skillTokens);
150
151
  }
151
152
  const recoverableStartupTokens = sumRecoverableStartupTokens(issues, [...localSkills, ...pluginSkills], currentProjectSlug, pluginSkillListingTokens);
152
- return {
153
+ // Labels below are authored by whoever wrote each skill, plugin, or memory
154
+ // file, and they reach the agent's context through the report. Flatten them
155
+ // at this one exit rather than at each site that reads a name off disk.
156
+ return sanitizeScanResult({
153
157
  localSkills,
154
158
  pluginSkills,
155
159
  plugins,
@@ -171,7 +175,7 @@ export async function scan(opts = {}) {
171
175
  allProjectsMemoryTokens,
172
176
  recoverableStartupTokens,
173
177
  disabledPluginSkillTokens,
174
- };
178
+ });
175
179
  }
176
180
  async function pathExists(p) {
177
181
  try {
@@ -0,0 +1,30 @@
1
+ import type { ScanResult } from '../types.js';
2
+ /**
3
+ * Names read off disk are written by whoever authored the skill, plugin, or
4
+ * memory file — not by the user running the scan. They flow through the report
5
+ * into the agent's context, which makes them an indirect prompt injection
6
+ * surface: a skill directory or frontmatter `name:` can carry instructions
7
+ * aimed at the model rather than a label aimed at a human.
8
+ *
9
+ * Snyk's audit of this skill (W011, medium 0.30) is about exactly this path.
10
+ * The scan never emits file *bodies* — descriptions are measured for token cost
11
+ * and then discarded — so what this module covers is the whole exposed surface,
12
+ * not a sample of it.
13
+ */
14
+ /** Longest label we render. Real names are far shorter; payloads are not. */
15
+ export declare const MAX_NAME_LENGTH = 120;
16
+ /**
17
+ * Collapse an untrusted label to a single bounded, printable line.
18
+ *
19
+ * Deliberately not an escape or an encoding: the value is a display label, and
20
+ * a reversible transform would relocate a payload rather than remove it.
21
+ */
22
+ export declare function sanitizeUntrusted(value: string, max?: number): string;
23
+ /**
24
+ * Return a copy of the scan with every outsider-authored label flattened.
25
+ *
26
+ * Applied once at the scanner's exit rather than at each of the dozen sites
27
+ * that read a name off disk: one chokepoint cannot be forgotten by whoever adds
28
+ * the next detector.
29
+ */
30
+ export declare function sanitizeScanResult(result: ScanResult): ScanResult;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Names read off disk are written by whoever authored the skill, plugin, or
3
+ * memory file — not by the user running the scan. They flow through the report
4
+ * into the agent's context, which makes them an indirect prompt injection
5
+ * surface: a skill directory or frontmatter `name:` can carry instructions
6
+ * aimed at the model rather than a label aimed at a human.
7
+ *
8
+ * Snyk's audit of this skill (W011, medium 0.30) is about exactly this path.
9
+ * The scan never emits file *bodies* — descriptions are measured for token cost
10
+ * and then discarded — so what this module covers is the whole exposed surface,
11
+ * not a sample of it.
12
+ */
13
+ /** Longest label we render. Real names are far shorter; payloads are not. */
14
+ export const MAX_NAME_LENGTH = 120;
15
+ /** C0/C1 controls, including the newlines that would forge new report rows. */
16
+ const CONTROL_CHARS = /[\u0000-\u001F\u007F-\u009F]/g;
17
+ /**
18
+ * Zero-width and bidi-override characters: invisible to the human reading the
19
+ * report, fully visible to the model reading the same string.
20
+ */
21
+ const INVISIBLE = /[\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]/g;
22
+ /**
23
+ * Collapse an untrusted label to a single bounded, printable line.
24
+ *
25
+ * Deliberately not an escape or an encoding: the value is a display label, and
26
+ * a reversible transform would relocate a payload rather than remove it.
27
+ */
28
+ export function sanitizeUntrusted(value, max = MAX_NAME_LENGTH) {
29
+ const flattened = value
30
+ .replace(CONTROL_CHARS, ' ')
31
+ .replace(INVISIBLE, '')
32
+ .replace(/\s+/g, ' ')
33
+ .trim();
34
+ if (flattened.length <= max)
35
+ return flattened;
36
+ return `${flattened.slice(0, max)}…`;
37
+ }
38
+ /**
39
+ * Paths are shown to the user and used to locate files for cleanup, so they are
40
+ * flattened but never truncated — a shortened path would be a wrong path.
41
+ */
42
+ function sanitizePath(value) {
43
+ return value.replace(CONTROL_CHARS, ' ').replace(INVISIBLE, '').trim();
44
+ }
45
+ /**
46
+ * Return a copy of the scan with every outsider-authored label flattened.
47
+ *
48
+ * Applied once at the scanner's exit rather than at each of the dozen sites
49
+ * that read a name off disk: one chokepoint cannot be forgotten by whoever adds
50
+ * the next detector.
51
+ */
52
+ export function sanitizeScanResult(result) {
53
+ const skill = (s) => ({
54
+ ...s,
55
+ name: sanitizeUntrusted(s.name),
56
+ path: sanitizePath(s.path),
57
+ });
58
+ return {
59
+ ...result,
60
+ localSkills: result.localSkills.map(skill),
61
+ pluginSkills: result.pluginSkills.map(skill),
62
+ plugins: result.plugins.map((p) => ({
63
+ ...p,
64
+ name: sanitizeUntrusted(p.name),
65
+ skills: p.skills.map((s) => sanitizeUntrusted(s)),
66
+ })),
67
+ brokenSymlinks: result.brokenSymlinks.map((b) => ({
68
+ ...b,
69
+ name: sanitizeUntrusted(b.name),
70
+ path: sanitizePath(b.path),
71
+ target: sanitizeUntrusted(b.target),
72
+ })),
73
+ memoryFiles: result.memoryFiles.map((m) => ({
74
+ ...m,
75
+ project: sanitizeUntrusted(m.project),
76
+ name: sanitizeUntrusted(m.name),
77
+ path: sanitizePath(m.path),
78
+ })),
79
+ claudeMdSections: result.claudeMdSections.map((s) => ({
80
+ ...s,
81
+ name: sanitizeUntrusted(s.name),
82
+ })),
83
+ mcpServerNames: result.mcpServerNames.map((n) => sanitizeUntrusted(n)),
84
+ issues: result.issues.map((i) => ({
85
+ ...i,
86
+ name: sanitizeUntrusted(i.name),
87
+ path: sanitizePath(i.path),
88
+ ...(i.detail === undefined ? {} : { detail: sanitizeUntrusted(i.detail) }),
89
+ ...(i.marketplace === undefined
90
+ ? {}
91
+ : { marketplace: sanitizeUntrusted(i.marketplace) }),
92
+ })),
93
+ pluginBreakdown: result.pluginBreakdown.map((p) => ({
94
+ ...p,
95
+ name: sanitizeUntrusted(p.name),
96
+ marketplace: sanitizeUntrusted(p.marketplace),
97
+ })),
98
+ userAgents: result.userAgents.map((a) => ({ ...a, name: sanitizeUntrusted(a.name) })),
99
+ userCommands: result.userCommands.map((c) => ({ ...c, name: sanitizeUntrusted(c.name) })),
100
+ };
101
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-slim",
3
- "version": "2.14.0",
3
+ "version": "2.14.2",
4
4
  "description": "Audit and shrink your Claude Code startup context. Measures what every skill, plugin, agent, command, and memory file costs in the system prompt, then reversibly disables the dead weight. Non-destructive scan, tiered proposals, one-command restore — no proxy, no compression.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -27,6 +27,14 @@ block does not survive into the next. It resolves in three tiers — the plugin'
27
27
  `npx`. That last tier is what makes the skill work when it was installed by
28
28
  `npx skills add` rather than `claude plugin install`, where no plugin root exists.
29
29
 
30
+ The `npx` tier pins a **minimum version, not just a major**. `claude-slim@^2` looks
31
+ safer but is worse: npx reuses any cached `_npx` install that satisfies the range and
32
+ never re-checks the registry, so a machine that once fetched an older 2.x keeps running
33
+ it — a security fix would never arrive. `--prefer-online` does not override this. Pinning
34
+ to the exact release changes the cache key every time, which forces a fresh fetch while
35
+ still refusing an unreviewed next major. `npm run check:versions` keeps this pin equal to
36
+ `package.json`, so bump them together.
37
+
30
38
  Do not shorten the name. A two-letter `cs` collides with claude-squad's binary, and a
31
39
  shell function is invisible to `timeout`, `env`, and `xargs` — a wrapped call would
32
40
  silently run that other program instead. Call `claude_slim` directly, never through a
@@ -39,7 +47,7 @@ wrapper.
39
47
  An outdated claude-slim does not merely lack features — it reports **wrong numbers**. Versions before 2.8.0 summed memory across every project on disk and inflated the startup estimate roughly 8×. Presenting those figures as fact is worse than not running at all, so check first:
40
48
 
41
49
  ```bash
42
- claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2' "$@"; fi; }
50
+ claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2.14.2' "$@"; fi; }
43
51
  claude_slim check-update --json
44
52
  ```
45
53
 
@@ -72,7 +80,7 @@ If `"outdated": false`, say nothing and continue to Phase 1.
72
80
  Run the CLI to collect environment data:
73
81
 
74
82
  ```bash
75
- claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2' "$@"; fi; }
83
+ claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2.14.2' "$@"; fi; }
76
84
  claude_slim scan --json
77
85
  ```
78
86
 
@@ -192,20 +200,20 @@ If subcommand is `scan`, stop here. Ask a localized equivalent of "Proceed with
192
200
  Run the interactive clean command:
193
201
 
194
202
  ```bash
195
- claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2' "$@"; fi; }
203
+ claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2.14.2' "$@"; fi; }
196
204
  claude_slim clean
197
205
  ```
198
206
 
199
207
  Or with dry-run:
200
208
  ```bash
201
- claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2' "$@"; fi; }
209
+ claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2.14.2' "$@"; fi; }
202
210
  claude_slim clean --dry-run
203
211
  ```
204
212
 
205
213
  After cleanup, re-run scan to get updated numbers, then show the savings report:
206
214
 
207
215
  ```bash
208
- claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2' "$@"; fi; }
216
+ claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2.14.2' "$@"; fi; }
209
217
  claude_slim report
210
218
  ```
211
219
 
@@ -218,7 +226,7 @@ Present the report box AND the before/after breakdown table to the user.
218
226
  When `/claude-slim restore` is invoked:
219
227
 
220
228
  ```bash
221
- claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2' "$@"; fi; }
229
+ claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2.14.2' "$@"; fi; }
222
230
  claude_slim restore
223
231
  ```
224
232
 
@@ -227,7 +235,7 @@ claude_slim restore
227
235
  When `/claude-slim doctor` is invoked:
228
236
 
229
237
  ```bash
230
- claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2' "$@"; fi; }
238
+ claude_slim(){ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && [ -f "$CLAUDE_PLUGIN_ROOT/dist/cli.js" ]; then node "$CLAUDE_PLUGIN_ROOT/dist/cli.js" "$@"; elif command -v claude-slim >/dev/null 2>&1; then claude-slim "$@"; else npx -y 'claude-slim@^2.14.2' "$@"; fi; }
231
239
  claude_slim doctor
232
240
  ```
233
241