OpenCode stopped bundling its Claude Pro/Max login plugins in version 1.3.0, so the way back is a custom provider: drop this repo's opencode.json into your project, hand OpenCode the p2a_ key from Plan2API as PLAN2API_API_KEY, and pick plan2api/claude/claude-sonnet-5 in /models. Claude Sonnet 5 and Opus 5.5 then run on your subscription with tool calls, streaming and a 1M-token context, with no Anthropic API key.
The same provider carries your ChatGPT Plus or Pro plan (plan2api/openai/gpt-6.1-sol), Google AI Pro (plan2api/gemini/gemini-4-argon-high) and Kimi Code (plan2api/kimi/k3), and it works on OpenCode 1.x and OpenCode 2.
Get a free p2a_ key | OpenCode guide on plan2api.com | API reference
- Open plan2api.com/connect and sign up with Google.
- Connect Claude by signing in with your Claude account on Anthropic's own sign-in page. Pro, Max 5x and Max 20x all work.
- Copy the
p2a_key you get after connecting. It is shown once; create more on the Keys page (plan2api.com/dashboard/keys).
ChatGPT Plus or Pro connects with a one-time device code on OpenAI's own page, Google AI Pro with your Google account, and Kimi Code with its API key.
curl -fsSL https://opencode.ai/v2/install | bashOr brew install anomalyco/tap/opencode-v2, or npm install -g @opencode/cli.
Put opencode.json in your project root, or in ~/.config/opencode/opencode.json to use it in every project:
mkdir -p ~/.config/opencode
curl -fsSL https://raw.githubusercontent.com/bitgate/opencode-claude-subscription/master/opencode.json \
-o ~/.config/opencode/opencode.jsonAlready have a global config? Merge the provider.plan2api block into it instead of overwriting.
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"plan2api": {
"npm": "@ai-sdk/openai-compatible",
"name": "Plan2API",
"options": {
"baseURL": "https://api.plan2api.com/v1",
"apiKey": "{env:PLAN2API_API_KEY}"
},
"models": {
"claude/claude-sonnet-5": {
"name": "Claude Sonnet 5",
"limit": { "context": 1000000, "output": 128000 }
},
"claude/claude-opus-5-5": {
"name": "Claude Opus 5.5",
"limit": { "context": 1000000, "output": 128000 }
}
}
}
},
"model": "plan2api/claude/claude-sonnet-5",
"small_model": "plan2api/claude/claude-haiku-4-5"
}The file in the repo adds Claude Haiku 4.5, GPT-6.1 Sol, Gemini 4 Argon, Gemini 3.8 Flash and Kimi K3.
OpenCode 2 runs model requests in a background service, so set the key on the service:
opencode service set env PLAN2API_API_KEY p2a_your_keyFor a one-off private session instead: PLAN2API_API_KEY=p2a_your_key opencode --standalone. OpenCode 1.x reads it from your shell:
export PLAN2API_API_KEY="p2a_your_key"Run opencode, type /models and choose Claude Sonnet 5 under Plan2API. The config already makes it the default and sends session titles to Claude Haiku 4.5 through small_model, so titles don't burn your Sonnet allowance.
OpenCode 2 reads the provider / npm / options shape above as-is, so the same file works on both versions. If you prefer OpenCode 2's native shape (providers, package, settings), use v2-native/opencode.jsonc instead. It uses the @opencode/ai/providers/openai-compatible package, reads the key from PLAN2API_API_KEY through env, and maps short model refs such as plan2api/claude-sonnet-5 to Plan2API ids with modelID. Keep one format per file, and don't point OpenCode 1.x at the native V2 file.
| Model ref | Runs on | Context window |
|---|---|---|
plan2api/claude/claude-sonnet-5 |
Claude Pro or Max | 1,000,000 |
plan2api/claude/claude-opus-5-5 |
Claude Pro or Max | 1,000,000 |
plan2api/claude/claude-haiku-4-5 |
Claude Pro or Max | 200,000 |
plan2api/openai/gpt-6.1-sol |
ChatGPT Plus or Pro (Codex) | 500,000 (Codex default) |
plan2api/gemini/gemini-4-argon-high |
Google AI Pro or Ultra | 1,048,576 |
plan2api/gemini/gemini-3.8-flash-high |
Google AI Pro or Ultra | 1,048,576 |
plan2api/kimi/k3 |
Kimi Code membership | 1,048,576 |
Want another Plan2API model? Add its id under models. GET https://api.plan2api.com/v1/models lists all of them with context_length, and the API reference has the full table.
- Streaming and function tool calls on every model, so OpenCode's tools and subagents run as normal.
reasoning_effort(orreasoning.effort):nonetomaxon Claude and Gemini,low,highormaxon Kimi, passed through on Codex.- Image input on Claude, Gemini and Kimi models.
- JSON mode on Codex, Gemini and Kimi. Claude answers a JSON
response_formatwith400 unsupported_parameter. - Chat Completions only: use
@ai-sdk/openai-compatible(or@opencode/ai/providers/openai-compatibleon V2), because@ai-sdk/openaicalls/v1/responses, which Plan2API does not serve.
| What you see | Why | Fix |
|---|---|---|
401 invalid_api_key |
PLAN2API_API_KEY isn't set where OpenCode runs requests |
OpenCode 2: opencode service set env PLAN2API_API_KEY p2a_...; OpenCode 1.x: export it before launching |
404 not_found |
The provider uses @ai-sdk/openai (Responses API), or baseURL is missing /v1 |
Use @ai-sdk/openai-compatible and https://api.plan2api.com/v1 |
Model unavailable: plan2api/... (OpenCode 2) |
The model ref doesn't match a key in the models map |
Use a key from the config, such as plan2api/claude/claude-sonnet-5 |
403 no_credentials |
The model belongs to a provider you haven't connected | Connect it at plan2api.com, or pick a claude/ model |
400 model_not_found |
The id sent to Plan2API is wrong | In opencode.json the model keys are the Plan2API ids; in the native V2 file, check modelID |
400 unsupported_parameter |
JSON response_format on a Claude model |
Use Codex, Gemini or Kimi for JSON mode |
429 subscription_quota_exhausted |
Your Claude plan hit its 5-hour or weekly limit | Wait for the Retry-After time, or connect a second Claude account so requests fail over automatically |
429 rate or inflight |
Parallel subagents beyond the Free plan's 1 request per second (4 at once) | Move to Pro: 10 per second, bursts of 600, 16 at once |
| Long sessions never compact | The model has no limit.context |
Add limit like the Claude entries |
Not out of the box anymore: OpenCode dropped its bundled Claude Pro/Max plugins in 1.3.0. Add Plan2API as a custom provider with this repo's opencode.json and your Claude subscription powers OpenCode again.
You don't need it. Plan2API signs in with your Claude account on Anthropic's own page once and gives OpenCode a standard p2a_ key, so OpenCode only ever sees an OpenAI-compatible provider.
Yes. OpenCode has its own Sign in with ChatGPT, and through Plan2API, GPT also sits in the same provider as Claude: connect ChatGPT and pick plan2api/openai/gpt-6.1-sol.
Yes. OpenCode 2 reads the provider block in opencode.json as-is, and v2-native/opencode.jsonc has the native V2 version. Set the key with opencode service set env PLAN2API_API_KEY p2a_your_key.
In your project root (or .opencode/opencode.json) for one project, or ~/.config/opencode/opencode.json for all of them.
@ai-sdk/openai talks to OpenAI's Responses API at /v1/responses, which Plan2API doesn't serve. @ai-sdk/openai-compatible uses /v1/chat/completions.
Plan2API Free is $0 with one connected subscription and no card. Pro is $12 a month for 3 subscriptions and rate limits that keep up with parallel subagents; Scale is $29 a month for 25. See pricing.
- OpenCode + Plan2API guide
- OpenCode vs Claude Code
- Use your Claude subscription as an API
- Claude Pro and Max usage limits
- Claude Code Router + Plan2API
- Plan2API API reference
Same setup, other clients: