fix: SDK Agent fails on Windows when username contains spaces (#1022)

* fix: SDK Agent fails on Windows when username contains spaces

Fixes spawn failure on Windows when the user's path contains spaces
(e.g., C:\Users\Anderson Wang\).

Root cause:
- SDKAgent.ts returns full auto-detected path with spaces
- ProcessRegistry.ts cannot execute .cmd files when path contains spaces

Solution:
- SDKAgent: On Windows, prefer "claude.cmd" via PATH instead of full path
- ProcessRegistry: Use cmd.exe /d /c wrapper for .cmd files on Windows

This preserves argument boundaries (e.g., empty string values) while
properly handling paths with spaces.

Fixes #1014

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* docs: add Windows spawn path with spaces fix documentation

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
ixnaswang
2026-02-16 13:31:11 +08:00
committed by GitHub
parent 6d1f17adee
commit 81013e1310
3 changed files with 127 additions and 8 deletions
+18 -7
View File
@@ -282,13 +282,24 @@ export function createPidCapturingSpawn(sessionDbId: number) {
env?: NodeJS.ProcessEnv;
signal?: AbortSignal;
}) => {
const child = spawn(spawnOptions.command, spawnOptions.args, {
cwd: spawnOptions.cwd,
env: spawnOptions.env,
stdio: ['pipe', 'pipe', 'pipe'],
signal: spawnOptions.signal, // CRITICAL: Pass signal for AbortController integration
windowsHide: true
});
// On Windows, use cmd.exe wrapper for .cmd files to properly handle paths with spaces
const useCmdWrapper = process.platform === 'win32' && spawnOptions.command.endsWith('.cmd');
const child = useCmdWrapper
? spawn('cmd.exe', ['/d', '/c', spawnOptions.command, ...spawnOptions.args], {
cwd: spawnOptions.cwd,
env: spawnOptions.env,
stdio: ['pipe', 'pipe', 'pipe'],
signal: spawnOptions.signal,
windowsHide: true
})
: spawn(spawnOptions.command, spawnOptions.args, {
cwd: spawnOptions.cwd,
env: spawnOptions.env,
stdio: ['pipe', 'pipe', 'pipe'],
signal: spawnOptions.signal, // CRITICAL: Pass signal for AbortController integration
windowsHide: true
});
// Capture stderr for debugging spawn failures
if (child.stderr) {
+11 -1
View File
@@ -446,7 +446,17 @@ export class SDKAgent {
return settings.CLAUDE_CODE_PATH;
}
// 2. Try auto-detection
// 2. On Windows, prefer "claude.cmd" via PATH to avoid spawn issues with spaces in paths
if (process.platform === 'win32') {
try {
execSync('where claude.cmd', { encoding: 'utf8', windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] });
return 'claude.cmd'; // Let Windows resolve via PATHEXT
} catch {
// Fall through to generic error
}
}
// 3. Try auto-detection for non-Windows platforms
try {
const claudePath = execSync(
process.platform === 'win32' ? 'where claude' : 'which claude',