@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 +48 -100
- package/bin/win-hooks.mjs +59 -62
- package/hooks/codex-hooks.json +7 -7
- package/hooks/hooks.json +4 -4
- package/hooks/run-hook.cmd +43 -30
- package/hooks/win-hooks +10 -0
- package/package.json +5 -2
- package/src/env.mjs +122 -0
- package/src/heal.mjs +125 -0
- package/src/hosts.mjs +122 -0
- package/src/patch.mjs +93 -0
- package/src/rules.mjs +129 -0
- package/src/settings.mjs +61 -0
- package/src/verify.mjs +197 -0
- package/hooks/codex-patch-all +0 -75
- package/hooks/patch-all +0 -169
- package/hooks/reheal +0 -71
- package/scripts/apply-patches +0 -250
- package/scripts/codex-apply-patches +0 -108
- package/scripts/codex-find-incompatible +0 -94
- package/scripts/codex-verify +0 -393
- package/scripts/find-incompatible +0 -82
- package/scripts/fix-backslash-paths +0 -94
- package/scripts/fix-bare-commands +0 -147
- package/scripts/lib/plugins.sh +0 -132
- package/scripts/sync-version +0 -42
- package/scripts/verify +0 -334
package/README.md
CHANGED
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
### *"Linux? Nah. WinUX!"*
|
|
6
6
|
|
|
7
|
-
**
|
|
7
|
+
**Windows auto-patcher for vibe coders.**
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
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)
|
|
14
13
|
[](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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
33
|
+
## Install it once, forget it exists
|
|
37
34
|
|
|
38
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
62
|
-
npx @lilmgenius/win-hooks status
|
|
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
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
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
|
-
|
|
69
|
+
## Staying fixed
|
|
94
70
|
|
|
95
71
|
```mermaid
|
|
96
72
|
flowchart LR
|
|
97
|
-
A[scan plugins] --> B[
|
|
73
|
+
A[scan installed plugins] --> B[patch broken hooks] --> C[verify & auto-repair]
|
|
98
74
|
```
|
|
99
75
|
|
|
100
|
-
|
|
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
|
-
|
|
78
|
+
Because the healthy path is silent, it also leaves a short log behind:
|
|
107
79
|
|
|
108
80
|
```bash
|
|
109
|
-
|
|
110
|
-
tail -n 5 ~/.codex/win-hooks/last-run.log
|
|
81
|
+
npx @lilmgenius/win-hooks status
|
|
111
82
|
```
|
|
112
83
|
|
|
113
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
| Command | Description |
|
|
86
|
+
| Command | What it does |
|
|
126
87
|
|---|---|
|
|
127
|
-
| `/win-hooks:status` | Show
|
|
128
|
-
| `/win-hooks:fix` |
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
99
|
+
## For the curious
|
|
140
100
|
|
|
141
|
-
|
|
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
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
119
|
+
## License
|
|
172
120
|
|
|
173
|
-
|
|
121
|
+
[MIT](LICENSE).
|
package/bin/win-hooks.mjs
CHANGED
|
@@ -1,82 +1,79 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// win-hooks CLI
|
|
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
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
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
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
27
|
+
if (hostIds.some((id) => !HOSTS[id])) {
|
|
28
|
+
console.error(USAGE);
|
|
29
|
+
process.exit(2);
|
|
30
|
+
}
|
|
20
31
|
|
|
21
|
-
if (
|
|
22
|
-
// Hooks run natively on macOS
|
|
23
|
-
console.error('win-hooks
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
for (const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
63
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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);
|
package/hooks/codex-hooks.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "win-hooks:
|
|
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/
|
|
10
|
-
"commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\" codex
|
|
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:
|
|
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/
|
|
23
|
-
"commandWindows": "\"${PLUGIN_ROOT}\\hooks\\run-hook.cmd\"
|
|
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:
|
|
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:
|
|
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\"
|
|
10
|
-
"timeout":
|
|
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\"
|
|
20
|
+
"command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/run-hook.cmd\" win-hooks heal --changed-only"
|
|
21
21
|
}
|
|
22
22
|
]
|
|
23
23
|
}
|
package/hooks/run-hook.cmd
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
: << 'CMDBLOCK'
|
|
2
2
|
@echo off
|
|
3
|
-
REM
|
|
4
|
-
REM
|
|
5
|
-
REM
|
|
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
|
|
8
|
-
REM
|
|
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
|
|
20
|
-
REM
|
|
21
|
-
|
|
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
|
|
29
|
-
if exist "C:\Program Files\Git\bin\bash.exe"
|
|
30
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
#
|
|
62
|
+
# bash: run the named script directly.
|
|
50
63
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
51
64
|
SCRIPT_NAME="$1"
|
|
52
65
|
shift
|
package/hooks/win-hooks
ADDED
|
@@ -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.
|
|
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
|
-
"
|
|
17
|
+
"src/",
|
|
15
18
|
"LICENSE",
|
|
16
19
|
"README.md"
|
|
17
20
|
],
|