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 { try {
if (command?.mode === "replace") { return await execCommand(executable, args, { timeout: 5_000 });
const { stdout } = await execCommand( } catch (error) {
command.argv[0]!, const err = error as { stdout?: string; stderr?: string; message?: string };
[...command.argv.slice(1), "auth", "status"], return {
{ timeout: 5_000 }, stdout: err.stdout ?? "",
); stderr: err.stderr ?? err.message ?? "",
return stdout.trim() || null; };
} }
};
try {
let result: { stdout: string; stderr: string };
if (command?.mode === "replace") {
result = await run(command.argv[0]!, [...command.argv.slice(1), "auth", "status"]);
} else {
const executable = await findExecutable("claude"); const executable = await findExecutable("claude");
if (!executable) { if (!executable) {
return null; return null;
} }
result = await run(executable, ["auth", "status"]);
}
const { stdout } = await execCommand(executable, ["auth", "status"], { timeout: 5_000 }); const combined = [result.stdout, result.stderr]
return stdout.trim() || null; .map((s) => s.trim())
.filter((s) => s.length > 0)
.join("\n");
return combined || null;
} catch { } catch {
return null; return null;
} }