claude-code-token-saver 0.1.3 → 0.1.4

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 (2) hide show
  1. package/bin/cli.js +32 -19
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -22,32 +22,42 @@ if (!fs.existsSync(script)) {
22
22
  process.exit(1);
23
23
  }
24
24
 
25
- // Candidate bash locations. First hit that runs wins.
25
+ // WSL's bash is often first on the Windows PATH, but it cannot open C:/... paths
26
+ // (it needs /mnt/c/...). So on Windows we prefer Git Bash (MSYS), which does
27
+ // understand C:/... paths, and only fall back to plain `bash` / WSL afterwards.
28
+ const WSL_BASH = "C:\\Windows\\System32\\bash.exe";
29
+
26
30
  function candidateBashes() {
27
- const list = ["bash"];
28
- if (process.platform === "win32") {
29
- const pf = process.env["ProgramFiles"] || "C:\\Program Files";
30
- const pf86 = process.env["ProgramFiles(x86)"] || "C:\\Program Files (x86)";
31
- const local = process.env["LOCALAPPDATA"] || "";
32
- list.push(
33
- path.join(pf, "Git", "bin", "bash.exe"),
34
- path.join(pf, "Git", "usr", "bin", "bash.exe"),
35
- path.join(pf86, "Git", "bin", "bash.exe"),
36
- local && path.join(local, "Programs", "Git", "bin", "bash.exe"),
37
- "C:\\Windows\\System32\\bash.exe" // WSL
38
- );
39
- }
40
- return list.filter(Boolean);
31
+ if (process.platform !== "win32") return ["bash"];
32
+ const pf = process.env["ProgramFiles"] || "C:\\Program Files";
33
+ const pf86 = process.env["ProgramFiles(x86)"] || "C:\\Program Files (x86)";
34
+ const local = process.env["LOCALAPPDATA"] || "";
35
+ return [
36
+ path.join(pf, "Git", "bin", "bash.exe"),
37
+ path.join(pf, "Git", "usr", "bin", "bash.exe"),
38
+ path.join(pf86, "Git", "bin", "bash.exe"),
39
+ local && path.join(local, "Programs", "Git", "bin", "bash.exe"),
40
+ "bash", // PATH (may be WSL; tried only if no Git Bash is present)
41
+ WSL_BASH, // WSL, last resort
42
+ ].filter(Boolean);
41
43
  }
42
44
 
43
45
  const args = process.argv.slice(2);
44
46
 
45
- // Pass a forward-slash path to bash. On Windows the script path uses
46
- // backslashes (C:\Users\...), which bash would treat as escape sequences and
47
- // mangle (C:UsersAdmin...). Git Bash / MSYS accept C:/Users/... just fine.
48
- const scriptArg = script.replace(/\\/g, "/");
47
+ // Pass a forward-slash path to bash. On Windows the script path uses backslashes
48
+ // (C:\Users\...), which bash would treat as escape sequences and mangle
49
+ // (C:UsersAdmin...). Git Bash / MSYS accept C:/Users/... just fine.
50
+ const scriptFwd = script.replace(/\\/g, "/");
51
+
52
+ // WSL needs a /mnt/<drive>/... path instead of C:/...
53
+ function toWslPath(p) {
54
+ return p.replace(/^([A-Za-z]):\//, function (_m, d) {
55
+ return "/mnt/" + d.toLowerCase() + "/";
56
+ });
57
+ }
49
58
 
50
59
  for (const bash of candidateBashes()) {
60
+ const scriptArg = bash === WSL_BASH ? toWslPath(scriptFwd) : scriptFwd;
51
61
  const res = spawnSync(bash, [scriptArg, ...args], {
52
62
  stdio: "inherit",
53
63
  cwd: process.cwd(),
@@ -55,6 +65,9 @@ for (const bash of candidateBashes()) {
55
65
  if (res.error && res.error.code === "ENOENT") {
56
66
  continue; // this bash isn't here, try the next candidate
57
67
  }
68
+ if (res.status === 127) {
69
+ continue; // bash ran but couldn't open the script (e.g. WSL + C:/ path) → next
70
+ }
58
71
  process.exit(res.status == null ? 1 : res.status);
59
72
  }
60
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-token-saver",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "One-shot installer that adds token-saving Claude Code rails (CLAUDE.md, hooks, subagents, slash commands, dev-docs) to any git repo.",
5
5
  "bin": {
6
6
  "claude-code-token-saver": "bin/cli.js",