Files
openclaw/extensions/anthropic/cli-auth-seam.ts
Ayaan Zaidi 750a64e7cd fix(anthropic): keep Claude CLI authentication native (#129052)
Stop OpenClaw from copying or refreshing Claude CLI OAuth tokens.
Claude CLI now owns native login and refresh state; Doctor removes retired copies while preserving CLI routing.

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
2026-08-25 17:18:06 +05:30

34 lines
1.0 KiB
TypeScript

import { spawnSync } from "node:child_process";
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
type ClaudeCliAuthStatus = { status: "available" } | { status: "missing" | "unreadable" };
/** Ask Claude CLI whether its own login is usable without reading token material. */
export function probeClaudeCliAuthStatus(params?: {
command?: string;
env?: NodeJS.ProcessEnv;
}): ClaudeCliAuthStatus {
const result = spawnSync(params?.command ?? "claude", ["auth", "status", "--json"], {
encoding: "utf8",
env: params?.env ?? process.env,
maxBuffer: 64 * 1024,
timeout: 3_000,
windowsHide: true,
});
if (result.error || result.status === null) {
return { status: "unreadable" };
}
if (result.status !== 0) {
return { status: "missing" };
}
try {
const parsed: unknown = JSON.parse(result.stdout);
if (!isRecord(parsed) || parsed.loggedIn !== true) {
return { status: "missing" };
}
return { status: "available" };
} catch {
return { status: "unreadable" };
}
}