Skip to content

fix(agent): support Claude Code OAuth subscription route - #16692

Closed
syx-labs wants to merge 1 commit into
NousResearch:mainfrom
syx-labs:fix/claude-code-oauth-subscription
Closed

fix(agent): support Claude Code OAuth subscription route#16692
syx-labs wants to merge 1 commit into
NousResearch:mainfrom
syx-labs:fix/claude-code-oauth-subscription

Conversation

@syx-labs

Copy link
Copy Markdown

Summary

  • Keep Claude Code OAuth requests using the Claude Code system identity while moving Hermes session instructions into the first user turn
  • Omit Hermes tool schemas/history on the subscription OAuth route, which currently rejects arbitrary tools with the misleading extra-usage error
  • Harden mocked/non-string Keychain payload handling in Anthropic credential tests

Test Plan

  • python -m py_compile agent/anthropic_adapter.py tests/agent/test_anthropic_adapter.py
  • python -m pytest tests/agent/test_anthropic_adapter.py -q
  • HOME=/Users/shadow XDG_CONFIG_HOME=/Users/shadow/.config hermes chat -q 'Responda apenas OK' --provider anthropic --model claude-opus-4-7

Notes

  • Branch was created from current origin/main to avoid including Gabriel-private Telegram Cockpit commits.

@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/anthropic Anthropic native Messages API area/auth Authentication, OAuth, credential pools labels Apr 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #10576 (sanitize OAuth system prompt for Claude Max proxy) and PR #13611 (move oversized OAuth system prompt to user prefix) — same OAuth/subscription route issue family.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jun 29, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for digging into this, @syx-labs — the diagnosis of the "out of extra usage" rejection on the Claude Code OAuth route was on the right track, and the keychain payload hardening was a thoughtful touch.

We're going to close this one, though, because the root cause has since been pinned down on main and fixed in a way that preserves tool use rather than disabling it.

Root cause (GH-25255): the subscription/OAuth billing classifier fingerprints the single-underscore mcp_ tool-name prefix as a third-party app and kicks the request into the extra-usage lane (HTTP 400). It isn't that arbitrary tools are rejected wholesale — it's specifically that prefix shape. The fix on main normalizes every tool name (bare Hermes tools and native mcp_<server>_<tool> names) to the double-underscore mcp__ form on the wire, which the classifier accepts and bills against the plan, then reverses the mapping in normalize_response so the dispatcher still sees the original name. Tools and full tool_use/tool_result history are preserved.

The approach in this PR — setting anthropic_tools = [] and scrubbing all tool history on the OAuth route — would disable agentic tool use entirely on Anthropic OAuth, which is the capability we specifically wanted to keep. The system-prompt relocation into a <session_instructions> user turn is also no longer needed: main keeps the Hermes system prompt in the API system field (after the Claude Code identity block) and just sanitizes product-name references.

Your code keeps your authorship in our review notes. Appreciate the contribution — closing as resolved-on-main.

@teknium1 teknium1 closed this Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/auth Authentication, OAuth, credential pools comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P1 High — major feature broken, no workaround provider/anthropic Anthropic native Messages API sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-caching Sweeper risk: may break/degrade prompt caching or cache-key stability (invariant) sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants