fix: prefer claude.exe over claude.cmd on Windows
Node cannot spawn a .cmd file without a shell, so a claude.cmd found earlier on PATH would hide a working claude.exe.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user