fix(server): include stderr in claude auth status diagnostic

Some status output (e.g. "Not logged in") goes to stderr. Capture both
stdout and stderr, including when the command exits non-zero, so the
diagnostic surfaces the full picture.
This commit is contained in:
Mohamed Boudra
2026-04-16 18:54:56 +07:00
parent 1b4483615a
commit 2e95003154
@@ -1217,23 +1217,38 @@ async function resolveClaudeAuth(
): Promise<string | null> { ): Promise<string | null> {
const command = runtimeSettings?.command; const command = runtimeSettings?.command;
const run = async (
executable: string,
args: string[],
): Promise<{ stdout: string; stderr: string }> => {
try {
return await execCommand(executable, args, { timeout: 5_000 });
} catch (error) {
const err = error as { stdout?: string; stderr?: string; message?: string };
return {
stdout: err.stdout ?? "",
stderr: err.stderr ?? err.message ?? "",
};
}
};
try { try {
let result: { stdout: string; stderr: string };
if (command?.mode === "replace") { if (command?.mode === "replace") {
const { stdout } = await execCommand( result = await run(command.argv[0]!, [...command.argv.slice(1), "auth", "status"]);
command.argv[0]!, } else {
[...command.argv.slice(1), "auth", "status"], const executable = await findExecutable("claude");
{ timeout: 5_000 }, if (!executable) {
); return null;
return stdout.trim() || null; }
result = await run(executable, ["auth", "status"]);
} }
const executable = await findExecutable("claude"); const combined = [result.stdout, result.stderr]
if (!executable) { .map((s) => s.trim())
return null; .filter((s) => s.length > 0)
} .join("\n");
return combined || null;
const { stdout } = await execCommand(executable, ["auth", "status"], { timeout: 5_000 });
return stdout.trim() || null;
} catch { } catch {
return null; return null;
} }