fix(windows): use absolute path with shell:false for Claude spawn (#143)

On Windows, spawning Claude with shell: true causes the process to
exit immediately with code 1. This happens because shell: true invokes
cmd.exe /c claude <args>, and cmd.exe's PATH resolution differs from
direct process creation, leading to environment inconsistencies.

This fix:
- Adds findWindowsClaudePath() to locate claude.exe absolute path
- Changes spawn to use absolute path with shell: false on Windows
- Maintains Unix behavior (command name works fine with shell: false)
- Adds HAPI_CLAUDE_PATH env var for user override

Tested on Windows 11 with Claude Code v2.1.29 and hapi v0.15.0.

via [HAPI](https://hapi.run)

Co-authored-by: HAPI <noreply@hapi.run>
This commit is contained in:
tw23
2026-02-03 13:28:14 +08:00
committed by GitHub
co-authored by HAPI
parent 2f6bbcd400
commit 798317cd05
3 changed files with 73 additions and 24 deletions
+3 -2
View File
@@ -347,8 +347,9 @@ export function query(config: {
stdio: ['pipe', 'pipe', 'pipe'],
signal: config.options?.abort,
env: spawnEnv,
// Use shell on Windows for command resolution
shell: process.platform === 'win32'
// Use shell: false with absolute path from getDefaultClaudeCodePath()
// This avoids cmd.exe resolution issues on Windows
shell: false
}) as ChildProcessWithoutNullStreams
// Handle stdin