From 5383615db5483ca6d915ad4d5a8d7bc290b492b1 Mon Sep 17 00:00:00 2001 From: nightq Date: Wed, 15 Apr 2026 09:29:49 +0800 Subject: [PATCH] fix: recognize Claude Code OAuth tokens (cc- prefix) in _is_oauth_token Fixes NousResearch/hermes-agent#9813 Root cause: _is_oauth_token() only recognized sk-ant-* and eyJ* patterns, but Claude Code OAuth tokens from CLAUDE_CODE_OAUTH_TOKEN use cc- prefix Fix: Add cc- prefix detection so these tokens route through Bearer auth --- agent/anthropic_adapter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/agent/anthropic_adapter.py b/agent/anthropic_adapter.py index 05449e2a77..7a37fc4144 100644 --- a/agent/anthropic_adapter.py +++ b/agent/anthropic_adapter.py @@ -277,8 +277,9 @@ def _is_oauth_token(key: str) -> bool: Positively identifies Anthropic OAuth tokens by their key format: - ``sk-ant-`` prefix (but NOT ``sk-ant-api``) → setup tokens, managed keys - ``eyJ`` prefix → JWTs from the Anthropic OAuth flow + - ``cc-`` prefix → Claude Code OAuth access tokens (from CLAUDE_CODE_OAUTH_TOKEN) - Non-Anthropic keys (MiniMax, Alibaba, etc.) don't match either pattern + Non-Anthropic keys (MiniMax, Alibaba, etc.) don't match any pattern and correctly return False. """ if not key: @@ -292,6 +293,9 @@ def _is_oauth_token(key: str) -> bool: # JWTs from Anthropic OAuth flow if key.startswith("eyJ"): return True + # Claude Code OAuth access tokens (opaque, from CLAUDE_CODE_OAUTH_TOKEN) + if key.startswith("cc-"): + return True return False