fix: 尝试修复 nodejs windows 环境的问题

This commit is contained in:
claude-code-best
2026-04-25 14:07:45 +08:00
parent 2e7fc428cd
commit 7a3cc24a00

View File

@@ -68,8 +68,15 @@ let nextId = 1
/** /**
* Default socket path based on PID, placed in a tmpdir subdirectory so it * Default socket path based on PID, placed in a tmpdir subdirectory so it
* survives across config-home changes and avoids polluting ~/.claude. * survives across config-home changes and avoids polluting ~/.claude.
*
* On Windows, Node.js requires named pipe paths in the `\\.\pipe\` namespace;
* file-system paths like `C:\...\Temp\x.sock` cause EACCES. Bun handles both
* transparently, but we use the pipe format on Windows for Node.js compat.
*/ */
export function getDefaultUdsSocketPath(): string { export function getDefaultUdsSocketPath(): string {
if (process.platform === 'win32') {
return `\\\\.\\pipe\\claude-code-${process.pid}`
}
return join(tmpdir(), 'claude-code-socks', `${process.pid}.sock`) return join(tmpdir(), 'claude-code-socks', `${process.pid}.sock`)
} }
@@ -123,14 +130,18 @@ export async function startUdsMessaging(
return return
} }
// Ensure parent directory exists // Ensure parent directory exists (skip on Windows — pipe paths aren't files)
await mkdir(dirname(path), { recursive: true }) if (process.platform !== 'win32') {
await mkdir(dirname(path), { recursive: true })
}
// Clean up stale socket file // Clean up stale socket file (skip on Windows — pipe paths aren't files)
try { if (process.platform !== 'win32') {
await unlink(path) try {
} catch { await unlink(path)
// ENOENT is fine } catch {
// ENOENT is fine
}
} }
socketPath = path socketPath = path
@@ -220,12 +231,14 @@ export async function stopUdsMessaging(): Promise<void> {
}) })
server = null server = null
// Remove socket file // Remove socket file (skip on Windows — pipe paths aren't files)
if (socketPath) { if (socketPath) {
try { if (process.platform !== 'win32') {
await unlink(socketPath) try {
} catch { await unlink(socketPath)
// Already gone } catch {
// Already gone
}
} }
delete process.env.CLAUDE_CODE_MESSAGING_SOCKET delete process.env.CLAUDE_CODE_MESSAGING_SOCKET
logForDebugging( logForDebugging(