Skip to content

feat(providers): Claude subscription support via the official Agent SDK - #80469

Closed
Zeus-Deus wants to merge 1 commit into
NousResearch:mainfrom
Zeus-Deus:t3code/add-claude-subscription-support
Closed

Zeus-Deus wants to merge 1 commit into
NousResearch:mainfrom
Zeus-Deus:t3code/add-claude-subscription-support

Conversation

@Zeus-Deus

@Zeus-Deus Zeus-Deus commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a new Claude subscription (Agent SDK) provider (claude-code, api_mode=claude_agent_sdk) that runs whole turns through Anthropic's official claude-agent-sdk. Users sign in with claude auth login; turns draw on their Claude Pro/Max/Team plan instead of the extra-usage pool.

The existing anthropic API-key provider is unchanged, and the current direct-OAuth path keeps working. Nothing is migrated automatically — users on the old path get a one-time notice explaining the two options.

Why

Today's claude-code alias reads Claude Code's credential store and hand-builds /v1/messages requests with Claude Code identity headers. Anthropic's billing classifier routes that to the plan's extra-usage pool (empty by default), which is the recurring "out of extra usage" complaint. Routing turns through the official SDK — the same integration shape as T3 Code and Codemux — bills the plan itself.

Design

  • Hermes keeps tools, approvals, guardrails, checkpoints, environments, memory, skills, and session history; the SDK keeps Claude's context, prompt cache, and compaction. Claude's tool calls come back over an in-process MCP bridge into execute_one_tool(), which mirrors the per-tool lifecycle of Hermes' own dispatchers (approvals, guardrails, checkpoints, environment routing, hooks).
  • Billing safety: a sanitized subprocess transport strips every higher-precedence credential (options.env can override but never delete), preflight refuses any turn that would not bill the plan (naming the offending variable), and a zero-cost init probe verifies the billing source per session. Auxiliary/side-LLM calls use the same transport and guard.
  • Durable sessions: DB-backed SessionStore mirror (the SDK's own conformance suite passes), restart resume, rewind/branch as SDK forks, stale-session recovery.
  • Ships default-off behind claude_subscription.enabled — Anthropic's Agent SDK docs and Help Center currently disagree on third-party subscription use, so enablement is an explicit user choice. Full decision record in docs/design/claude-subscription-via-agent-sdk.md.
  • New CI: a boundary checker forbidding Claude-credential access and Claude Code impersonation (legacy path allow-listed until retirement), and an integration job that installs the real SDK.

Testing

  • ~600 targeted tests, green with and without the optional claude-agent-sdk extra installed; full suites unaffected.
  • Live verification in unprivileged containers (--cap-drop=ALL, non-root) on a consenting maintainer account: billing proven by falsification — with a deliberately invalid ANTHROPIC_API_KEY in the environment, a turn through this runtime succeeds (plan credential) while the same turn without sanitization fails; the CLI does not fall back from a bad key.
  • Clean-container E2E of a fresh pip install -e '.[claude-code]': chat, tool calls through the bridge, terminal, context continuity, and restart resume (same SDK session id after a new process). Also exercised against SDK 0.2.131 to confirm the range pin at the time; after the rebase the floor is 0.2.140, the first release whose mcp range admits the mcp==2.0.0 main pins.
  • Interactive TUI testing on a real Max subscription: multi-turn, model switching via set_model (context preserved), tool execution, session persistence.

Notes for review

  • The legacy path's spoofing/credential code is deliberately not removed — it is what current users run, and it is allow-listed in the boundary checker under TODO(legacy-retirement) markers for removal after enablement and migration.
  • pyproject.toml adds claude-code as an opt-in extra (the SDK wheels are ~80 MB; deliberately not in [all]). uv.lock regenerated.

🤖 Generated with Claude Code

@Zeus-Deus
Zeus-Deus requested a review from a team August 6, 2026 16:38
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/acp Agent Communication Protocol adapter comp/desktop Electron desktop app (apps/desktop/*) comp/plugins Plugin system and bundled plugins tool/delegate Subagent delegation provider/anthropic Anthropic native Messages API area/auth Authentication, OAuth, credential pools area/billing Account usage, credit usage, billing (cross-cutting) needs-decision Awaiting maintainer decision before any implementation sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-automation Sweeper risk: may affect CI, automerge, label sync, or maintainer automation labels Aug 6, 2026
@Zeus-Deus
Zeus-Deus force-pushed the t3code/add-claude-subscription-support branch from 330a533 to e48cd3c Compare August 26, 2026 17:19
Adds a new 'claude-code' provider (api_mode=claude_agent_sdk) that runs
whole turns through Anthropic's claude-agent-sdk, so a Claude Pro/Max/Team
subscription is billed to the user's plan instead of the extra-usage pool.
The existing 'anthropic' API-key provider is unchanged and the current
direct-OAuth path keeps working; nothing is migrated automatically.

Highlights:
- New whole-turn runtime beside the codex one: sync facade over the async
  SDK client, event projector to the canonical Hermes callbacks, in-process
  MCP bridge routing every tool call through the one canonical
  execute_one_tool() lifecycle (approvals, guardrails, checkpoints,
  environments all preserved).
- Billing safety: a sanitized subprocess transport strips every
  higher-precedence credential (options.env can override but never delete),
  a static+dynamic preflight refuses to start a turn that would not bill
  the plan, and a zero-cost init probe verifies the billing source per
  session. Auxiliary (side-LLM) calls go through the same transport+guard.
- Durable sessions: DB-backed SessionStore mirror (SDK conformance suite
  passes), Hermes<->SDK session binding, restart resume, rewind/branch via
  SDK forks, stale-session recovery.
- System prompt: claude_code preset + Hermes' own identity section
  (SOUL.md or DEFAULT_AGENT_IDENTITY) + a factual tool-routing note;
  the full Hermes prompt rides the first user turn. Measured against the
  live billing classifier: preset replacement or a full-prompt append is
  billed to extra usage.
- Ships default-off behind claude_subscription.enabled pending Anthropic
  policy clarification (see docs/design/claude-subscription-via-agent-sdk.md).
- CI: claude-boundary checker forbidding credential access and Claude Code
  impersonation, plus an integration job that installs the real SDK and
  runs the gated tests.

Rebase notes (2026-08-26, onto main @ 5538bd1):
- agent/tool_executor.py: main's two dispatchers are kept as they are on
  main; execute_one_tool()/finalize_tool_outcome() are re-ported onto
  main's middleware (five-field managed result, dispatched-aware terminal
  post_tool_call rule, tool_call_id-aware guardrail observation) as the
  entry point for the Agent SDK bridge, instead of re-routing the batch
  paths through the funnel.
- claude-agent-sdk floor 0.2.128 -> 0.2.140: main pins mcp==2.0.0 and
  0.2.140 is the first SDK release whose mcp range admits 2.x. A dated
  exclude-newer exception (remove after 2026-09-01) lets uv see it.
- hermes_state.py: the provider rewind-boundary note now runs inside
  main's single-transaction rewind body.
- hermes_cli/models.py keeps main's provider labels.
- scripts/check_claude_boundary.py allow-lists hermes_cli/inventory.py
  (docstring mention of the legacy Claude Code credential file, added
  on main).
- tests: the lifecycle test patches _dispatch_pre_tool_call_hooks (main's
  single pre_tool_call entry point) and honours
  suppress_post_tool_call_hook; the delegate test uses non-placeholder
  goals (main's batch quality gate).
- tests made hermetic against the host's Claude setup: the runtime turn
  tests stub verify_claude_billing_for_agent (the per-session CLI probe)
  and the auxiliary routing fixture pretends the claude CLI resolves —
  both had only passed on machines with a signed-in Claude Code.
- lint.yml "Claude Agent SDK integration": install from uv.lock
  (--extra dev --extra claude-code) instead of pip-installing the SDK
  alone; main's agent.display now imports the yaml-backed utils module.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Zeus-Deus
Zeus-Deus force-pushed the t3code/add-claude-subscription-support branch from e48cd3c to 9326a55 Compare August 26, 2026 17:52
@Zeus-Deus

Copy link
Copy Markdown
Contributor Author

Closing this in favour of the official route that landed since: the core seams in #117451 plus the claude-subscription-directsdk plugin (NousResearch/hermes-plugin-claude-subscription-directsdk, listed in the catalog via #117622). It covers the same use case, a Claude Pro/Max subscription through the official Claude Code/Agent SDK path, as an out-of-tree provider, which is a cleaner fit than the in-core approach here. I'm using it day to day. Thanks to everyone who reviewed and tested this. If anything from this branch is still missing in the plugin, I'll raise it there as a focused issue or PR.

@Zeus-Deus Zeus-Deus closed this Sep 28, 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 area/billing Account usage, credit usage, billing (cross-cutting) comp/acp Agent Communication Protocol adapter comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/desktop Electron desktop app (apps/desktop/*) comp/plugins Plugin system and bundled plugins needs-decision Awaiting maintainer decision before any implementation P3 Low — cosmetic, nice to have provider/anthropic Anthropic native Messages API sweeper:risk-automation Sweeper risk: may affect CI, automerge, label sync, or maintainer automation sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/delegate Subagent delegation type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants