From 3de186831388bab4c113e6a2ee1066759982e17e Mon Sep 17 00:00:00 2001 From: dtzp555 Date: Wed, 25 Mar 2026 20:42:16 +1000 Subject: [PATCH] fix: read OAuth token from Linux credentials file as fallback On Linux (no macOS keychain), read ~/.claude/.credentials.json first. Falls through to macOS keychain if file not found. Fixes /ocp usage showing "No OAuth token" on Linux servers and RPi. Co-Authored-By: Claude Opus 4.6 (1M context) --- server.mjs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server.mjs b/server.mjs index 354ebf1..7b885f8 100644 --- a/server.mjs +++ b/server.mjs @@ -43,6 +43,7 @@ import { randomUUID, timingSafeEqual } from "node:crypto"; import { readFileSync, accessSync, constants } from "node:fs"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; +import { homedir } from "node:os"; const __dirname = dirname(fileURLToPath(import.meta.url)); const _pkg = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8")); @@ -687,6 +688,15 @@ let usageCache = { data: null, fetchedAt: 0 }; const USAGE_CACHE_TTL = 300000; // 5 min function getOAuthToken() { + // Try Linux file-based credentials first + try { + const credPath = join(homedir(), ".claude", ".credentials.json"); + const creds = JSON.parse(readFileSync(credPath, "utf8")); + const token = creds?.claudeAiOauth?.accessToken; + if (token) return token; + } catch { /* fall through to macOS keychain */ } + + // Try macOS keychain try { const raw = execFileSync("security", [ "find-generic-password", "-s", "Claude Code-credentials", "-w"