OpenCode 2 plugin for Anthropic OAuth with Claude Pro/Max.
This package is adapted from
op-anthropic-auth version 0.1.4,
created by leohenon and released under the MIT
License. The original project's authentication approach, request shaping, and
plugin design form the basis of this package.
This adaptation ports that work to the OpenCode 2 plugin API. It is maintained as a separate package and is not an official OpenCode 2 release from the original author. The license retains credit for the original work.
Warning
This is an unofficial compatibility plugin. Anthropic may restrict third-party use of Claude subscription OAuth credentials, and using it could put your account at risk. Review Anthropic's current terms and use it at your own discretion.
OpenCode 2 beta sends Anthropic OAuth requests as-is, and Anthropic rejects them with
an opaque 429 ({"message":"Error"}). This plugin rewrites every request to
api.anthropic.com so it passes OAuth gating:
- registers a
Claude Pro/Maxbrowser login using OAuth and PKCE - lets OpenCode 2 store credentials and refresh expired tokens
- sets the
claude-cliuser-agent, matching your installed Claude Code version, and the requiredanthropic-betaheaders - adds the
x-anthropic-billing-headersystem block - prepends the Claude Code identity to the system prompt and relocates remaining system text into the first user message
- prefixes tool names with
mcp_and rewrites the response stream back
opencode2 plugin add op-anthropic-auth-v2
opencode2 auth login anthropic --method oauthor add it to ~/.config/opencode/opencode.jsonc:
The login command opens Anthropic's authorization page. Complete authorization, then paste the returned code into OpenCode 2. Users with a plain API key are unaffected; the plugin leaves non-OAuth connections untouched.
This adaptation only targets OpenCode 2. OpenCode 1 users should use the original op-anthropic-auth package.
Built against opencode2 0.0.0-beta-19271. The v2 plugin API is beta and may
change; pin accordingly.
The plugin reports a Claude Code version to meet Anthropic's model compatibility check. It reads that version from your own install rather than pinning one, in this order:
- the
CLAUDE_CODE_VERSIONenvironment variable, if it looks like a version - a native install — it follows the
claudesymlink on yourPATHand takes the version from the target path - an npm install — it reads the version from
@anthropic-ai/claude-code'spackage.json 2.1.326, if no install is found
The lookup is cached for 60 seconds, so a Claude Code update takes effect without
restarting OpenCode. Set CLAUDE_CODE_VERSION to report a specific version.
The runtime uses @openauthjs/openauth for PKCE generation. Development uses the
matching @opencode-ai/plugin beta types, TypeScript, and Node.js types to check the
published JavaScript against the OpenCode 2 plugin API.
npm install
npm test
npm run typecheck
npm run check
npm run pack:dry-run
{ "plugins": ["op-anthropic-auth-v2"] }