@xtruder/opencode-claude-max-plugin
v0.1.12
Published
OpenCode plugin for Claude Max/Pro subscription via @anthropic-ai/sdk - uses Claude Code OAuth credentials
Maintainers
Readme
@xtruder/opencode-claude-max-plugin
An OpenCode plugin that enables Claude Pro/Max subscription access via the official @anthropic-ai/sdk, using OAuth credentials from Claude Code (~/.claude/.credentials.json).
Why?
- Use your Claude subscription — Automatically reads OAuth credentials from Claude Code, no separate API key needed
- Matches Claude Code exactly — Same headers, billing, tool names, and request format as Claude Code CLI
- Prompt caching — 98% of input tokens served from cache (system prompt + tools cached globally)
- All Claude models — Opus 4.6, Sonnet 4.6, Haiku 4.5
- Extended thinking — Full reasoning support with thinking variants (high/max)
- Usage tracking — Built-in
/usagecommand shows subscription utilization - Self-registering — Models are registered automatically, no manual provider config needed
Installation
Add the plugin to your opencode.json (project-level or ~/.config/opencode/opencode.json globally):
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@xtruder/opencode-claude-max-plugin"]
}That's it. The plugin self-registers the anthropic-sdk provider and its models (Haiku 4.5, Sonnet 4.6, Opus 4.6) at startup via the OpenCode config hook. No separate provider block is needed.
Then open OpenCode and run /connect → Other → anthropic-sdk. If Claude Code is installed and you're logged in, credentials are read automatically from ~/.claude/.credentials.json — no API key needed.
Custom model options
If you want to override model settings (e.g. thinking budgets, variants), you can add a provider block alongside the plugin:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@xtruder/opencode-claude-max-plugin"],
"provider": {
"anthropic-sdk": {
"models": {
"claude-sonnet-4-6": {
"options": {
"thinking": { "type": "enabled", "budgetTokens": 1024 }
},
"variants": {
"high": { "thinking": { "type": "enabled", "budgetTokens": 10000 } },
"max": { "thinking": { "type": "enabled", "budgetTokens": 32000 } }
}
}
}
}
}
}Config-level settings are merged with plugin defaults — you only need to specify what you want to override.
Authentication
Credentials are resolved in order:
ANTHROPIC_API_KEYenv var orapiKeyprovider option- Claude Code credentials — auto-read from
~/.claude/.credentials.json
For Claude Code credentials, log in via claude CLI first (claude auth login).
Features
- Streaming and non-streaming completions
- Tool/function calling with Claude Code tool name mapping (
task→Agent, etc.) - MCP tool name remapping (
server_tool→mcp__server__tool) - Extended thinking with signature passthrough for multi-turn conversations
- Prompt caching (98% cache hit rate with full OpenCode tool set)
- Subscription rate limit detection — fails fast with clear message instead of hanging
- Long context auto-detection — adds
context-1mbeta header when request body is large /usageslash command — shows current session and weekly utilization
Usage Command
After adding the config, run /usage inside OpenCode to see your subscription usage:
Claude Subscription Usage
────────────────────────────────────────────────────
Current session
████████████████████████████████░░░░░░░░░░░░░░░░░░ 67% used
Resets 7:00 PM GMT+1
Current week (all models)
████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 8% used
Resets Mar 30, 7:00 AM GMT+2With Vercel AI SDK
The plugin also works as a standalone Vercel AI SDK provider:
import { createAnthropicSDK } from "@xtruder/opencode-claude-max-plugin"
import { streamText } from "ai"
// Uses ~/.claude/.credentials.json automatically
const provider = createAnthropicSDK()
const model = provider.languageModel("claude-sonnet-4-6")
const result = streamText({ model, prompt: "Hello!" })
for await (const chunk of result.textStream) {
process.stdout.write(chunk)
}Development
bun install
bun run build
bun run test # integration tests (requires ANTHROPIC_API_KEY or Claude Code credentials)See RESEARCH.md for detailed reverse-engineering findings on how we matched Claude Code's request format.
License
MIT
