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:
@@ -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) {
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user