feat: Claude subscription support through a Claude Agent provider
Issue for this PR
No issue. Ports upstream opencode PR 58782, "feat(core): add Claude Agent provider".
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Lets a user chat with Claude models on their Claude Pro/Max subscription. The CLI starts the user's installed claude through Anthropic's Claude Agent SDK, so the login stays with Claude Code. The CLI never reads or stores its token. Setup is claude auth login, then /connect → Claude Agent.
The existing opencode-anthropic-auth plugin sends subscription OAuth tokens straight to the Anthropic API, which Anthropic now restricts for third-party apps. Upstream replaced that approach with this provider.
Why this is a port, not a cherry-pick. Upstream built the provider in packages/core on its v2 plugin context (ctx.provider, ctx.aisdk.hook, ctx.session.hook). Our shipped CLI does not run that runtime: providers resolve in provider/provider.ts and requests are built in session/llm.ts.
src/altimate/provider/claude-agent/{claude,sync,tools,language-model}/are upstream's modules, copied with import paths adjusted. They manage theclaudeprocess, keep the CLI's history in sync with Claude's saved session, and hold Claude's tool calls until the CLI runs them.index.ts,catalog.ts,storage.tsandplugin.tsreplace upstream's plugin-context wiring.- Marked hooks in
provider.ts,transform.ts,llm.ts,plugin/index.tsand the TUI provider list connect it. - The folder's
README.mdlists every difference from upstream for the next bridge merge.
Behaviour. Claude uses Altimate's tools, permissions, agent prompt, skills and AGENTS.md. Claude Code's own tools, settings files, CLAUDE.md, hooks, MCP servers, memory and auto compaction are turned off. The per-turn environment block is not sent, because upstream found that forwarding it made subscriptions reject chats as a third-party app. A subscription shows $0 cost; an API key or cloud login is priced from that provider's catalog.
One fix on top of upstream. Our session processor only records a tool call whose part a tool-input-start opened. Upstream sends a bare tool-call, so the first live chat looped on empty steps. The stream converter now emits tool-input-start/delta/end before each call.
Known gaps, documented in the README:
- Titles, summaries and compaction run as standalone calls. Upstream copies the chat's Claude session so they reuse its prompt cache; our runtime has no hook for that.
headerTimeoutandchunkTimeoutnever reach Claude Code, because the provider loader removes them first.- A model list that changes mid-session shows after the next reload.
Dependency. @anthropic-ai/claude-agent-sdk@0.3.301, upstream's version. Installing it also downloads a ~270 MB per-platform copy of claude that is never run.
How did you verify your code works?
Live runs with a real Claude Max login and claude 2.1.322, in an isolated data directory:
- TUI (tmux):
/connect→ Claude Agent saved only the marker, not a token. Models listed: Opus 5.5, Fable 5.2, Sonnet 5.5, Haiku 5.5, with effort variants. - Sonnet 5.5 at medium effort: called
globand tworeads and answered correctly. The follow-up ransql_analyzeand reused the same Claude session and process. Cost was $0, ~58K prompt tokens came from cache, and Haiku generated the title. - Switching providers: an Altimate LLM Gateway turn, then back to Claude. Claude caught up on the turn it had not seen.
altimate run -m claude-agent/haikuand thebuild:localbinary: both answered correctly with tool calls, so the SDK survives bundling.
Not covered yet:
- Permission prompts (YOLO was on), interrupting mid-tool, and the 5-minute idle stop and resume.
- Compaction, subagents and attachments.
- The logged-out and missing-
claudepaths, and Linux/Windows.
Checks:
bun turbo typecheckpasses.- Marker guard, branding audit and tracker-leak scan are clean.
- 105 Claude Agent tests pass: upstream's replay tests through the real SDK, plus
integration.test.ts. - Full
packages/opencodemain pass: 20,934 pass, 6 fail. The 6 failures (mcp.headersandmcp HttpApi) fail the same way on a clean checkout ofmainon this machine. - CI's subprocess pass: 40/40.
Codex review fixes (second commit):
- Generate calls work.
agent createwith a Claude model ran live and wrote an agent file. - Stopped tools now interrupt the waiting Claude turn.
- Connection settings, login status and the session registry are kept per project.
- A plugin's explicit
maxOutputTokensis kept. - Covered by
review-fixes.test.ts. After these fixes, I re-ran the Claude Agent tests and the message-conversion suite, not the full suite.
Cost side effects
None that grow with user data. Each chat runs on the user's own Claude login. The /connect login check starts claude without sending a prompt, so it uses no tokens.
Screenshots / recordings
Not included yet.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
- I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"
🤖 Generated with Claude Code
Summary by CodeRabbit
- New Features
- Added Claude Agent as a provider, with Claude Code sign-in, session support, tool use, and model discovery.
- The first-run provider picker can suggest providers based on saved subscription logins.
- Added detection for Claude, ChatGPT, Copilot, SuperGrok, and GitLab Duo subscriptions.
- Documentation
- Updated Claude and ChatGPT subscription setup guidance, including headless use.
- Documented Claude Agent setup, model selection, and configuration.
- Bug Fixes
- OAuth sign-in requests now stop when their dialogs are dismissed.
- Retired Anthropic sign-ins are identified, with guidance to reconnect using Claude subscription sign-in or an API key.