← Insights

Claude Subscription in OpenCode: What Works and What Is Allowed

opencode-claude-auth copies Claude Code login tokens into OpenCode. Here is why its logins fail, and which Claude sign-in routes Anthropic allows.

8 min read
Claude Subscription in OpenCode: What Works and What Is Allowed

You can use a Claude subscription in OpenCode through Anthropic's own Claude Code. Run claude auth login on the machine where OpenCode runs, then connect the Claude Agent provider in OpenCode. Claude Code makes the model calls, and your plan covers the usage. If you use an Anthropic API key instead, requests are billed separately at API prices. Copying your Claude login into OpenCode with the opencode-claude-auth plugin is a different thing, and Anthropic's terms do not allow it. This article covers which route to use, what the plugin's errors mean, and where the plugin stops being a safe choice.

To see what those requests cost, cost-xray, a Tigerless Labs tool, captures the API traffic a local Claude Code sends and splits the tokens by source, such as the system prompt, tool schemas and tool results. It also estimates what the same requests would cost at API prices. That figure is an API equivalent. What you pay for a subscription follows your plan. The split between sources inside one request is approximate, but the total matches the usage the provider reports. cost-xray runs on macOS and Linux, and it observes the traffic without changing what Claude Code sends.

Which Claude sign-in routes does Anthropic allow in OpenCode?

Two routes are documented by the companies involved, and the plugin is not one of them. The table compares all three.

RouteHow you sign inWhat it costsRemote server or workspace
Claude Agent provider in OpenCodeInstall Claude Code 2.1.248 or later, then run claude auth loginYour Claude plan covers the usage when Claude Code is signed in with a subscriptionOnly when Claude Code is installed on the same machine as the OpenCode server. Remote workspaces are not supported
Anthropic API keyCreate a key in the Claude Console, then enter it with /connect in OpenCodeAnthropic API prices, see the Claude Code pricing guide for how the two compareYes, from any machine that can reach the API
opencode-claude-auth pluginImports Claude Code's tokens from the Keychain or credentials fileYour plan, but Anthropic's terms do not permit this useNot a supported setup

The Claude Agent provider is the subscription route. OpenCode's documentation says Claude Code makes the model calls and OpenCode handles everything else. Anthropic's compliance page allows a person to sign in to the unmodified Claude Code binary with their own subscription, and this route relies on that case. It covers your own use on the machine where you signed in. Other people's use and products follow the rules in the paragraphs below.

The API key route follows OpenCode's provider setup: run /connect, choose the provider and enter its credentials. Anthropic's API overview says the key comes from the Console. If OpenCode runs in a remote workspace, use this route, because Claude Agent does not run there. Products that build on the API use this route too. If you want to see what each request costs on the subscription route, read what Claude Code sends to the API and what each part costs.

Other cases have their own rules. If you build your own application that calls Claude, authenticate it with an Anthropic API key from the Claude Console or with a supported cloud provider. Anthropic does not permit third-party developers to offer Claude.ai login in their own application or to route requests through Free, Pro, Max or Ultra plan credentials on behalf of their users. If your platform hosts the unmodified Claude Code, for example in a hosted sandbox, Anthropic's Commercial Terms of Service apply: the binary must not be modified, no built-in authentication method may be removed or disabled, each end user authenticates with their own credentials, and that usage is billed directly to that user. You may not pay for, resell or intermediate it on their behalf. A team member uses the subscription route with their own Claude account on the machine where they run OpenCode.

What does opencode-claude-auth do?

opencode-claude-auth is a community plugin for OpenCode, the terminal coding tool. It reads the OAuth tokens that Claude Code keeps on your machine, either in the macOS Keychain or in a file called .credentials.json under your Claude config folder. OpenCode then uses those tokens for its Anthropic provider. In OpenCode's connect menu the option appears as Import Claude Code subscription.

The plugin's README calls it a community workaround that may stop working if Anthropic changes its sign-in system. The same README says Anthropic's terms allow subscription tokens only with official Anthropic clients. Keep that in mind for the rest of this article. Other plugins for Claude Code are covered in our list of open-source Claude Code plugins.

Why does OpenCode still return 401 Invalid API key after I log in to Claude Code again?

One macOS user reported this in issue #187. Claude Code worked on the same machine, yet every OpenCode request failed with a 401 and "Invalid API key". The user had already cleared the plugin's cache. They deleted the Keychain item, logged in to Claude Code again, and confirmed the item came back. The 401 kept coming.

On April 16, 2026, the maintainer suggested clearing the OpenCode cache. The issue was closed on July 10, 2026, and the thread does not confirm that the fix worked.

A 401 after a fresh login therefore does not prove your subscription is broken. It shows that the plugin sits between Claude Code and OpenCode, and that the join can fail. If the 401 continues, use a route from the table above instead of repairing the plugin. The next section covers the token refresh, the other place where that join breaks.

Why does the token refresh keep failing?

Subscription tokens expire, so the plugin refreshes them. In its current implementation the plugin normally refreshes directly with Anthropic's OAuth endpoint, and it falls back to the claude CLI only in a narrow window. Before it refreshes, it reads the Keychain again and adopts any newer token stored there. The README's troubleshooting table lists two error messages. "Token expired and refresh failed" means the automatic refresh did not work, and the fix is to run claude yourself to sign in again. "Auth keeps failing right after re-authenticating with claude" means OpenCode may still hold a stale refresh token from an earlier connection, and the README says to run /connect again.

Issue #281, opened on 7 September 2026, reports that the plugin's refresh asks the user to sign in again. The cause is not confirmed, so this article does not say why it happens.

Rate-limit errors such as 429 are a different failure, covered in Claude 429 Errors: What They Mean and How to Fix Them.

Why does the plugin fail to load on OpenCode 2?

OpenCode 2 changed how plugins load. In issue #290, a user reported that version 2.2.1 was rejected at startup. OpenCode said the plugin must export a default definition with an id and an effect or setup function. The plugin was written for OpenCode's older plugin interface, so its login hook never registered and the Claude credentials stayed unavailable.

Version 3.0.0, released on 16 October 2026, targets OpenCode 2. Its config key is plugins, where OpenCode 1 used plugin. Versions 3.0.0 and later do not load on OpenCode 1.x. The last release that supports OpenCode 1.x is 2.2.1.

What do you give up with the Claude Agent route?

The Claude Agent route runs Claude Code as the model caller, so the settings of each tool matter. Claude gets Claude Code's system prompt, plus your OpenCode agent's prompt, AGENTS.md files, OpenCode skills and MCP instructions. It uses OpenCode's tools and permissions. Your Claude Code settings, CLAUDE.md files, hooks, MCP servers, skills and memory are not loaded. So a skill or instruction that lives in OpenCode still applies, and one that lives in Claude Code does not carry over. Features such as /usage, /loop, auto mode and agent teams belong to Claude Code and are unavailable here. Temperature, top-p, top-k, seed and stop sequences are not supported, and plugin hooks that watch HTTP requests do not run. Check these gaps before you switch. A Codex skill's behavior in Claude Code shows what carries over between tools.

When is the plugin the wrong choice, even if it works?

Most of the time it is. The plugin's README says Anthropic's terms allow subscription tokens only with official Anthropic clients. Anthropic's legal and compliance page is stricter. It says OAuth sign-in is meant for Claude Code and other native Anthropic applications. It says developers may not route requests through Free, Pro, Max or Ultra plan credentials on behalf of their users. It also says Anthropic may enforce these restrictions without prior notice.

A plugin that works this month can stop working the next, and a broken login interrupts whatever you were doing. For a team, a product or any hosted deployment, follow the route rules in the sections above rather than the plugin.

Conclusion

Claude works inside OpenCode through two routes that Anthropic's terms cover: the Claude Agent provider, with Claude Code installed on the same machine as the OpenCode server, and an API key billed through the Console. The plugin copies a login that Anthropic's terms tie to its own applications, so its 401 and refresh errors are a warning as well as a bug report.

The decision rule is short. If your own Claude plan should cover the work and Claude Code runs on the same machine as the OpenCode server, use the Claude Agent provider. If OpenCode runs in a remote workspace, or you build your own application, use an API key from the Console or a supported cloud provider. If your platform hosts the unmodified Claude Code, follow the hosting terms in the body. The plugin fits none of these cases.

The next step is small. Install Claude Code 2.1.248 or later on the machine where you run OpenCode, sign in with claude auth login, then connect Claude Agent with /connect and pick a model with /models. The model list comes from Claude Code. On a remote server, Claude Code has to be installed and signed in on that server. In a remote workspace, Claude Agent is unavailable, so use an API key there.

FAQ

Will the plugin get my Claude account banned?

Neither source says that directly. Anthropic's compliance page says it may take measures to enforce these restrictions without prior notice, and the plugin's README says it may stop working. Treat the plugin as a risk to your account, not a safe shortcut.

Does the Claude Agent route use my subscription or bill me?

It depends on how Claude Code is signed in. With a Claude subscription, your plan covers the usage, and OpenCode shows no cost. With an Anthropic API key or a cloud provider, billing follows that provider's prices. If you host the unmodified Claude Code for others, each user signs in with their own credentials and is billed under their own agreement.

Can I use the Claude Agent route on a remote server?

Claude Agent requires Claude Code to be installed on the same machine as the OpenCode server. If you connect to that server from another computer, the same-machine requirement still applies to the server. OpenCode remote workspaces do not support Claude Agent.

Does the plugin still work with OpenCode 1?

Version 3.0.0 and later do not load on OpenCode 1.x. The last version that does is 2.2.1, which the plugin's documentation says to pin if you must stay on OpenCode 1.

Share this article

Keep reading