Skip to content

The agent that grows with you

fix(inventory): keep Anthropic OAuth logins visible in desktop pickers

Viktor4ec57d56a941
diff --git a/hermes_cli/inventory.py b/hermes_cli/inventory.py
index bce98ef1e6b..094a66a62db 100644
--- a/hermes_cli/inventory.py
+++ b/hermes_cli/inventory.py
@@ -661,6 +661,33 @@ def _append_unconfigured_rows(
return extras
+def _anthropic_oauth_credentials_present() -> bool:
+ """True when the user explicitly authenticated Anthropic via OAuth.
+
+ Two deliberate flows leave no trace in active_provider /
+ model.provider / API-key env vars: Hermes' own Anthropic device flow
+ (token in auth.json) and a Claude Code login (~/.claude/.credentials.json).
+ ``list_authenticated_providers`` already accepts both readers as real
+ credentials when discovering rows; this mirrors that acceptance so the
+ desktop explicit-only filter does not silently drop a provider the user
+ deliberately signed into. Unlike ambient CLI tokens (gh -> copilot),
+ an OAuth access token only exists after an interactive login.
+ """
+ try:
+ from agent.anthropic_adapter import (
+ read_claude_code_credentials,
+ read_hermes_oauth_credentials,
+ )
+
+ hermes_creds = read_hermes_oauth_credentials() or {}
+ if hermes_creds.get("accessToken"):
+ return True
+ cc_creds = read_claude_code_credentials() or {}
+ return bool(cc_creds.get("accessToken"))
+ except Exception:
+ return False
+
+
def _filter_explicit_provider_rows(rows: list[dict], ctx: ConfigContext) -> list[dict]:
"""Keep only rows backed by explicit user configuration.
@@ -697,6 +724,14 @@ def _filter_explicit_provider_rows(rows: list[dict], ctx: ConfigContext) -> list
# them would defeat their purpose (zero-setup discoverability).
kept.append(row)
continue
+ if slug == "anthropic" and _anthropic_oauth_credentials_present():
+ # Anthropic OAuth logins (Hermes device flow / Claude Code) are
+ # deliberate sign-ins that leave no trace in active_provider,
+ # model.provider, or API-key env vars. The strict gate below
+ # would drop the row even though list_authenticated_providers
+ # just accepted those same credentials when building it.
+ kept.append(row)
+ continue
if is_provider_explicitly_configured(slug):
kept.append(row)
return kept
diff --git a/tests/hermes_cli/test_inventory.py b/tests/hermes_cli/test_inventory.py
index 92ee4beafee..7b4ff6e575c 100644
--- a/tests/hermes_cli/test_inventory.py
+++ b/tests/hermes_cli/test_inventory.py
@@ -208,6 +208,72 @@ def test_explicit_only_filters_ambient_credentials_but_keeps_current_and_custom_
]
+def test_explicit_only_keeps_anthropic_row_with_oauth_credentials():
+ """Anthropic OAuth logins are deliberate sign-ins, not ambient credentials.
+
+ Claude Code (~/.claude/.credentials.json) and Hermes' own device flow
+ leave no trace in active_provider / model.provider / API-key env vars,
+ so is_provider_explicitly_configured() returns False even though
+ list_authenticated_providers just accepted those same credentials when
+ building the row. The desktop explicit-only filter must keep it.
+ """
+ rows = [
+ {"slug": "anthropic", "name": "Anthropic", "models": ["claude-sonnet-5"],
+ "total_models": 1, "is_current": False, "is_user_defined": False,
+ "source": "hermes"},
+ {"slug": "copilot", "name": "Copilot", "models": ["gpt-5.4"],
+ "total_models": 1, "is_current": False, "is_user_defined": False,
+ "source": "hermes"},
+ ]
+ ctx = _empty_ctx(provider="opencode-go", model="glm-5.3")
+ with (
+ _list_auth_returning(rows),
+ patch("hermes_cli.config.read_raw_config", return_value={}),
+ patch(
+ "hermes_cli.auth.is_provider_explicitly_configured",
+ return_value=False,
+ ),
+ patch(
+ "hermes_cli.inventory._anthropic_oauth_credentials_present",
+ return_value=True,
+ ),
+ ):
+ payload = build_models_payload(ctx, explicit_only=True)
+
+ slugs = [row["slug"] for row in payload["providers"]]
+ assert "anthropic" in slugs, (
+ "Anthropic OAuth login must survive the explicit-only filter"
+ )
+ assert "copilot" not in slugs, (
+ "ambient credential discovery must stay filtered"
+ )
+
+
+def test_explicit_only_drops_anthropic_row_without_oauth_credentials():
+ """No OAuth token and no explicit config -> Anthropic stays hidden."""
+ rows = [
+ {"slug": "anthropic", "name": "Anthropic", "models": ["claude-sonnet-5"],
+ "total_models": 1, "is_current": False, "is_user_defined": False,
+ "source": "hermes"},
+ ]
+ ctx = _empty_ctx(provider="opencode-go", model="glm-5.3")
+ with (
+ _list_auth_returning(rows),
+ patch("hermes_cli.config.read_raw_config", return_value={}),
+ patch(
+ "hermes_cli.auth.is_provider_explicitly_configured",
+ return_value=False,
+ ),
+ patch(
+ "hermes_cli.inventory._anthropic_oauth_credentials_present",
+ return_value=False,
+ ),
+ ):
+ payload = build_models_payload(ctx, explicit_only=True)
+
+ assert "anthropic" not in [row["slug"] for row in payload["providers"]]
+
+
# ─── picker_hints ──────────────────────────────────────────────────────