docs/bug-fixes/windows-spaces-issue.md
Summary: Claude SDK Agent fails to start on Windows when the user's path contains spaces (e.g., C:\Users\Anderson Wang\), causing PostToolUse hooks to hang indefinitely.
Severity: High - Core functionality broken
Affected Platform: Windows only
PostToolUse hook displays (1/2 done) indefinitely. Worker logs show:
ERROR [SESSION] Generator failed {provider=claude, error=Claude Code process exited with code 1}
ERROR [SESSION] Generator exited unexpectedly
Two issues in the Windows code path:
SDKAgent.ts - Returns full auto-detected path with spaces:
C:\Users\Anderson Wang\AppData\Roaming\npm\claude.cmd
ProcessRegistry.ts - Node.js spawn() cannot directly execute .cmd files when the path contains spaces
src/services/worker/SDKAgent.tsOn Windows, prefer claude.cmd via PATH instead of full auto-detected path:
// 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
}
}
src/services/worker/ProcessRegistry.tsUse cmd.exe /d /c wrapper for .cmd files on Windows:
const useCmdWrapper = process.platform === 'win32' && spawnOptions.command.endsWith('.cmd');
if (useCmdWrapper) {
child = spawn('cmd.exe', ['/d', '/c', spawnOptions.command, ...spawnOptions.args], {
cwd: spawnOptions.cwd,
env: spawnOptions.env,
stdio: ['pipe', 'pipe', 'pipe'],
signal: spawnOptions.signal,
windowsHide: true
});
}
shell: true prevents empty string misparsingVerified on Windows 11 with username containing spaces:
CLAUDE_CODE_PATH setting