OpenCode is a terminal-based AI coding agent. It used to support Claude Pro/Max subscriptions out of the box via an OAuth plugin that handled authentication the same way Claude Code does. No API key needed, just your existing subscription.
That changed with OpenCode 1.3.0. Anthropic threatened legal action over the plugin, and OpenCode's maintainer Dax removed it. The built-in opencode-anthropic-auth npm package was pulled. If you run /connect in OpenCode now and select Anthropic, the Claude Pro/Max OAuth option is gone.
You are paying for access to the model. The tokens are yours. Anthropic just does not want third-party tools using them.
What Happened
Prior to version 1.3.0, OpenCode shipped with a plugin called opencode-anthropic-auth. It handled the full OAuth flow against Anthropic's servers: PKCE handshake, token exchange, automatic refresh, and header injection. It worked seamlessly.
Anthropic's legal team stepped in and demanded it be removed. The npm package was unpublished. The OpenCode docs now state that "Anthropic explicitly prohibits" using Pro/Max subscriptions with third-party tools.
The Fix: Community Plugin
The community rebuilt the auth plugin as an external package: @ex-machina/opencode-anthropic-auth. It replicates the original functionality that was removed. A mirror is available on Codeberg if the GitHub repo gets taken down.
It supports three authentication methods:
- Claude Pro/Max OAuth - authenticates via
claude.aiusing your subscription. No API costs. - API Key Creation - OAuth flow via
console.anthropic.comthat generates an API key on your behalf. - Manual API Key - enter an existing API key directly.
Under the hood it runs the same PKCE-secured OAuth flow, exchanges authorization codes for token pairs, and injects the right headers and beta flags into requests.
Setup
Add the plugin to your OpenCode config. This goes in either your global config at ~/.config/opencode/opencode.json or your project-level opencode.json:
{
"plugin": ["@ex-machina/opencode-anthropic-auth"]
}
Launch OpenCode. Run /connect, select Anthropic, and the Claude Pro/Max OAuth option is back. Authenticate through your browser and you are set.
The Token Refresh Problem
The plugin's automatic token refresh has been broken for some time. Once your OAuth access token expires, the plugin fails to renew it and OpenCode locks you out. You are left staring at an auth error despite having an active subscription and a working plugin.
On macOS, opencode-inject fixes this. It is a shell script that reads your Claude Code OAuth credentials directly from the macOS Keychain and writes them into OpenCode's auth.json file. Run it whenever the plugin fails to refresh and you are back online immediately.
Here is what it does:
- Reads the
Claude Code-credentialsentry from the macOS Keychain usingsecurity - Extracts the
accessToken,refreshToken, andexpiresAtfields - Writes them into
~/.local/share/opencode/auth.jsonunder theanthropicOAuth key
No third-party dependencies. No network calls. Pure shell and Python 3, both already on your Mac.
Requirements
- macOS only (Keychain access via
securityCLI) - Claude Code installed and authenticated with a Pro or Max subscription
- OpenCode installed with the community plugin configured
Setup
-
Auth with Claude Code
Run
claudein your terminal to make sure your tokens are fresh.Warning: Make sure your Claude Code session does not have stale tokens. If you have not launched Claude Code in a while, open it and verify it connects successfully before running the inject script. Stale or expired tokens in the Keychain will be copied as-is and will not work. -
Download the script
The script is hosted on Codeberg: codeberg.org/breakzero/opencode-inject
Make it executable and drop it somewhere on your
$PATH:chmod +x opencode-inject mv opencode-inject ~/.local/bin/ -
Run it
Whenever OpenCode complains about an expired token:
opencode-injectYour subscription tokens are synced and OpenCode works again.
Break Zero