claude-git-hooks 2.33.0 → 2.33.1
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/CHANGELOG.md +13 -0
- package/lib/commands/helpers.js +69 -2
- package/lib/utils/claude-client.js +177 -37
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,19 @@ Todos los cambios notables en este proyecto se documentarán en este archivo.
|
|
|
5
5
|
El formato está basado en [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
y este proyecto adhiere a [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.33.1] - 2026-03-26
|
|
9
|
+
|
|
10
|
+
### 🔧 Changed
|
|
11
|
+
- Improved WSL Claude CLI detection to resolve Claude's path via login shell when installed via nvm or user-scoped npm prefix
|
|
12
|
+
- Added support for detecting Claude CLI in non-default WSL distros when the default distro is docker-desktop or similar
|
|
13
|
+
- Switched to execFileSync for WSL distro listing to avoid cmd.exe quote mangling issues
|
|
14
|
+
- Updated README-NPM with release workflow commands documentation and WSL troubleshooting guide
|
|
15
|
+
|
|
16
|
+
### 🐛 Fixed
|
|
17
|
+
- Fixed Claude CLI not being detected on Windows when running from Git Bash with Claude installed inside WSL via nvm (#120)
|
|
18
|
+
- Fixed WSL distro detection failing due to UTF-16LE encoding from wsl.exe output
|
|
19
|
+
|
|
20
|
+
|
|
8
21
|
## [2.33.0] - 2026-03-20
|
|
9
22
|
|
|
10
23
|
### ✨ Added
|
package/lib/commands/helpers.js
CHANGED
|
@@ -18,6 +18,7 @@ import os from 'os';
|
|
|
18
18
|
import https from 'https';
|
|
19
19
|
import { fileURLToPath } from 'url';
|
|
20
20
|
import { dirname } from 'path';
|
|
21
|
+
import { getRunningWSLDistros } from '../utils/claude-client.js';
|
|
21
22
|
|
|
22
23
|
// Why: ES6 modules don't have __dirname, need to recreate it
|
|
23
24
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -130,9 +131,46 @@ export function isWindows() {
|
|
|
130
131
|
return os.platform() === 'win32' || process.env.OS === 'Windows_NT';
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Resolve Claude's absolute path inside WSL via login shell
|
|
136
|
+
* Why: If Claude is installed via nvm or user-scoped npm prefix in WSL,
|
|
137
|
+
* it's only in PATH when .bashrc/.profile is sourced (login/interactive shell).
|
|
138
|
+
* A bare `wsl claude` runs a non-interactive shell that skips profile loading.
|
|
139
|
+
*
|
|
140
|
+
* @param {string|null} distro - WSL distro name (null = default distro)
|
|
141
|
+
* @returns {string|null} Absolute Linux path to claude binary, or null
|
|
142
|
+
*/
|
|
143
|
+
export function resolveClaudePathInWSL(distro = null) {
|
|
144
|
+
const distroFlag = distro ? `-d "${distro}" ` : '';
|
|
145
|
+
try {
|
|
146
|
+
const resolvedPath = execSync(`wsl ${distroFlag}bash -lc "which claude"`, {
|
|
147
|
+
encoding: 'utf8',
|
|
148
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
149
|
+
timeout: 10000
|
|
150
|
+
}).trim();
|
|
151
|
+
|
|
152
|
+
if (resolvedPath && resolvedPath.startsWith('/')) {
|
|
153
|
+
// Verify the resolved path actually works
|
|
154
|
+
execSync(`wsl ${distroFlag}${resolvedPath} --version`, {
|
|
155
|
+
stdio: 'ignore',
|
|
156
|
+
timeout: 10000
|
|
157
|
+
});
|
|
158
|
+
return resolvedPath;
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
} catch (e) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
133
166
|
/**
|
|
134
167
|
* Get Claude command based on platform
|
|
135
168
|
* Why: On Windows, try native Claude first, then WSL as fallback
|
|
169
|
+
* Strategy:
|
|
170
|
+
* 1. Native Windows `claude` (installed via npm/scoop/choco on Windows)
|
|
171
|
+
* 2. Direct `wsl claude` (Claude in WSL default PATH)
|
|
172
|
+
* 3. WSL login-shell resolution (Claude installed via nvm or custom PATH in WSL)
|
|
173
|
+
* 4. Non-default distro scan (default may be docker-desktop, not Ubuntu)
|
|
136
174
|
* @returns {string}
|
|
137
175
|
*/
|
|
138
176
|
export function getClaudeCommand() {
|
|
@@ -142,8 +180,37 @@ export function getClaudeCommand() {
|
|
|
142
180
|
execSync('claude --version', { stdio: 'ignore', timeout: 3000 });
|
|
143
181
|
return 'claude';
|
|
144
182
|
} catch (e) {
|
|
145
|
-
//
|
|
146
|
-
|
|
183
|
+
// Try direct WSL (Claude in default non-interactive PATH)
|
|
184
|
+
try {
|
|
185
|
+
execSync('wsl claude --version', { stdio: 'ignore', timeout: 10000 });
|
|
186
|
+
return 'wsl claude';
|
|
187
|
+
} catch (e2) {
|
|
188
|
+
// Try WSL with login shell (Claude installed via nvm or custom PATH)
|
|
189
|
+
const resolvedPath = resolveClaudePathInWSL();
|
|
190
|
+
if (resolvedPath) {
|
|
191
|
+
return `wsl ${resolvedPath}`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Strategy 4: Non-default WSL distro (e.g., default is docker-desktop)
|
|
195
|
+
const distros = getRunningWSLDistros('wsl');
|
|
196
|
+
for (const distro of distros) {
|
|
197
|
+
try {
|
|
198
|
+
execSync(`wsl -d "${distro}" claude --version`, {
|
|
199
|
+
stdio: 'ignore',
|
|
200
|
+
timeout: 10000
|
|
201
|
+
});
|
|
202
|
+
return `wsl -d "${distro}" claude`;
|
|
203
|
+
} catch (distroError) {
|
|
204
|
+
const resolved = resolveClaudePathInWSL(distro);
|
|
205
|
+
if (resolved) {
|
|
206
|
+
return `wsl -d "${distro}" ${resolved}`;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// All attempts failed — return best-effort fallback
|
|
212
|
+
return 'wsl claude';
|
|
213
|
+
}
|
|
147
214
|
}
|
|
148
215
|
}
|
|
149
216
|
return 'claude';
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* - claude-diagnostics: Error detection and formatting
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { spawn, execSync } from 'child_process';
|
|
18
|
+
import { spawn, execSync, execFileSync } from 'child_process';
|
|
19
19
|
import fs from 'fs/promises';
|
|
20
20
|
import path from 'path';
|
|
21
21
|
import os from 'os';
|
|
@@ -70,6 +70,37 @@ const isWSLAvailable = () => {
|
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Get running WSL distros, excluding Docker-internal ones
|
|
75
|
+
* Why: The default WSL distro may be docker-desktop (which doesn't have Claude).
|
|
76
|
+
* We need to find the actual Linux distro (e.g., Ubuntu) where Claude is installed.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} wslPath - Absolute path to wsl.exe
|
|
79
|
+
* @returns {string[]} List of running non-Docker distro names
|
|
80
|
+
*/
|
|
81
|
+
export const getRunningWSLDistros = (wslPath) => {
|
|
82
|
+
try {
|
|
83
|
+
// Use execFileSync to bypass cmd.exe shell quoting — args passed directly to wsl.exe
|
|
84
|
+
const raw = execFileSync(wslPath, ['-l', '--running', '-q'], {
|
|
85
|
+
timeout: 5000,
|
|
86
|
+
stdio: ['pipe', 'pipe', 'ignore']
|
|
87
|
+
});
|
|
88
|
+
// Why UTF-16LE: wsl.exe is a native Windows executable that outputs Unicode in Windows' default
|
|
89
|
+
// encoding (UTF-16LE), not UTF-8. The null bytes (\0) are BOM artifacts and padding characters
|
|
90
|
+
// from the UTF-16LE encoding that must be stripped to get clean distro names.
|
|
91
|
+
const output = raw.toString('utf16le');
|
|
92
|
+
return output
|
|
93
|
+
.split(/\r?\n/)
|
|
94
|
+
.map((s) => s.replace(/\0/g, '').trim())
|
|
95
|
+
.filter((s) => s && !s.toLowerCase().includes('docker'));
|
|
96
|
+
} catch (e) {
|
|
97
|
+
logger.debug('claude-client - getRunningWSLDistros', 'Failed to list WSL distros', {
|
|
98
|
+
error: e.message
|
|
99
|
+
});
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
73
104
|
/**
|
|
74
105
|
* Get Claude command configuration for current platform
|
|
75
106
|
* Why: On Windows, try native Claude first, then WSL as fallback
|
|
@@ -112,11 +143,12 @@ const getClaudeCommand = () => {
|
|
|
112
143
|
// Node 24: Resolve wsl.exe absolute path to avoid shell: true
|
|
113
144
|
const wslPath = which('wsl');
|
|
114
145
|
if (wslPath) {
|
|
146
|
+
const wslCheckTimeout = config.system.wslCheckTimeout || 15000;
|
|
147
|
+
|
|
148
|
+
// Strategy 1: Direct `wsl claude` (Claude in default non-interactive PATH)
|
|
149
|
+
// Use execFileSync to bypass cmd.exe — args passed directly to wsl.exe without quote mangling
|
|
115
150
|
try {
|
|
116
|
-
|
|
117
|
-
// Increased timeout from 5s to 15s to handle system load better
|
|
118
|
-
const wslCheckTimeout = config.system.wslCheckTimeout || 15000;
|
|
119
|
-
execSync(`"${wslPath}" claude --version`, {
|
|
151
|
+
execFileSync(wslPath, ['claude', '--version'], {
|
|
120
152
|
stdio: 'ignore',
|
|
121
153
|
timeout: wslCheckTimeout
|
|
122
154
|
});
|
|
@@ -125,11 +157,9 @@ const getClaudeCommand = () => {
|
|
|
125
157
|
});
|
|
126
158
|
return { command: wslPath, args: ['claude'] };
|
|
127
159
|
} catch (wslError) {
|
|
128
|
-
// Differentiate error types for accurate user feedback
|
|
129
160
|
const errorMsg = wslError.message || '';
|
|
130
|
-
const wslCheckTimeout = config.system.wslCheckTimeout || 15000;
|
|
131
161
|
|
|
132
|
-
// Timeout: Transient system load issue
|
|
162
|
+
// Timeout: Transient system load issue — don't try fallback
|
|
133
163
|
if (errorMsg.includes('ETIMEDOUT')) {
|
|
134
164
|
throw new ClaudeClientError(
|
|
135
165
|
'Timeout connecting to WSL - system under heavy load',
|
|
@@ -146,30 +176,132 @@ const getClaudeCommand = () => {
|
|
|
146
176
|
);
|
|
147
177
|
}
|
|
148
178
|
|
|
149
|
-
// Not
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
179
|
+
// Not a timeout — try login-shell fallback below
|
|
180
|
+
logger.debug(
|
|
181
|
+
'claude-client - getClaudeCommand',
|
|
182
|
+
'Direct wsl claude failed, trying login-shell resolution',
|
|
183
|
+
{ error: errorMsg }
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Strategy 2: WSL login-shell resolution (Claude installed via nvm or custom PATH)
|
|
188
|
+
// Why: `wsl claude` runs a non-interactive shell that doesn't source .bashrc/.profile,
|
|
189
|
+
// so Claude installed via nvm or user-scoped npm prefix won't be in PATH.
|
|
190
|
+
// `bash -lc "which claude"` sources the login profile to resolve the full path.
|
|
191
|
+
// Why execFileSync: cmd.exe strips inner quotes from `bash -lc "which claude"`,
|
|
192
|
+
// causing bash to receive `which` and `claude` as separate args. execFileSync bypasses
|
|
193
|
+
// cmd.exe and passes arguments directly, preserving multi-word argument boundaries.
|
|
194
|
+
try {
|
|
195
|
+
const resolvedPath = execFileSync(
|
|
196
|
+
wslPath,
|
|
197
|
+
['bash', '-lc', 'which claude'],
|
|
198
|
+
{
|
|
199
|
+
encoding: 'utf8',
|
|
200
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
201
|
+
timeout: wslCheckTimeout
|
|
202
|
+
}
|
|
203
|
+
).trim();
|
|
204
|
+
|
|
205
|
+
if (resolvedPath && resolvedPath.startsWith('/')) {
|
|
206
|
+
// Verify: run the resolved path via login shell (node may also require login shell)
|
|
207
|
+
execFileSync(wslPath, ['bash', '-lc', `${resolvedPath} --version`], {
|
|
208
|
+
stdio: 'ignore',
|
|
209
|
+
timeout: wslCheckTimeout
|
|
159
210
|
});
|
|
211
|
+
logger.debug(
|
|
212
|
+
'claude-client - getClaudeCommand',
|
|
213
|
+
'Using WSL Claude CLI via login-shell resolution',
|
|
214
|
+
{ wslPath, claudePath: resolvedPath }
|
|
215
|
+
);
|
|
216
|
+
// Return loginShell so executeClaude wraps the call in bash -lc
|
|
217
|
+
return { command: wslPath, args: [], loginShell: { path: resolvedPath } };
|
|
160
218
|
}
|
|
219
|
+
} catch (loginShellError) {
|
|
220
|
+
logger.debug(
|
|
221
|
+
'claude-client - getClaudeCommand',
|
|
222
|
+
'WSL login-shell resolution failed',
|
|
223
|
+
{ error: loginShellError.message }
|
|
224
|
+
);
|
|
225
|
+
}
|
|
161
226
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
227
|
+
// Strategy 3: Non-default WSL distro (e.g., default is docker-desktop)
|
|
228
|
+
// Why: If the default WSL distro is docker-desktop or another minimal distro,
|
|
229
|
+
// Claude may be installed in a different distro like Ubuntu.
|
|
230
|
+
const distros = getRunningWSLDistros(wslPath);
|
|
231
|
+
logger.debug(
|
|
232
|
+
'claude-client - getClaudeCommand',
|
|
233
|
+
'Trying non-default WSL distros',
|
|
234
|
+
{ distros }
|
|
235
|
+
);
|
|
236
|
+
|
|
237
|
+
for (const distro of distros) {
|
|
238
|
+
// Try direct call in this distro
|
|
239
|
+
try {
|
|
240
|
+
execFileSync(wslPath, ['-d', distro, 'claude', '--version'], {
|
|
241
|
+
stdio: 'ignore',
|
|
242
|
+
timeout: wslCheckTimeout
|
|
243
|
+
});
|
|
244
|
+
logger.debug(
|
|
245
|
+
'claude-client - getClaudeCommand',
|
|
246
|
+
'Using WSL Claude CLI in distro',
|
|
247
|
+
{ wslPath, distro }
|
|
248
|
+
);
|
|
249
|
+
return { command: wslPath, args: ['-d', distro, 'claude'] };
|
|
250
|
+
} catch (distroError) {
|
|
251
|
+
// Try login-shell resolution in this distro
|
|
252
|
+
try {
|
|
253
|
+
const resolved = execFileSync(
|
|
254
|
+
wslPath,
|
|
255
|
+
['-d', distro, 'bash', '-lc', 'which claude'],
|
|
256
|
+
{
|
|
257
|
+
encoding: 'utf8',
|
|
258
|
+
stdio: ['pipe', 'pipe', 'ignore'],
|
|
259
|
+
timeout: wslCheckTimeout
|
|
260
|
+
}
|
|
261
|
+
).trim();
|
|
262
|
+
|
|
263
|
+
if (resolved && resolved.startsWith('/')) {
|
|
264
|
+
execFileSync(
|
|
265
|
+
wslPath,
|
|
266
|
+
['-d', distro, 'bash', '-lc', `${resolved} --version`],
|
|
267
|
+
{
|
|
268
|
+
stdio: 'ignore',
|
|
269
|
+
timeout: wslCheckTimeout
|
|
270
|
+
}
|
|
271
|
+
);
|
|
272
|
+
logger.debug(
|
|
273
|
+
'claude-client - getClaudeCommand',
|
|
274
|
+
'Using WSL Claude CLI via login-shell in distro',
|
|
275
|
+
{ wslPath, distro, claudePath: resolved }
|
|
276
|
+
);
|
|
277
|
+
// Return loginShell so executeClaude wraps the call in bash -lc
|
|
278
|
+
return {
|
|
279
|
+
command: wslPath,
|
|
280
|
+
args: ['-d', distro],
|
|
281
|
+
loginShell: { path: resolved }
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
} catch (distroLoginError) {
|
|
285
|
+
logger.debug(
|
|
286
|
+
'claude-client - getClaudeCommand',
|
|
287
|
+
`Distro ${distro} does not have Claude`,
|
|
288
|
+
{ error: distroLoginError.message }
|
|
289
|
+
);
|
|
170
290
|
}
|
|
171
|
-
}
|
|
291
|
+
}
|
|
172
292
|
}
|
|
293
|
+
|
|
294
|
+
// All strategies failed
|
|
295
|
+
throw new ClaudeClientError('Claude CLI not found in WSL', {
|
|
296
|
+
context: {
|
|
297
|
+
platform: 'Windows',
|
|
298
|
+
wslPath,
|
|
299
|
+
error: 'Claude not found via direct call or login-shell resolution',
|
|
300
|
+
triedDistros: distros,
|
|
301
|
+
suggestion:
|
|
302
|
+
'Install Claude in WSL: wsl -e bash -c "npm install -g @anthropic-ai/claude-cli"'
|
|
303
|
+
}
|
|
304
|
+
});
|
|
173
305
|
}
|
|
174
306
|
|
|
175
307
|
throw new ClaudeClientError('Claude CLI not found in Windows or WSL', {
|
|
@@ -212,18 +344,26 @@ const getClaudeCommand = () => {
|
|
|
212
344
|
const executeClaude = (prompt, { timeout = 120000, allowedTools = [], model = null } = {}) =>
|
|
213
345
|
new Promise((resolve, reject) => {
|
|
214
346
|
// Get platform-specific command
|
|
215
|
-
const { command, args } = getClaudeCommand();
|
|
347
|
+
const { command, args, loginShell } = getClaudeCommand();
|
|
216
348
|
|
|
217
|
-
//
|
|
349
|
+
// Build final args — handling differs for login-shell (WSL via bash -lc) vs direct invocation
|
|
218
350
|
const finalArgs = [...args];
|
|
219
|
-
if (
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
finalArgs.push('
|
|
351
|
+
if (loginShell) {
|
|
352
|
+
// Why: When claude is found via WSL login-shell (e.g. nvm-installed node), it must be
|
|
353
|
+
// executed inside bash --login so that .profile/.bashrc set up the correct PATH.
|
|
354
|
+
// All CLI flags are embedded in the bash -c command string (no spaces in flag values).
|
|
355
|
+
const claudeParts = [loginShell.path];
|
|
356
|
+
if (allowedTools.length > 0) claudeParts.push(`--allowedTools ${allowedTools.join(',')}`);
|
|
357
|
+
if (model) claudeParts.push(`--model ${model}`);
|
|
358
|
+
finalArgs.push('bash', '-lc', claudeParts.join(' '));
|
|
359
|
+
} else {
|
|
360
|
+
if (allowedTools.length > 0) {
|
|
361
|
+
// Format: --allowedTools "mcp__github__create_pull_request,mcp__github__get_file_contents"
|
|
362
|
+
finalArgs.push('--allowedTools', allowedTools.join(','));
|
|
363
|
+
}
|
|
364
|
+
if (model) {
|
|
365
|
+
finalArgs.push('--model', model);
|
|
366
|
+
}
|
|
227
367
|
}
|
|
228
368
|
|
|
229
369
|
// CRITICAL FIX: Windows .cmd/.bat file handling
|