@lilmgenius/win-hooks 1.10.0 → 1.11.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
@@ -4,11 +4,10 @@
4
4
 
5
5
  ### *"Linux? Nah. WinUX!"*
6
6
 
7
- **Don't let Windows kill your vibe coding flow.**
7
+ **Windows auto-patcher for vibe coders.**
8
8
 
9
- Every Claude Code / Codex plugin assumes you're on macOS or Linux.<br>
10
- On Windows, your sessions start with a wall of red hook errors.<br>
11
- **win-hooks fixes that. Automatically. Every session.**
9
+ Your AI coding tools work on Windows. Their plugins mostly don't.<br>
10
+ win-hooks fixes them for you — automatically, every session.
12
11
 
13
12
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
14
13
  [![Platform](https://img.shields.io/badge/platform-Windows%2010%2F11-0078D6?logo=windows)](https://www.microsoft.com/windows)
@@ -19,9 +18,7 @@ On Windows, your sessions start with a wall of red hook errors.<br>
19
18
 
20
19
  ---
21
20
 
22
- ## The Problem
23
-
24
- You install a Claude Code / Codex plugin, start a session, and see errors like:
21
+ ## You know this screen
25
22
 
26
23
  ```
27
24
  SessionStart hook error: /bin/bash: command not found
@@ -29,145 +26,96 @@ PreToolUse hook error: scripts/check.sh: No such file or directory
29
26
  PostToolUse hook error: semgrep: command not found
30
27
  ```
31
28
 
32
- The plugin may be fine on macOS or Linux, but its hooks assume Unix tools, `.sh` scripts, or shell paths that Windows does not run directly.
29
+ You installed a plugin. It works fine for everyone on a Mac. On your machine it greets you with red text every single time you open a session.
33
30
 
34
- ## Quick Start
31
+ Nothing is broken on your end. Almost every plugin is written and tested on macOS or Linux, so its hooks quietly assume Unix tools that Windows does not have. You are not supposed to fix that by hand. **win-hooks does it for you.**
35
32
 
36
- ### Claude Code
33
+ ## Install it once, forget it exists
37
34
 
38
- Paste once:
35
+ **Claude Code**
39
36
 
40
37
  ```bash
41
38
  claude plugin marketplace add LilMGenius/win-hooks && claude plugin install win-hooks
42
39
  ```
43
40
 
44
- That is the setup. No config, no flags, no manual patching.
45
-
46
- ### Codex
47
-
48
- Paste once:
41
+ **Codex**
49
42
 
50
43
  ```bash
51
44
  codex plugin marketplace add LilMGenius/win-hooks && codex plugin add win-hooks@win-hooks
52
45
  ```
53
46
 
54
- Codex uses its native `commandWindows` field, so the original cross-platform `command` stays intact.
55
-
56
- ### CLI (npm)
47
+ That's it. No config, no flags, nothing to remember. From then on win-hooks checks your plugins at the start of every session and repairs whatever broke — including plugins you install later, and plugins that break again after an update.
57
48
 
58
- Want a one-shot fix, or to run it in CI, without installing the plugin? Run it directly:
49
+ Prefer a one-shot fix, or need it in CI? Skip the plugin and run it directly:
59
50
 
60
51
  ```bash
61
- npx @lilmgenius/win-hooks # repair installed Claude Code AND Codex plugin hooks
62
- npx @lilmgenius/win-hooks status # show the last repair result
52
+ npx @lilmgenius/win-hooks # repair every installed plugin, now
53
+ npx @lilmgenius/win-hooks status # show what it found last time
63
54
  ```
64
55
 
65
- Windows only. It uses the same runtimes as the plugin — Git for Windows (Bash) and Node.js. Installed as a plugin, win-hooks also runs automatically every session; the CLI is for when you'd rather trigger it yourself.
66
-
67
- ## What win-hooks Fixes
68
-
69
- win-hooks scans your installed Claude Code / Codex plugins and repairs Windows-incompatible hook commands before they keep breaking your session.
70
-
71
- It handles the common failure modes:
56
+ ## What it actually fixes
72
57
 
73
- - `.sh` scripts called directly from Windows
74
- - missing Unix-only commands such as `semgrep` or `shellcheck`
75
- - bare `node`, `python`, `python3`, `npx`, or `npm` commands that work in Git Bash but fail through Windows hook dispatch
76
- - Windows backslash paths inside hook commands
77
- - UTF-8 BOM, CRLF, invalid JSON, missing wrappers, and broken wrapper files
78
- - `python3` hooks blocked by the Microsoft Store Python alias
79
-
80
- Original plugin files are backed up where hooks are patched, and already-compatible plugins are skipped.
81
-
82
- ## How It Stays Fixed
83
-
84
- win-hooks runs automatically at session start.
85
-
86
- Claude Code pipeline:
58
+ | The error you see | What was wrong |
59
+ |---|---|
60
+ | `check.sh: No such file or directory` | Windows can't run a `.sh` script directly |
61
+ | `semgrep: command not found` | The plugin expects a Unix tool you don't have |
62
+ | `'node' is not recognized` | Works in Git Bash, invisible to the process that launches hooks |
63
+ | `Python was not found; ... Microsoft Store` | Windows' fake `python3` placeholder shadowing your real one |
64
+ | `JSON Parse error: Unrecognized token` | An invisible byte (BOM) at the top of a config file |
65
+ | `Cannot find module 'C:\Users...'` | Backslashes in a path getting eaten before the hook runs |
87
66
 
88
- ```mermaid
89
- flowchart LR
90
- A[scan plugins] --> B[patch hooks.json] --> C[normalize settings.json] --> D["verify & auto-repair"]
91
- ```
67
+ Every repair is made next to the original file, never on top of it. The plugin's own files are backed up, and anything already working is left alone.
92
68
 
93
- Codex pipeline:
69
+ ## Staying fixed
94
70
 
95
71
  ```mermaid
96
72
  flowchart LR
97
- A[scan plugins] --> B["add commandWindows wrappers"] --> C["verify & auto-repair"]
73
+ A[scan installed plugins] --> B[patch broken hooks] --> C[verify & auto-repair]
98
74
  ```
99
75
 
100
- Plugin updates are covered too. If an update replaces a repaired hook with a fresh broken one, win-hooks re-patches it at the next session start.
101
-
102
- It also checks again on your next prompt after a plugin update. Use `/reload-plugins` when you want the repaired hook config loaded without starting a new session.
103
-
104
- ## Check Status
76
+ That runs at session start, and again on your next prompt if a plugin updated itself in the meantime — because an update reinstalls the plugin's original, still-broken hooks. When win-hooks re-patches mid-session it tells you to run `/reload-plugins`, which picks up the fix without restarting.
105
77
 
106
- The normal path is silent, so win-hooks writes a small heartbeat log:
78
+ Because the healthy path is silent, it also leaves a short log behind:
107
79
 
108
80
  ```bash
109
- tail -n 5 ~/.claude/win-hooks/last-run.log
110
- tail -n 5 ~/.codex/win-hooks/last-run.log
81
+ npx @lilmgenius/win-hooks status
111
82
  ```
112
83
 
113
- - `phase=done` means the self-heal completed.
114
- - a lone `phase=start` means the run was cut off mid-way and should retry next session.
115
- - no file means it has not dispatched yet.
116
-
117
- You can also run:
118
-
119
- ```text
120
- /win-hooks:status
121
- ```
84
+ Or, inside a session:
122
85
 
123
- ## Commands
124
-
125
- | Command | Description |
86
+ | Command | What it does |
126
87
  |---|---|
127
- | `/win-hooks:status` | Show the current compatibility status of installed plugin hooks. |
128
- | `/win-hooks:fix` | Manually run the repair pipeline. Normally you should not need this. |
88
+ | `/win-hooks:status` | Show what's healthy, what's broken, and when it last ran |
89
+ | `/win-hooks:fix` | Run the repair now, instead of waiting for the next session |
129
90
 
130
91
  ## Requirements
131
92
 
132
- - Windows 10/11
133
- - Claude Code / Codex
134
- - Git for Windows
135
- - Node.js available on PATH
93
+ Windows 10/11, and [Git for Windows](https://git-scm.com/download/win) — which you almost certainly already have. Node.js comes with Claude Code and Codex.
94
+
95
+ ## Privacy
136
96
 
137
- Claude Code already provides the Node.js runtime used by the Claude-side patch/verify flow. The Codex flow also uses `node` in `scripts/codex-find-incompatible` and `scripts/codex-verify`. Git for Windows provides the Bash runtime used to execute repaired hooks.
97
+ win-hooks runs entirely on your machine and sends nothing anywhere. No telemetry, no network calls, no account. The only thing it writes outside a plugin's own folder is a short local log of its own runs, so you can check it actually ran.
138
98
 
139
- ## Technical Notes
99
+ ## For the curious
140
100
 
141
- For Claude Code, win-hooks creates a dedicated `_hooks/` directory inside each patched plugin. The original hook target stays untouched, and `hooks.json` points at a Windows-safe wrapper.
101
+ win-hooks never edits a plugin's own scripts. It writes a small `_hooks/` directory next to them, containing one wrapper per broken hook plus a single `run-hook.cmd` — a file that is valid batch *and* valid shell at once, so Windows and Git Bash can each run the same entry point. The plugin's `hooks.json` is then pointed at the wrapper, with the original saved as `hooks.json.bak`.
142
102
 
143
103
  ```
144
104
  plugin/
145
105
  ├── hooks/
146
- │ ├── hooks.json
147
- │ └── hooks.json.bak
148
- ├── _hooks/
149
- │ ├── run-hook.cmd
150
- │ └── <wrapper>
151
- └── scripts/
152
- └── setup.sh
106
+ │ ├── hooks.json → now points at the wrapper
107
+ │ └── hooks.json.bak → your original, untouched
108
+ └── _hooks/
109
+ ├── run-hook.cmd → batch + shell polyglot entry point
110
+ └── check → resolves the real interpreter, then execs
153
111
  ```
154
112
 
155
- The wrapper entry point is a polyglot `.cmd` file: Windows runs the batch portion, while Bash can run the shell portion. That keeps one repaired hook path usable across both Windows dispatch and Bash execution.
113
+ Codex works the same way, with one difference: it has a native `commandWindows` field, so win-hooks *adds* the Windows command instead of replacing the portable one. Your plugins keep working unchanged on macOS and Linux.
156
114
 
157
- For Codex, win-hooks creates `_codex_hooks/` and adds `commandWindows` to incompatible hook entries:
115
+ Wrapper filenames are deliberately extensionless (`check`, not `check.sh`) — Claude Code auto-prepends `bash` to anything containing `.sh` on Windows, which would undo the fix.
158
116
 
159
- ```
160
- plugin/
161
- ├── .codex-plugin/
162
- │ └── plugin.json
163
- ├── hooks/
164
- │ ├── hooks.json
165
- │ └── hooks.json.codex-win-hooks.bak
166
- └── _codex_hooks/
167
- ├── run-hook.cmd
168
- └── <wrapper>
169
- ```
117
+ Contributors: [`AGENTS.md`](AGENTS.md) documents every failure mode win-hooks handles, with the root cause behind each one.
170
118
 
171
- Codex keeps using the original `command` on macOS/Linux. On Windows it uses the generated `commandWindows` wrapper.
119
+ ## License
172
120
 
173
- Contributors can read [`CLAUDE.md`](CLAUDE.md) for the internal scanner, patcher, verifier, and case notes.
121
+ [MIT](LICENSE).
package/bin/win-hooks.mjs CHANGED
@@ -1,82 +1,79 @@
1
1
  #!/usr/bin/env node
2
- // win-hooks CLI — a thin shim over the same bash pipeline the plugin runs.
2
+ // win-hooks CLI - the single entry point. The plugin's own SessionStart and
3
+ // UserPromptSubmit hooks land here too, via hooks/run-hook.cmd -> hooks/win-hooks.
3
4
  //
4
- // `npx win-hooks` scan + repair installed Claude Code AND Codex plugin hooks
5
- // `npx win-hooks claude` Claude Code plugins only (hooks/patch-all)
6
- // `npx win-hooks codex` Codex plugins only (hooks/codex-patch-all)
7
- // `npx win-hooks status` tail the heartbeat logs
5
+ // win-hooks repair Claude Code and Codex plugin hooks
6
+ // win-hooks heal [host] repair one host (claude | codex)
7
+ // win-hooks status [host] report without changing anything
8
8
  //
9
- // win-hooks patches files on disk; if you install it as a plugin it also runs
10
- // automatically at session start. This CLI is for a one-shot fix, CI, or when
11
- // you'd rather not run the SessionStart hook.
9
+ // --changed-only skip when no plugin's hooks changed since the last run
10
+ // (the per-prompt guard; near-free on the hot path)
11
+ //
12
+ // Progress goes to stderr, never stdout: these hooks run under Claude Code,
13
+ // whose UserPromptSubmit stdout is injected into the model's context.
14
+
15
+ import { isWindows } from '../src/env.mjs';
16
+ import { HOSTS } from '../src/hosts.mjs';
17
+ import { heal, inspect } from '../src/heal.mjs';
18
+
19
+ const USAGE = 'usage: win-hooks [heal|status] [claude|codex] [--changed-only]';
12
20
 
13
- import { existsSync, readFileSync } from 'node:fs';
14
- import { execFileSync, spawnSync } from 'node:child_process';
15
- import { fileURLToPath } from 'node:url';
16
- import { dirname, join } from 'node:path';
17
- import { homedir } from 'node:os';
21
+ const args = process.argv.slice(2);
22
+ const flags = new Set(args.filter((a) => a.startsWith('--')));
23
+ const words = args.filter((a) => !a.startsWith('--'));
24
+ const command = ['heal', 'status'].includes(words[0]) ? words.shift() : 'heal';
25
+ const hostIds = words.length ? words : Object.keys(HOSTS);
18
26
 
19
- const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
27
+ if (hostIds.some((id) => !HOSTS[id])) {
28
+ console.error(USAGE);
29
+ process.exit(2);
30
+ }
20
31
 
21
- if (process.platform !== 'win32') {
22
- // Hooks run natively on macOS/Linux — nothing to repair. Not an error.
23
- console.error('win-hooks only applies on Windows; your plugin hooks run natively here. Nothing to do.');
32
+ if (!isWindows()) {
33
+ // Hooks run natively on macOS and Linux. Nothing to repair is not an error.
34
+ console.error('win-hooks: not Windows - your plugin hooks already run natively here.');
24
35
  process.exit(0);
25
36
  }
26
37
 
27
- // Resolve a real bash.exe, mirroring hooks/run-hook.cmd's search order.
28
- function resolveBash() {
29
- const candidates = [];
30
- if (process.env.WH_BASH_EXE) candidates.push(process.env.WH_BASH_EXE);
31
- candidates.push(
32
- 'C:\\Program Files\\Git\\bin\\bash.exe',
33
- 'C:\\Program Files (x86)\\Git\\bin\\bash.exe',
34
- );
35
- for (const c of candidates) if (existsSync(c)) return c;
36
- try {
37
- const out = execFileSync('where', ['bash'], { encoding: 'utf8' });
38
- const first = out.split(/\r?\n/).map((l) => l.trim()).find(Boolean);
39
- if (first && existsSync(first)) return first;
40
- } catch { /* fall through */ }
41
- return null;
38
+ if (command === 'status') {
39
+ console.log(hostIds.map(report).join('\n\n'));
40
+ process.exit(0);
42
41
  }
43
42
 
44
- function runBash(bash, scriptRel) {
45
- const res = spawnSync(bash, [join(ROOT, scriptRel)], { stdio: 'inherit', env: process.env });
46
- if (res.error) {
47
- console.error(`win-hooks: failed to run ${scriptRel}: ${res.error.message}`);
48
- return 1;
43
+ for (const id of hostIds) {
44
+ try {
45
+ const result = heal(id, { changedOnly: flags.has('--changed-only') });
46
+ if (result) for (const line of summarize(result)) console.error(line);
47
+ } catch (e) {
48
+ // One broken host must not take the session down with it.
49
+ console.error('win-hooks: ' + HOSTS[id].label + ' repair failed - ' + e.message);
49
50
  }
50
- return res.status ?? 0;
51
51
  }
52
52
 
53
- function status() {
54
- const home = process.env.USERPROFILE || homedir();
55
- let shown = false;
56
- for (const log of [join(home, '.claude', 'win-hooks', 'last-run.log'), join(home, '.codex', 'win-hooks', 'last-run.log')]) {
57
- if (!existsSync(log)) continue;
58
- shown = true;
59
- console.log(`\n# ${log}`);
60
- console.log(readFileSync(log, 'utf8').trim().split(/\r?\n/).slice(-5).join('\n'));
53
+ function summarize({ host, patched, failed, settings, issues, fixes }) {
54
+ const lines = [];
55
+ for (const p of patched) lines.push('win-hooks: patched ' + p.plugin.id + ' (' + p.wrappers.join(', ') + ')');
56
+ for (const f of failed) lines.push('win-hooks: could not patch ' + f.plugin.id + ' - ' + f.error);
57
+ if (settings.length) lines.push('win-hooks: repaired ' + settings.length + ' hook command(s) in ' + host.label + ' settings');
58
+ for (const f of fixes) lines.push('win-hooks: ' + f);
59
+ if (patched.length || fixes.length) {
60
+ lines.push('win-hooks: repairs are on disk - run /reload-plugins to apply them to this session.');
61
61
  }
62
- if (!shown) console.log('win-hooks: no heartbeat yet — run `npx win-hooks` or start a session.');
63
- return 0;
62
+ const unresolved = issues.length - fixes.length;
63
+ if (unresolved > 0) lines.push('win-hooks: ' + unresolved + ' issue(s) need attention - run /win-hooks:status');
64
+ return lines;
64
65
  }
65
66
 
66
- const cmd = (process.argv[2] || 'fix').toLowerCase();
67
- if (cmd === 'status') process.exit(status());
67
+ function report(id) {
68
+ const { host, plugins, incompatible, issues, settings, log } = inspect(id);
69
+ const lines = ['# ' + host.label + ' - ' + plugins.length + ' hook file(s) scanned'];
68
70
 
69
- const bash = resolveBash();
70
- if (!bash) {
71
- console.error('win-hooks: could not find bash.exe. Install Git for Windows, or set WH_BASH_EXE to your bash path.');
72
- process.exit(1);
73
- }
71
+ for (const i of incompatible) lines.push(' incompatible ' + i.id + ' [' + i.event + '] ' + i.command);
72
+ for (const i of issues) lines.push(' ' + i.type.padEnd(14) + i.plugin + ' ' + i.detail);
73
+ for (const s of settings) lines.push(' ' + s.type.padEnd(14) + s.path + ' ' + s.to);
74
+ if (lines.length === 1) lines.push(' healthy - every hook is Windows-compatible');
74
75
 
75
- let rc = 0;
76
- if (cmd === 'fix' || cmd === 'claude') rc = runBash(bash, 'hooks/patch-all') || rc;
77
- if (cmd === 'fix' || cmd === 'codex') rc = runBash(bash, 'hooks/codex-patch-all') || rc;
78
- if (!['fix', 'claude', 'codex'].includes(cmd)) {
79
- console.error(`win-hooks: unknown command "${cmd}". Use: (none) | claude | codex | status`);
80
- process.exit(2);
76
+ lines.push('', ' last runs:');
77
+ lines.push(...(log.length ? log.map((l) => ' ' + l) : [' (never run)']));
78
+ return lines.join('\n');
81
79
  }
82
- process.exit(rc);
@@ -1,15 +1,15 @@
1
1
  {
2
- "description": "win-hooks: Auto-patches Codex plugin hooks for Windows compatibility",
2
+ "description": "win-hooks: repairs Codex plugin hooks for Windows",
3
3
  "hooks": {
4
4
  "SessionStart": [
5
5
  {
6
6
  "hooks": [
7
7
  {
8
8
  "type": "command",
9
- "command": "bash \"${PLUGIN_ROOT}/hooks/codex-patch-all\"",
10
- "commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" codex-patch-all",
9
+ "command": "bash \"${PLUGIN_ROOT}/hooks/win-hooks\" heal codex",
10
+ "commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" win-hooks heal codex",
11
11
  "timeout": 60,
12
- "statusMessage": "win-hooks: Checking Codex plugin hooks"
12
+ "statusMessage": "win-hooks: checking Codex plugin hooks"
13
13
  }
14
14
  ]
15
15
  }
@@ -19,10 +19,10 @@
19
19
  "hooks": [
20
20
  {
21
21
  "type": "command",
22
- "command": "bash \"${PLUGIN_ROOT}/hooks/codex-patch-all\" --changed-only",
23
- "commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" codex-patch-all --changed-only",
22
+ "command": "bash \"${PLUGIN_ROOT}/hooks/win-hooks\" heal codex --changed-only",
23
+ "commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" win-hooks heal codex --changed-only",
24
24
  "timeout": 20,
25
- "statusMessage": "win-hooks: Checking changed Codex plugin hooks"
25
+ "statusMessage": "win-hooks: checking changed Codex plugin hooks"
26
26
  }
27
27
  ]
28
28
  }
package/hooks/hooks.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
- "description": "win-hooks: Auto-patches Claude Code plugin hooks for Windows compatibility",
2
+ "description": "win-hooks: repairs Claude Code plugin hooks for Windows",
3
3
  "hooks": {
4
4
  "SessionStart": [
5
5
  {
6
6
  "hooks": [
7
7
  {
8
8
  "type": "command",
9
- "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" patch-all",
10
- "timeout": 60000
9
+ "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" win-hooks heal",
10
+ "timeout": 60
11
11
  }
12
12
  ]
13
13
  }
@@ -17,7 +17,7 @@
17
17
  "hooks": [
18
18
  {
19
19
  "type": "command",
20
- "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" reheal"
20
+ "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" win-hooks heal --changed-only"
21
21
  }
22
22
  ]
23
23
  }
@@ -1,11 +1,13 @@
1
1
  : << 'CMDBLOCK'
2
2
  @echo off
3
- REM Cross-platform polyglot wrapper for hook scripts.
4
- REM On Windows: cmd.exe runs the batch portion, which finds bash and delegates.
5
- REM On Unix: the shell interprets this as a script (: is a no-op in bash).
3
+ REM The entry point every patched hook is dispatched through - a single file
4
+ REM that is valid batch AND valid bash at once. cmd.exe runs the batch block
5
+ REM below; bash treats it as a quoted here-doc and falls through to the tail.
6
6
  REM
7
- REM Extensionless script names avoid Claude Code's Windows auto-detection
8
- REM that prepends "bash" to any command containing .sh.
7
+ REM Why a polyglot: Claude Code and Codex each dispatch hooks differently, and
8
+ REM the wrapper has to be reachable from both without shipping two files.
9
+ REM Wrapper names are extensionless because Claude Code prepends "bash" to any
10
+ REM command containing .sh on Windows, which would undo the patch (CASE-07).
9
11
  REM
10
12
  REM Usage: run-hook.cmd <script-name> [args...]
11
13
 
@@ -15,38 +17,49 @@ if "%~1"=="" (
15
17
  )
16
18
 
17
19
  set "HOOK_DIR=%~dp0"
20
+ set "WH_BASH="
18
21
 
19
- REM Explicit override (CASE-27, studied against oh-my-openagent's
20
- REM NODE_REPL_NODE_PATH pattern): set once if bash lives somewhere
21
- REM run-hook.cmd doesn't already look, e.g. a portable/scoop/winget Git
22
- REM install. Skipped entirely unless set, so default behavior is unchanged.
23
- if defined WH_BASH_EXE if exist "%WH_BASH_EXE%" (
24
- "%WH_BASH_EXE%" "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
25
- exit /b %ERRORLEVEL%
26
- )
22
+ REM Explicit override first: set WH_BASH_EXE when bash lives somewhere this
23
+ REM does not already look, e.g. a portable, scoop, or winget Git install.
24
+ if defined WH_BASH_EXE if exist "%WH_BASH_EXE%" set "WH_BASH=%WH_BASH_EXE%"
27
25
 
28
- REM Try Git for Windows bash in standard locations
29
- if exist "C:\Program Files\Git\bin\bash.exe" (
30
- "C:\Program Files\Git\bin\bash.exe" "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
31
- exit /b %ERRORLEVEL%
32
- )
33
- if exist "C:\Program Files (x86)\Git\bin\bash.exe" (
34
- "C:\Program Files (x86)\Git\bin\bash.exe" "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
35
- exit /b %ERRORLEVEL%
36
- )
26
+ REM Then Git for Windows, which is where it almost always is.
27
+ if not defined WH_BASH if exist "C:\Program Files\Git\bin\bash.exe" set "WH_BASH=C:\Program Files\Git\bin\bash.exe"
28
+ if not defined WH_BASH if exist "C:\Program Files (x86)\Git\bin\bash.exe" set "WH_BASH=C:\Program Files (x86)\Git\bin\bash.exe"
37
29
 
38
- REM Try bash on PATH (MSYS2, Cygwin, WSL interop, etc.)
39
- where bash >nul 2>nul
40
- if %ERRORLEVEL% equ 0 (
41
- bash "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
42
- exit /b %ERRORLEVEL%
43
- )
30
+ if defined WH_BASH goto :run
31
+
32
+ REM Finally PATH (MSYS2, Cygwin, a nonstandard install). Resolved by the FOR
33
+ REM path-search modifier below rather than by `where`, which costs a subprocess.
34
+ REM That modifier must not be named in a REM: cmd.exe expands it there too, and
35
+ REM a comment mentioning it is a syntax error.
36
+ for %%I in (bash.exe) do set "WH_BASH=%%~$PATH:I"
37
+ if not defined WH_BASH goto :nobash
38
+
39
+ REM PATH bash is often C:\Windows\System32\bash.exe, the WSL launcher, which
40
+ REM cannot open Windows paths and still exits 0 - it would swallow every hook
41
+ REM forever. So the candidate has to prove it can see the script it is about to
42
+ REM run (CASE-29). Only PATH is probed; the paths above are known-good. The
43
+ REM path goes through the environment because bash would receive it as $0 and
44
+ REM WSL's launcher does not forward $0 the way a real bash does.
45
+ set "WH_PROBE=%HOOK_DIR%%~1"
46
+ "%WH_BASH%" -c "test -f \"$WH_PROBE\"" >nul 2>&1
47
+ if errorlevel 1 goto :nobash
48
+
49
+ :run
50
+ REM %* would ignore the shift, so arguments are forwarded positionally. Eight
51
+ REM is every hook win-hooks generates; a ninth would be silently dropped.
52
+ "%WH_BASH%" "%HOOK_DIR%%~1" %2 %3 %4 %5 %6 %7 %8 %9
53
+ exit /b %ERRORLEVEL%
44
54
 
45
- REM No bash found - exit silently rather than error
55
+ :nobash
56
+ REM Fail-safe: no repair, never a broken session - but say so, because a hook
57
+ REM that does nothing quietly is the exact failure win-hooks exists to catch.
58
+ echo run-hook.cmd: no bash that can run "%~1"; skipping >&2
46
59
  exit /b 0
47
60
  CMDBLOCK
48
61
 
49
- # Unix: run the named script directly
62
+ # bash: run the named script directly.
50
63
  SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
51
64
  SCRIPT_NAME="$1"
52
65
  shift
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ # The bridge from a hook dispatch to the engine.
3
+ #
4
+ # run-hook.cmd already knows how to find bash on Windows, so win-hooks reaches
5
+ # its own engine exactly the way a patched plugin reaches its wrapper - if this
6
+ # path works here, it works there.
7
+ #
8
+ # Fail-safe: a missing runtime means no repair, never a broken session.
9
+ command -v node >/dev/null 2>&1 || exit 0
10
+ exec node "$(cd "$(dirname "$0")/.." && pwd)/bin/win-hooks.mjs" "$@"
package/package.json CHANGED
@@ -1,17 +1,20 @@
1
1
  {
2
2
  "name": "@lilmgenius/win-hooks",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
7
  "description": "Auto-patches Claude Code and Codex plugin hooks for Windows compatibility. Fixes .sh scripts, missing binaries, Unix-only commands, and encoding issues that break hooks on Windows.",
8
+ "scripts": {
9
+ "test": "node test/run.mjs"
10
+ },
8
11
  "bin": {
9
12
  "win-hooks": "bin/win-hooks.mjs"
10
13
  },
11
14
  "files": [
12
15
  "bin/",
13
16
  "hooks/",
14
- "scripts/",
17
+ "src/",
15
18
  "LICENSE",
16
19
  "README.md"
17
20
  ],