Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
feat(backends): preload masked API key + show active auth mode
cyhd7b47f2de6e0
diff --git a/tests/test_api_key_masking.py b/tests/test_api_key_masking.pynew file mode 100644index 000000000..5bb3a09dd--- /dev/null+++ b/tests/test_api_key_masking.py@@ -0,0 +1,56 @@+"""Regression tests for the Settings → Backends API-key masker.++Pins the masked-preview format that the Codex and Claude provider pages+display in place of the stored API key. The full plaintext key must never+leak into the response; only the leading prefix (e.g. ``sk-proj-``,+``sk-ant-``) plus the trailing four characters survive the mask.+"""++from __future__ import annotations++from vibe.api import _mask_api_key+++def test_blank_or_none_returns_none() -> None:+ assert _mask_api_key(None) is None+ assert _mask_api_key("") is None+ assert _mask_api_key(" ") is None+++def test_codex_sk_proj_key_keeps_prefix_and_last4() -> None:+ result = _mask_api_key("sk-proj-aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456H8mN")+ assert result is not None+ assert result.startswith("sk-proj-")+ assert result.endswith("H8mN")+ # Body must be dots only (no plaintext middle).+ middle = result[len("sk-proj-") : -4]+ assert middle == "•" * 9+++def test_claude_sk_ant_key_keeps_prefix_and_last4() -> None:+ result = _mask_api_key("sk-ant-aBcDeFgHiJkLmNoPqRsTuVwXyZ0123456cd34")+ assert result is not None+ assert result.startswith("sk-ant-")+ assert result.endswith("cd34")+++def test_short_or_unstructured_key_falls_back_to_dots_plus_last4() -> None:+ assert _mask_api_key("abcd1234") == "••••••1234"+ assert _mask_api_key("plainstring") == "••••••ring"+++def test_whitespace_is_stripped() -> None:+ result = _mask_api_key(" sk-proj-foobarbaz12345abcd ")+ assert result is not None+ assert result.startswith("sk-proj-")+ assert result.endswith("abcd")+++def test_mask_never_leaks_plaintext_middle() -> None:+ """No matter the key, the response must not contain any non-prefix+ non-last4 characters of the input."""+ key = "sk-proj-MIDDLECONTENTTHATMUSTNOTLEAK7777"+ result = _mask_api_key(key)+ assert result is not None+ assert "MIDDLE" not in result+ assert "MUSTNOTLEAK" not in resultdiff --git a/ui/src/components/settings/SettingsClaudeProviderPage.tsx b/ui/src/components/settings/SettingsClaudeProviderPage.tsxindex 481651c18..18f7ea1af 100644--- a/ui/src/components/settings/SettingsClaudeProviderPage.tsx+++ b/ui/src/components/settings/SettingsClaudeProviderPage.tsx@@ -4,11 +4,13 @@ import { useTranslation } from 'react-i18next';import {AlertTriangle,ArrowLeft,+ CheckCircle2,ChevronDown,ChevronUp,Download,Info,KeyRound,+ Pencil,RefreshCw,RotateCcw,Save,@@ -17,6 +19,7 @@ import {} from 'lucide-react';import clsx from 'clsx';+import { Badge } from '../ui/badge';import { Button } from '../ui/button';import { Card, CardContent } from '../ui/card';import { Input } from '../ui/input';@@ -100,6 +103,10 @@ export const SettingsClaudeProviderPage: React.FC = () => {const [authSaving, setAuthSaving] = useState(false);const [authMode, setAuthMode] = useState<ClaudeAuthMode>('oauth');const [apiKey, setApiKey] = useState('');+ // ``editingKey`` mirrors the Codex page convention: false = show the+ // saved key as a read-only mask (``sk-ant-•••cd34``) with a pencil to+ // replace it; true = empty editable input ready for a fresh secret.+ const [editingKey, setEditingKey] = useState(false);const [baseUrl, setBaseUrl] = useState('');useEffect(() => {@@ -131,9 +138,10 @@ export const SettingsClaudeProviderPage: React.FC = () => {setAuthState(data);setAuthMode(data.auth_mode);setBaseUrl(data.base_url || '');- // Never preload api_key; only its length is returned. Empty input- // means "keep whatever is stored" on save.+ // The masked preview lives in ``authState.api_key_masked``;+ // ``apiKey`` stays empty until the user clicks "Replace".setApiKey('');+ setEditingKey(false);}).catch(() => {// ApiContext already toasted; leave the page on its defaults.@@ -245,6 +253,7 @@ export const SettingsClaudeProviderPage: React.FC = () => {setAuthMode(result.auth_mode);setBaseUrl(result.base_url || '');setApiKey('');+ setEditingKey(false);// Claude restart is synthetic (one-shot CLI) so result.restart.ok// is always true; treat any falsy state defensively just in case.if (result.restart?.ok === false) {@@ -433,9 +442,27 @@ export const SettingsClaudeProviderPage: React.FC = () => {<Card><CardContent className="flex flex-col gap-5 p-6"><div className="flex flex-col gap-2">- <Label className="text-xs font-medium uppercase text-muted">- {t('settings.backends.claudeAuthModeLabel')}- </Label>+ <div className="flex items-center justify-between gap-3">+ <Label className="text-xs font-medium uppercase text-muted">+ {t('settings.backends.claudeAuthModeLabel')}+ </Label>+ {authState?.active_auth_mode && authState.active_auth_mode !== 'none' && (+ <Badge+ variant={authState.active_auth_mode === 'oauth' ? 'success' : 'info'}+ className="font-mono uppercase tracking-[0.06em]"+ >+ <CheckCircle2 className="size-3" />+ {authState.active_auth_mode === 'oauth'+ ? t('settings.backends.activeAuthOauth')+ : t('settings.backends.activeAuthApiKey')}+ </Badge>+ )}+ {authState?.active_auth_mode === 'none' && (+ <Badge variant="secondary" className="font-mono uppercase tracking-[0.06em]">+ {t('settings.backends.activeAuthNone')}+ </Badge>+ )}+ </div><SegmentedRadiovalue={authMode}onChange={setAuthMode}@@ -452,12 +479,12 @@ export const SettingsClaudeProviderPage: React.FC = () => {{authMode === 'oauth' && (<BackendOAuthPanelbackend={BACKEND_ID}- // Claude OAuth credentials live in the keychain on Mac,- // ``~/.claude/credentials.json`` elsewhere — we don't probe- // either here. The panel always offers a Sign-in button;- // a successful in-session login flips the label to- // "Re-authenticate" via its own state.- signedIn={false}+ // ``has_oauth_credentials`` flips when ``~/.claude/credentials.json``+ // carries a usable token bundle — that's a real signal we can+ // trust on Linux/Docker. macOS keychain installs still report+ // false, but a successful in-session login flips the panel's+ // own state anyway.+ signedIn={!!authState?.has_oauth_credentials}title={t('settings.backends.claudeOauthPanelTitle')}subtitle={t('settings.backends.claudeOauthPanelSubtitle')}onSuccess={() => {@@ -484,21 +511,60 @@ export const SettingsClaudeProviderPage: React.FC = () => {<Label htmlFor="claude-api-key" className="text-xs font-medium uppercase text-muted">{t('settings.backends.claudeApiKeyLabel')}</Label>- <div className="relative">- <KeyRound className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted" />- <Input- id="claude-api-key"- type="password"- autoComplete="off"- spellCheck={false}- placeholder={t('settings.backends.claudeApiKeyPlaceholder') as string}- value={apiKey}- onChange={(e) => setApiKey(e.target.value)}- className="pl-9 font-mono"- disabled={authSaving}- />+ {authState?.has_api_key && !editingKey ? (+ // Same masked-preview affordance the Codex page uses;+ // keeps the user from re-typing the secret when they+ // are only changing the Base URL.+ <div className="flex items-center gap-2 rounded-md border border-border bg-foreground/[0.04] px-3 py-2">+ <KeyRound className="size-4 shrink-0 text-muted" />+ <code className="flex-1 truncate font-mono text-[13px] text-foreground">+ {authState.api_key_masked || '••••••••'}+ </code>+ <Button+ type="button"+ variant="ghost"+ size="xs"+ onClick={() => {+ setEditingKey(true);+ setApiKey('');+ }}+ >+ <Pencil className="size-3" />+ {t('settings.backends.replaceApiKey')}+ </Button>+ </div>+ ) : (+ <div className="relative">+ <KeyRound className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted" />+ <Input+ id="claude-api-key"+ type="password"+ autoComplete="off"+ spellCheck={false}+ placeholder={t('settings.backends.claudeApiKeyPlaceholder') as string}+ value={apiKey}+ onChange={(e) => setApiKey(e.target.value)}+ className="pl-9 font-mono"+ disabled={authSaving}+ autoFocus={editingKey}+ />+ </div>+ )}+ <div className="flex items-center justify-between gap-2">+ <p className="text-[12px] text-muted">{apiKeyStatus}</p>+ {authState?.has_api_key && editingKey && (+ <button+ type="button"+ className="text-[12px] text-muted underline-offset-2 transition hover:text-foreground hover:underline"+ onClick={() => {+ setEditingKey(false);+ setApiKey('');+ }}+ >+ {t('common.cancel')}+ </button>+ )}</div>- <p className="text-[12px] text-muted">{apiKeyStatus}</p></div><div className="flex flex-col gap-2">diff --git a/ui/src/components/settings/SettingsCodexProviderPage.tsx b/ui/src/components/settings/SettingsCodexProviderPage.tsxindex affe05c3b..4c2ca01ae 100644--- a/ui/src/components/settings/SettingsCodexProviderPage.tsx+++ b/ui/src/components/settings/SettingsCodexProviderPage.tsx@@ -1,9 +1,10 @@import React, { useEffect, useMemo, useState } from 'react';import { Link } from 'react-router-dom';-import { ArrowLeft, Info, KeyRound, RotateCcw, Save } from 'lucide-react';+import { ArrowLeft, CheckCircle2, Info, KeyRound, Pencil, RotateCcw, Save } from 'lucide-react';import { useTranslation } from 'react-i18next';import clsx from 'clsx';+import { Badge } from '../ui/badge';import { Button } from '../ui/button';import { Card, CardContent } from '../ui/card';import { Input } from '../ui/input';@@ -61,6 +62,11 @@ export const SettingsCodexProviderPage: React.FC = () => {const [saving, setSaving] = useState(false);const [authMode, setAuthMode] = useState<CodexAuthMode>('oauth');const [apiKey, setApiKey] = useState('');+ // ``editingKey`` distinguishes "showing the saved masked key" (false,+ // input is read-only and pre-filled with ``api_key_masked``) from "user+ // is typing a fresh secret" (true, input is editable + empty). The+ // pencil button flips it on; saving or reloading flips it back off.+ const [editingKey, setEditingKey] = useState(false);const [baseUrl, setBaseUrl] = useState('');useEffect(() => {@@ -72,10 +78,10 @@ export const SettingsCodexProviderPage: React.FC = () => {setState(data);setAuthMode(data.auth_mode);setBaseUrl(data.base_url || '');- // Never preload the api_key field: the server only returns its- // length, and an empty input here is interpreted as "keep what's- // stored" on save unless the user types a fresh value.+ // Empty + read-only input + masked preview rendered separately+ // (see below) reflects the saved state without leaking plaintext.setApiKey('');+ setEditingKey(false);}).catch(() => {// Errors are already surfaced via ToastContext by ApiContext;@@ -134,6 +140,7 @@ export const SettingsCodexProviderPage: React.FC = () => {setAuthMode(result.auth_mode);setBaseUrl(result.base_url || '');setApiKey('');+ setEditingKey(false);if (result.restart?.ok === false) {// Config saved, restart failed — make the partial success visible.showToast(result.restart.message || result.message || t('settings.backends.codexSaveSuccess'), 'warning');@@ -165,9 +172,27 @@ export const SettingsCodexProviderPage: React.FC = () => {<Card><CardContent className="flex flex-col gap-5 p-6"><div className="flex flex-col gap-2">- <Label className="text-xs font-medium uppercase text-muted">- {t('settings.backends.codexAuthModeLabel')}- </Label>+ <div className="flex items-center justify-between gap-3">+ <Label className="text-xs font-medium uppercase text-muted">+ {t('settings.backends.codexAuthModeLabel')}+ </Label>+ {state?.active_auth_mode && state.active_auth_mode !== 'none' && (+ <Badge+ variant={state.active_auth_mode === 'oauth' ? 'success' : 'info'}+ className="font-mono uppercase tracking-[0.06em]"+ >+ <CheckCircle2 className="size-3" />+ {state.active_auth_mode === 'oauth'+ ? t('settings.backends.activeAuthOauth')+ : t('settings.backends.activeAuthApiKey')}+ </Badge>+ )}+ {state?.active_auth_mode === 'none' && (+ <Badge variant="secondary" className="font-mono uppercase tracking-[0.06em]">+ {t('settings.backends.activeAuthNone')}+ </Badge>+ )}+ </div><SegmentedRadiovalue={authMode}onChange={setAuthMode}@@ -230,20 +255,61 @@ export const SettingsCodexProviderPage: React.FC = () => {<Label htmlFor="codex-api-key" className="text-xs font-medium uppercase text-muted">{t('settings.backends.codexApiKeyLabel')}</Label>- <div className="relative">- <KeyRound className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted" />- <Input- id="codex-api-key"- type="password"- autoComplete="off"- spellCheck={false}- placeholder={t('settings.backends.codexApiKeyPlaceholder') as string}- value={apiKey}- onChange={(e) => setApiKey(e.target.value)}- className="pl-9 font-mono"- />+ {state?.has_api_key && !editingKey ? (+ // Saved-key preview: render the server-masked value+ // (``sk-proj-•••H8mN``) read-only with a pencil to swap+ // in a fresh key. Same affordance shown in design.pen+ // ``cxApiVal`` — saves the user from typing the secret+ // again when they only want to change the Base URL.+ <div className="flex items-center gap-2 rounded-md border border-border bg-foreground/[0.04] px-3 py-2">+ <KeyRound className="size-4 shrink-0 text-muted" />+ <code className="flex-1 truncate font-mono text-[13px] text-foreground">+ {state.api_key_masked || '••••••••'}+ </code>+ <Button+ type="button"+ variant="ghost"+ size="xs"+ onClick={() => {+ setEditingKey(true);+ setApiKey('');+ }}+ >+ <Pencil className="size-3" />+ {t('settings.backends.replaceApiKey')}+ </Button>+ </div>+ ) : (+ <div className="relative">+ <KeyRound className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted" />+ <Input+ id="codex-api-key"+ type="password"+ autoComplete="off"+ spellCheck={false}+ placeholder={t('settings.backends.codexApiKeyPlaceholder') as string}+ value={apiKey}+ onChange={(e) => setApiKey(e.target.value)}+ className="pl-9 font-mono"+ autoFocus={editingKey}+ />+ </div>+ )}+ <div className="flex items-center justify-between gap-2">+ <p className="text-[12px] text-muted">{apiKeyStatus}</p>+ {state?.has_api_key && editingKey && (+ <button+ type="button"+ className="text-[12px] text-muted underline-offset-2 transition hover:text-foreground hover:underline"+ onClick={() => {+ setEditingKey(false);+ setApiKey('');+ }}+ >+ {t('common.cancel')}+ </button>+ )}</div>- <p className="text-[12px] text-muted">{apiKeyStatus}</p></div><div className="flex flex-col gap-2">diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsxindex 24c18f768..47b20e24f 100644--- a/ui/src/context/ApiContext.tsx+++ b/ui/src/context/ApiContext.tsx@@ -148,11 +148,22 @@ export type CodexAuthMode = 'oauth' | 'api_key';// as "no key configured" in that case.export type CodexCredentialsStore = 'file' | 'keyring' | 'auto' | (string & {});+export type ActiveAuthMode = 'oauth' | 'api_key' | 'none';+export type CodexAuthState = {ok: boolean;auth_mode: CodexAuthMode;+ // What the running Codex CLI is actually using at launch — separate+ // from ``auth_mode`` which is the user's saved intent. Lets the UI+ // surface "Currently active: …" so the two-radio choice is no longer+ // ambiguous about which mode is live.+ active_auth_mode: ActiveAuthMode;has_api_key: boolean;api_key_length: number;+ // Server-masked preview (e.g. ``sk-proj-•••••••••H8mN``). Used to+ // pre-fill the API Key input so the page reflects the saved state+ // instead of looking empty. Plaintext keys never leave the server.+ api_key_masked: string | null;base_url: string | null;has_chatgpt_tokens: boolean;credentials_store: CodexCredentialsStore;@@ -187,8 +198,14 @@ export type ClaudeAuthMode = 'oauth' | 'api_key';export type ClaudeAuthState = {ok: boolean;auth_mode: ClaudeAuthMode;+ // Live source the CLI is actually inheriting at launch (api_key when+ // V2Config injects ``ANTHROPIC_API_KEY`` and strips OAuth env vars,+ // oauth when ``~/.claude/credentials.json`` has a usable token).+ active_auth_mode: ActiveAuthMode;has_api_key: boolean;api_key_length: number;+ api_key_masked: string | null;+ has_oauth_credentials: boolean;base_url: string | null;settings_path: string | null;settings_exists: boolean;diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex e62fc0b6d..5ecb911eb 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -188,6 +188,10 @@"testConnectionLastFail": "Last run failed: {{detail}}","testConnectionSuccessToast": "Backend reachable · {{ms}} ms","testConnectionFailedToast": "Backend test failed: {{detail}}",+ "activeAuthOauth": "Active: OAuth",+ "activeAuthApiKey": "Active: API Key",+ "activeAuthNone": "Not signed in",+ "replaceApiKey": "Replace","opencodeProvidersTitle": "Providers","opencodeProvidersSubtitle": "Lazy-loaded from the OpenCode server · auth handled via API key or `opencode auth login`","opencodeProvidersCount": "{{configured}}/{{total}} configured",diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex 6a392a67b..52b9061a5 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -188,6 +188,10 @@"testConnectionLastFail": "上次失败:{{detail}}","testConnectionSuccessToast": "后端可达 · {{ms}} ms","testConnectionFailedToast": "后端测试失败:{{detail}}",+ "activeAuthOauth": "当前:OAuth",+ "activeAuthApiKey": "当前:API Key",+ "activeAuthNone": "未登录",+ "replaceApiKey": "替换","opencodeProvidersTitle": "服务商","opencodeProvidersSubtitle": "从 OpenCode Server 实时拉取 · 通过 API Key 或 `opencode auth login` 完成授权","opencodeProvidersCount": "已配置 {{configured}}/{{total}}",diff --git a/vibe/api.py b/vibe/api.pyindex e79193c6a..2dfc94951 100644--- a/vibe/api.py+++ b/vibe/api.py@@ -2060,6 +2060,30 @@ def restart_backend(name: str) -> dict:_VALID_AUTH_MODES = {"oauth", "api_key"}+def _mask_api_key(api_key: str | None) -> str | None:+ """Return a UI-safe preview of an API key.++ Pattern: keep the prefix up to (and including) the first ``-`` block+ (e.g. ``sk-proj-``, ``sk-ant-``) so the user can still recognize+ the key type, then dots, then the last 4 characters. Short keys+ (<= 12 chars) get a uniform 6-dots-plus-last-4 pattern so we never+ accidentally render plaintext for a malformed key.+ """+ if not isinstance(api_key, str) or not api_key.strip():+ return None+ key = api_key.strip()+ last4 = key[-4:]+ if len(key) > 12 and "-" in key:+ # Take the recognizable prefix up to and including the second dash+ # (handles both ``sk-...`` and ``sk-proj-...`` shapes).+ first_dash = key.find("-")+ second_dash = key.find("-", first_dash + 1)+ prefix_end = second_dash + 1 if second_dash != -1 else first_dash + 1+ prefix = key[:prefix_end]+ return f"{prefix}{'•' * 9}{last4}"+ return f"{'•' * 6}{last4}"++# ---------------------------------------------------------------------------# Web Settings → Backends OAuth flow plumbing#@@ -2287,13 +2311,29 @@ def get_codex_auth() -> dict:auth_mode = configured_modeelse:auth_mode = disk_state.get("auth_mode")+ # The *active* auth source the running Codex CLI uses at launch is+ # determined entirely by ``~/.codex/auth.json``: a stored API key wins;+ # else ChatGPT tokens; else "not configured". This is what the user+ # cares about ("which one is actually working"), separate from the+ # ``auth_mode`` field above (which is the *intent* we'd save next).+ has_api_key_live = bool(disk_state.get("has_api_key"))+ has_chatgpt_live = bool(disk_state.get("has_chatgpt_tokens"))+ if has_api_key_live:+ active_auth_mode = "api_key"+ elif has_chatgpt_live:+ active_auth_mode = "oauth"+ else:+ active_auth_mode = "none"+return {"ok": True,"auth_mode": auth_mode or "oauth",- "has_api_key": bool(disk_state.get("has_api_key")),+ "active_auth_mode": active_auth_mode,+ "has_api_key": has_api_key_live,"api_key_length": int(disk_state.get("api_key_length") or 0),+ "api_key_masked": _mask_api_key(disk_state.get("api_key_raw")),"base_url": disk_state.get("base_url"),- "has_chatgpt_tokens": bool(disk_state.get("has_chatgpt_tokens")),+ "has_chatgpt_tokens": has_chatgpt_live,# Forward the live Codex credentials-store status so the UI can# warn when the user is about to switch storage backends# (Codex's documented default is ``auto`` → keyring-preferred).@@ -2443,9 +2483,10 @@ def get_claude_auth() -> dict:env). The UI surfaces a warning so users aren't confused by stalekeys silently overriding what they just saved."""- from vibe.claude_config import read_claude_auth_state+ from vibe.claude_config import read_claude_auth_state, read_claude_oauth_signed_indisk_state = read_claude_auth_state()+ oauth_signed_in = read_claude_oauth_signed_in()try:config = load_config()cfg = getattr(getattr(config, "agents", None), "claude", None)@@ -2472,11 +2513,32 @@ def get_claude_auth() -> dict:# in effect.settings_conflict = bool(disk_state.get("settings_env_has_key")) and has_api_key+ # ``active_auth_mode`` reflects what the running CLI is actually using+ # at launch — separate from ``auth_mode`` (the user's saved intent).+ # V2Config drives ``build_claude_subprocess_env``: api_key mode injects+ # ``ANTHROPIC_API_KEY`` and strips OAuth-related env vars; oauth mode+ # leaves those keys alone and relies on ``~/.claude/credentials.json``+ # / the OS keychain. So in api_key mode the key wins; in oauth mode+ # the credentials file is what counts.+ if auth_mode == "api_key" and has_api_key:+ active_auth_mode = "api_key"+ elif auth_mode == "oauth" and oauth_signed_in:+ active_auth_mode = "oauth"+ elif has_api_key:+ active_auth_mode = "api_key"+ elif oauth_signed_in:+ active_auth_mode = "oauth"+ else:+ active_auth_mode = "none"+return {"ok": True,"auth_mode": auth_mode,+ "active_auth_mode": active_auth_mode,"has_api_key": has_api_key,"api_key_length": len(configured_key),+ "api_key_masked": _mask_api_key(configured_key),+ "has_oauth_credentials": oauth_signed_in,"base_url": configured_base or None,"settings_path": disk_state.get("settings_path"),"settings_exists": bool(disk_state.get("settings_exists")),diff --git a/vibe/claude_config.py b/vibe/claude_config.pyindex 6c9b070b3..f1c249ec4 100644--- a/vibe/claude_config.py+++ b/vibe/claude_config.py@@ -69,6 +69,49 @@ def get_claude_settings_path(home: Path | None = None) -> Path:return get_claude_home(home) / "settings.json"+def get_claude_credentials_path(home: Path | None = None) -> Path:+ """Return the absolute path to ``~/.claude/credentials.json``.++ The Claude CLI writes OAuth tokens here on platforms that lack a+ usable keychain (notably Linux/Docker, including the regression+ container). The Settings UI uses presence + a token field as a+ best-effort signal for "Claude is signed in via OAuth" since the+ macOS keychain is not portably introspectable.+ """+ return get_claude_home(home) / "credentials.json"+++def read_claude_oauth_signed_in(home: Path | None = None) -> bool:+ """Best-effort probe for whether Claude has a usable OAuth session.++ True iff ``~/.claude/credentials.json`` exists and carries something+ that looks like an OAuth token bundle. We don't attempt to introspect+ keychain-backed installs (macOS) — those return False here but the UI+ can still light up the OAuth banner after a successful in-app login.+ """+ path = get_claude_credentials_path(home)+ if not path.exists():+ return False+ try:+ data = json.loads(path.read_text(encoding="utf-8"))+ except (OSError, json.JSONDecodeError):+ return False+ if not isinstance(data, dict):+ return False+ # Claude writes nested ``claudeAiOauth`` payloads in newer builds; flat+ # ``access_token``/``refresh_token`` keys also occur. Accept either.+ nested = data.get("claudeAiOauth") if isinstance(data.get("claudeAiOauth"), dict) else None+ if nested and any(+ isinstance(nested.get(field), str) and nested.get(field)+ for field in ("access_token", "refresh_token", "accessToken", "refreshToken")+ ):+ return True+ for field in ("access_token", "refresh_token", "accessToken", "refreshToken"):+ if isinstance(data.get(field), str) and data.get(field):+ return True+ return False++def _load_settings(path: Path) -> Dict[str, Any]:if not path.exists():return {}diff --git a/vibe/codex_config.py b/vibe/codex_config.pyindex 9082b1ace..45d9e1678 100644--- a/vibe/codex_config.py+++ b/vibe/codex_config.py@@ -401,6 +401,10 @@ def read_codex_auth_state(home: Path | None = None) -> Dict[str, Any]:"auth_mode": inferred_mode,"has_api_key": isinstance(api_key, str) and bool(api_key),"api_key_length": len(api_key) if isinstance(api_key, str) else 0,+ # Plaintext API key — only consumed by ``vibe.api.get_codex_auth``+ # which masks it before returning to the UI. Never serialized to+ # JSON directly.+ "api_key_raw": api_key if isinstance(api_key, str) and api_key else None,"base_url": base_url,"has_chatgpt_tokens": has_chatgpt_tokens,"credentials_store": effective_store,