diff --git a/src/agent/claude-code/binary.ts b/src/agent/claude-code/binary.ts index 44becc3..5e57cda 100644 --- a/src/agent/claude-code/binary.ts +++ b/src/agent/claude-code/binary.ts @@ -20,7 +20,7 @@ function getWindowsSearchSpec(env: BinaryLookup["env"], homeDir: string): Search const appData = env.APPDATA ?? paths.join(homeDir, "AppData", "Roaming"); return { paths, - names: ["claude.cmd", "claude.exe"], + names: ["claude.exe", "claude.cmd"], knownDirs: [paths.join(homeDir, ".local", "bin"), paths.join(homeDir, ".claude", "local"), env.npm_config_prefix ?? paths.join(appData, "npm")], }; } @@ -38,8 +38,8 @@ function getPosixSearchSpec(env: BinaryLookup["env"], homeDir: string): SearchSp export function resolveClaudeBinary({ env, platform, homeDir, isExecutable }: BinaryLookup): string | null { const { paths, names, knownDirs } = platform === "win32" ? getWindowsSearchSpec(env, homeDir) : getPosixSearchSpec(env, homeDir); const pathDirs = (env.PATH ?? "").split(paths.delimiter).filter(Boolean); - for (const dir of [...pathDirs, ...knownDirs]) { - for (const name of names) { + for (const name of names) { + for (const dir of [...pathDirs, ...knownDirs]) { const candidate = paths.join(dir, name); if (isExecutable(candidate)) return candidate; } diff --git a/tests/claude-code-binary.test.ts b/tests/claude-code-binary.test.ts index 05adf28..00c7d34 100644 --- a/tests/claude-code-binary.test.ts +++ b/tests/claude-code-binary.test.ts @@ -49,6 +49,13 @@ test("windows looks for claude.cmd and claude.exe", () => { assert.equal(resolveWith(["C:\\bin\\claude"], env, "win32", winHome), null); }); +test("windows prefers claude.exe anywhere over claude.cmd, which Node cannot spawn without a shell", () => { + const winHome = "C:\\Users\\u"; + const env = { PATH: "C:\\bin", APPDATA: `${winHome}\\AppData\\Roaming` }; + const executables = ["C:\\bin\\claude.cmd", `${winHome}\\.local\\bin\\claude.exe`]; + assert.equal(resolveWith(executables, env, "win32", winHome), `${winHome}\\.local\\bin\\claude.exe`); +}); + test("returns null when every location misses", () => { assert.equal(resolveWith([], { PATH: "/usr/bin:/bin" }), null); });