@lilmgenius/win-hooks 1.10.0 → 1.12.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,170 +4,76 @@
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
+ win-hooks repairs the plugin hooks that break on your Windows machine.<br>
10
+ Automatically, at every session start, and again for ones added later.
12
11
 
13
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
14
- [![Platform](https://img.shields.io/badge/platform-Windows%2010%2F11-0078D6?logo=windows)](https://www.microsoft.com/windows)
15
- [![Claude Code](https://img.shields.io/badge/Claude%20Code-Plugin-6B4FBB)](https://docs.anthropic.com/en/docs/claude-code)
16
- [![Codex](https://img.shields.io/badge/Codex-Plugin-000000?logo=openai&logoColor=white)](https://developers.openai.com/codex)
12
+ [![Windows 10/11](https://img.shields.io/badge/Windows-10%2F11-0078D4)](https://www.microsoft.com/windows)
13
+ [![Claude Code plugin](https://img.shields.io/badge/Claude%20Code-plugin-D97757)](https://docs.anthropic.com/en/docs/claude-code)
14
+ [![Codex plugin](https://img.shields.io/badge/Codex-plugin-FFFFFF)](https://developers.openai.com/codex)
15
+ [![License: MIT](https://img.shields.io/badge/License-MIT-000000)](LICENSE)
17
16
 
18
17
  </div>
19
18
 
20
19
  ---
21
20
 
22
- ## The Problem
21
+ ## Install
23
22
 
24
- You install a Claude Code / Codex plugin, start a session, and see errors like:
23
+ Pick your tool and paste one line.
25
24
 
26
- ```
27
- SessionStart hook error: /bin/bash: command not found
28
- PreToolUse hook error: scripts/check.sh: No such file or directory
29
- PostToolUse hook error: semgrep: command not found
30
- ```
31
-
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.
33
-
34
- ## Quick Start
35
-
36
- ### Claude Code
37
-
38
- Paste once:
25
+ **Claude Code**
39
26
 
40
27
  ```bash
41
28
  claude plugin marketplace add LilMGenius/win-hooks && claude plugin install win-hooks
42
29
  ```
43
30
 
44
- That is the setup. No config, no flags, no manual patching.
45
-
46
- ### Codex
47
-
48
- Paste once:
31
+ **Codex**
49
32
 
50
33
  ```bash
51
34
  codex plugin marketplace add LilMGenius/win-hooks && codex plugin add win-hooks@win-hooks
52
35
  ```
53
36
 
54
- Codex uses its native `commandWindows` field, so the original cross-platform `command` stays intact.
55
-
56
- ### CLI (npm)
57
-
58
- Want a one-shot fix, or to run it in CI, without installing the plugin? Run it directly:
37
+ **Neither, just fix my plugins now**
59
38
 
60
39
  ```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
40
+ npx @lilmgenius/win-hooks
63
41
  ```
64
42
 
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.
43
+ That's the whole setup. No config, no flags, nothing to remember.
66
44
 
67
- ## What win-hooks Fixes
45
+ You need Windows 10/11 and [Git for Windows](https://git-scm.com/download/win). Node.js already comes with Claude Code and Codex.
68
46
 
69
- win-hooks scans your installed Claude Code / Codex plugins and repairs Windows-incompatible hook commands before they keep breaking your session.
47
+ ## What it fixes
70
48
 
71
- It handles the common failure modes:
72
-
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:
87
-
88
- ```mermaid
89
- flowchart LR
90
- A[scan plugins] --> B[patch hooks.json] --> C[normalize settings.json] --> D["verify & auto-repair"]
91
- ```
92
-
93
- Codex pipeline:
94
-
95
- ```mermaid
96
- flowchart LR
97
- A[scan plugins] --> B["add commandWindows wrappers"] --> C["verify & auto-repair"]
98
- ```
49
+ You installed a plugin. It works fine for everyone on a Mac. On your machine it greets you with red text every time you open a session.
99
50
 
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
105
-
106
- The normal path is silent, so win-hooks writes a small heartbeat log:
107
-
108
- ```bash
109
- tail -n 5 ~/.claude/win-hooks/last-run.log
110
- tail -n 5 ~/.codex/win-hooks/last-run.log
111
- ```
112
-
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
- ```
122
-
123
- ## Commands
124
-
125
- | Command | Description |
51
+ | The error you see | What was wrong |
126
52
  |---|---|
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. |
129
-
130
- ## Requirements
53
+ | `check.sh: No such file or directory` | Windows can't run a `.sh` script directly |
54
+ | `semgrep: command not found` | The plugin expects a Unix tool you don't have |
55
+ | `'node' is not recognized` | Works in Git Bash, invisible to the process that launches hooks |
56
+ | `Python was not found; ... Microsoft Store` | Windows' fake `python3` placeholder shadowing your real one |
57
+ | `JSON Parse error: Unrecognized token` | An invisible byte (BOM) at the top of a config file |
58
+ | `Cannot find module 'C:\Users...'` | Backslashes in a path getting eaten before the hook runs |
131
59
 
132
- - Windows 10/11
133
- - Claude Code / Codex
134
- - Git for Windows
135
- - Node.js available on PATH
60
+ None of that is your fault. Almost every plugin is written and tested on macOS or Linux, so its hooks assume Unix tools that Windows does not have.
136
61
 
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.
62
+ ## How it stays fixed
138
63
 
139
- ## Technical Notes
64
+ win-hooks repairs your plugins at every session start, including ones you install later and ones that break again after an update. Repairs are written next to the original file, never on top of it, and anything already working is left alone.
140
65
 
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.
66
+ A healthy run is silent. To look anyway:
142
67
 
143
- ```
144
- plugin/
145
- ├── hooks/
146
- │ ├── hooks.json
147
- │ └── hooks.json.bak
148
- ├── _hooks/
149
- │ ├── run-hook.cmd
150
- │ └── <wrapper>
151
- └── scripts/
152
- └── setup.sh
153
- ```
154
-
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.
68
+ | Command | What it does |
69
+ |---|---|
70
+ | `/win-hooks:patch` | Checks every plugin, shows what it found, repairs anything broken |
71
+ | `npx @lilmgenius/win-hooks patch` | The same, from any terminal |
156
72
 
157
- For Codex, win-hooks creates `_codex_hooks/` and adds `commandWindows` to incompatible hook entries:
73
+ ## Privacy
158
74
 
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
- ```
75
+ win-hooks runs entirely on your machine and sends nothing anywhere. No telemetry, no network calls, no account. Outside a plugin's own folder it writes only a short local log of its own runs, so you can confirm it ran.
170
76
 
171
- Codex keeps using the original `command` on macOS/Linux. On Windows it uses the generated `commandWindows` wrapper.
77
+ ## License
172
78
 
173
- Contributors can read [`CLAUDE.md`](CLAUDE.md) for the internal scanner, patcher, verifier, and case notes.
79
+ [MIT](LICENSE). How it works, and every failure mode it handles: [`AGENTS.md`](AGENTS.md).
package/bin/win-hooks.mjs CHANGED
@@ -1,82 +1,116 @@
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
+ // win-hooks patch [host] report, repair what is not healthy, prove the result
8
9
  //
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.
10
+ // --changed-only skip when no plugin's hooks changed since the last run
11
+ // (the per-prompt guard; near-free on the hot path)
12
+ //
13
+ // Progress goes to stderr, never stdout: these hooks run under Claude Code,
14
+ // whose UserPromptSubmit stdout is injected into the model's context. `status`
15
+ // and `patch` are the exception - a person asked for their output.
16
+
17
+ import { isWindows } from '../src/env.mjs';
18
+ import { HOSTS } from '../src/hosts.mjs';
19
+ import { heal, inspect } from '../src/heal.mjs';
20
+
21
+ const USAGE = 'usage: win-hooks [heal|status|patch] [claude|codex] [--changed-only]';
12
22
 
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';
23
+ const args = process.argv.slice(2);
24
+ const flags = new Set(args.filter((a) => a.startsWith('--')));
25
+ const words = args.filter((a) => !a.startsWith('--'));
26
+ const command = ['heal', 'status', 'patch'].includes(words[0]) ? words.shift() : 'heal';
27
+ const hostIds = words.length ? words : Object.keys(HOSTS);
18
28
 
19
- const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
29
+ if (hostIds.some((id) => !HOSTS[id])) {
30
+ console.error(USAGE);
31
+ process.exit(2);
32
+ }
20
33
 
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.');
34
+ if (!isWindows()) {
35
+ // Hooks run natively on macOS and Linux. Nothing to repair is not an error.
36
+ console.error('win-hooks: not Windows - your plugin hooks already run natively here.');
24
37
  process.exit(0);
25
38
  }
26
39
 
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;
40
+ if (command !== 'heal') {
41
+ console.log(hostIds.map(command === 'patch' ? patchHost : statusOf).join('\n\n'));
42
+ process.exit(0);
43
+ }
44
+
45
+ for (const id of hostIds) {
36
46
  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;
47
+ const result = heal(id, { changedOnly: flags.has('--changed-only') });
48
+ if (result) for (const line of summarize(result)) console.error(line);
49
+ } catch (e) {
50
+ // One broken host must not take the session down with it.
51
+ console.error('win-hooks: ' + HOSTS[id].label + ' repair failed - ' + e.message);
52
+ }
42
53
  }
43
54
 
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;
55
+ function summarize({ host, patched, failed, settings, issues, fixes }) {
56
+ const lines = [];
57
+ for (const p of patched) lines.push('win-hooks: patched ' + p.plugin.id + ' (' + p.wrappers.join(', ') + ')');
58
+ for (const f of failed) lines.push('win-hooks: could not patch ' + f.plugin.id + ' - ' + f.error);
59
+ if (settings.length) lines.push('win-hooks: repaired ' + settings.length + ' hook command(s) in ' + host.label + ' settings');
60
+ for (const f of fixes) lines.push('win-hooks: ' + f);
61
+ if (patched.length || fixes.length) {
62
+ lines.push('win-hooks: repairs are on disk - run /reload-plugins to apply them to this session.');
49
63
  }
50
- return res.status ?? 0;
64
+ const unresolved = issues.length - fixes.length;
65
+ if (unresolved > 0) lines.push('win-hooks: ' + unresolved + ' issue(s) need attention - run /win-hooks:patch');
66
+ return lines;
51
67
  }
52
68
 
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'));
69
+ // Report, repair what is not healthy, then prove the result - one verb,
70
+ // because nobody inspects hooks for their own sake. A healthy host leaves
71
+ // nothing to decide, and a broken one was always going to be repaired, so
72
+ // splitting the two only asks the user which one they needed.
73
+ function patchHost(id) {
74
+ const before = inspect(id);
75
+ if (healthy(before)) return report(before) + heartbeat(before);
76
+
77
+ try {
78
+ heal(id);
79
+ } catch (e) {
80
+ return report(before) + '\n\n repair failed - ' + e.message;
61
81
  }
62
- if (!shown) console.log('win-hooks: no heartbeat yet — run `npx win-hooks` or start a session.');
63
- return 0;
82
+
83
+ const after = inspect(id);
84
+ return report(before) + '\n\n' + report(after, 'after repair') + heartbeat(after)
85
+ + '\n repairs are on disk - run /reload-plugins to apply them to this session.';
86
+ }
87
+
88
+ // Every function below is a declaration, not a const: the dispatch above runs
89
+ // before this point in the module, and only declarations are hoisted.
90
+ function statusOf(id) {
91
+ const state = inspect(id);
92
+ return report(state) + heartbeat(state);
93
+ }
94
+
95
+ function healthy({ incompatible, issues, settings }) {
96
+ return !incompatible.length && !issues.length && !settings.length;
64
97
  }
65
98
 
66
- const cmd = (process.argv[2] || 'fix').toLowerCase();
67
- if (cmd === 'status') process.exit(status());
99
+ function report({ host, plugins, incompatible, issues, settings }, heading) {
100
+ const title = '# ' + host.label + (heading ? ' ' + heading : '')
101
+ + ' - ' + plugins.length + ' hook file(s) scanned';
102
+ const lines = [title];
68
103
 
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);
104
+ for (const i of incompatible) lines.push(' incompatible ' + i.id + ' [' + i.event + '] ' + i.command);
105
+ for (const i of issues) lines.push(' ' + i.type.padEnd(14) + i.plugin + ' ' + i.detail);
106
+ for (const s of settings) lines.push(' ' + s.type.padEnd(14) + s.path + ' ' + s.to);
107
+ if (lines.length === 1) lines.push(' healthy - every hook is Windows-compatible');
108
+ return lines.join('\n');
73
109
  }
74
110
 
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);
111
+ // The happy path is silent, so the run log is the only way to tell a healthy
112
+ // host apart from a hook that never dispatched at all (CASE-25).
113
+ function heartbeat({ log }) {
114
+ return '\n\n last runs:\n'
115
+ + (log.length ? log.map((l) => ' ' + l) : [' (never run)']).join('\n');
81
116
  }
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,21 @@
1
1
  {
2
2
  "name": "@lilmgenius/win-hooks",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
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.",
7
+ "description": "Windows auto-patcher for vibe coders.",
8
+ "longDescription": "win-hooks scans the Claude Code and Codex plugins installed on a Windows machine and repairs the hooks that cannot run there: .sh scripts cmd.exe cannot execute, bare Unix commands and interpreters that do not resolve, UTF-8 BOMs, and backslash paths. It repairs at every session start and again whenever a plugin update reverts a fix, so plugins installed later are covered too.",
9
+ "scripts": {
10
+ "test": "node test/run.mjs"
11
+ },
8
12
  "bin": {
9
13
  "win-hooks": "bin/win-hooks.mjs"
10
14
  },
11
15
  "files": [
12
16
  "bin/",
13
17
  "hooks/",
14
- "scripts/",
18
+ "src/",
15
19
  "LICENSE",
16
20
  "README.md"
17
21
  ],
@@ -35,14 +39,5 @@
35
39
  "bugs": {
36
40
  "url": "https://github.com/LilMGenius/win-hooks/issues"
37
41
  },
38
- "keywords": [
39
- "windows",
40
- "hooks",
41
- "claude-code",
42
- "codex",
43
- "compatibility",
44
- "patch",
45
- "cli",
46
- "cross-platform"
47
- ]
42
+ "keywords": ["windows","hooks","claude-code","codex","plugin","compatibility","patch","cli","winux"]
48
43
  }