You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: Multi-Account OAuth Support with Auto-Relogin #11830
Add support for multiple OAuth accounts per provider with automatic credential rotation and browser-based session management for expired tokens.
Motivation
Currently, OpenCode only supports a single OAuth account per provider. When that account hits rate limits, work stops. Users who have multiple accounts (e.g. personal + work) need to manually switch between them.
This feature enables:
Multiple accounts per provider — add as many OAuth accounts as you want
Automatic failover — when one account hits rate limits or auth failures, seamlessly rotate to the next
Browser-based auto-relogin — automatically refresh expired tokens using Puppeteer sessions
Per-request credential tracking — know which account is being used for each session
Changes
Backend (packages/opencode)
Multi-account store: Track multiple OAuth records per provider in auth/index.ts
Credential rotation (auth/rotating-fetch.ts): Automatically failover to next account on rate limits or auth failures
Browser sessions (auth/browser.ts): Puppeteer-based auto-relogin for expired tokens
Similar scope — credential rotation. This implementation goes further with Puppeteer-based auto-relogin, per-request credential tracking via AsyncLocalStorage, and a full Settings UI for account management
This is the implementation for that request. Covers round-robin load balancing via rotating-fetch.ts with configurable cooldowns and automatic failover
The PR implementing this is #11832 — all CI checks passing ✅
Thanks for sharing @aydgn! That's an interesting plugin, but it solves a different problem.
opencode-antigravity-auth is specifically for authenticating against Google's Antigravity IDE to access Gemini and Claude models through Google's quota. It's a third-party auth plugin for one specific provider.
This issue/PR is about native multi-account support for OpenCode's built-in OAuth providers — Copilot, Codex, and any other OAuth-based provider. It adds:
Multiple accounts per provider with automatic rotation on rate limits
Puppeteer-based auto-relogin when tokens expire (no manual re-auth)
A Settings UI for managing accounts (add/remove, set active, view status)
Per-request credential tracking via AsyncLocalStorage
Configurable cooldowns, retries, and failover logic
So it's more of a core infrastructure feature for OpenCode itself rather than a provider-specific plugin. Both can happily coexist though — you could use the Antigravity plugin for Google models and this PR's multi-account support for Copilot/Codex at the same time.
There might be a strategic consideration here: some providers may prefer that their subscriptions aren't used via third-party tools like OpenCode. Integrating this into the core might be perceived as conflicting with provider interests (e.g., Anthropic). Would it be better to implement this as a plugin? This gives users the choice while keeping the core engine provider-neutral.
Valid concern @abien, but I think it's worth noting: OpenCode already has OAuth integration for Claude, Copilot and Codex built into its core. This isn't something new — it's been there from the start, and it's what enables users to connect their existing subscriptions.
This PR doesn't introduce OAuth support — it extends what's already built-in. It adds the ability to manage multiple accounts per provider and auto-relogin when tokens expire. If there were a philosophical problem with using provider subscriptions via OpenCode, that ship has already sailed — the entire auth infrastructure is a core feature.
As for the "provider interests" angle — the OAuth tokens get revoked or blocked from time to time, and new workarounds are found. That's been the cycle. If the stance were that this conflicts with provider interests, the existing single-account OAuth would need to be removed too. My PR just makes the existing experience more robust by adding failover and rotation.
That said, I do agree plugins are great for provider-specific things (like the Antigravity plugin @aydgn linked). But multi-account management for OpenCode's own built-in auth providers feels like core infrastructure to me.
Reacted by Alexander Bien, Tomasz Grabowski, Aydoğan, boscivity, Chindriș Mihai - Alexandru, Patrick Zanzarini, Minh Nguyen and Victor Ferreira
I completely agree @mguttmann. Having it automatically switch to the next account would be ideal just like in the plugin I shared earlier. That would really provide the best experience.
I dont know about auto switching based on usage limits. But I definitely would like a way to switch between work copilot and personal copilot. Perhaps via an environment variable OPENCODE_COPILOT_USER.
Alternatively we could have something similar to NVIM_APPNAME where there would be a completely seperate config and state tracking. This would allow to keep the current single auth strategy and handle things with configuration/state isolation. Note: You cant do this with OPENCODE_CONFIG_DIR because that only isolates the config, it still keeps all state information in a shared location which would disallow separate auth strategy.
They might be afraid that users will misuse the tools provided by OpenAI and other companies, not directly, but through their usage. So, it’s better to use workarounds to achieve your goals on your own risk.
Adding a concrete real-world case + a source-level observation that might help scope this.
My scenario: several GitHub Copilot Business accounts with identical model/quota. I burn one down, then rotate to the next. Because Copilot has no multi-account switch, the only way to rotate is to overwrite the stored credential (edit auth.json, which is migrated into account.json on load). This is exactly the manual switching this issue wants to eliminate.
Source-level note — the v2 storage already has the foundation, the Copilot plugin just doesn't use it:
account.json (version: 2, in ~/.local/share/opencode) is already a multi-account structure:
{
"version": 2,
"accounts": {
"<id1>": { "serviceID": "github-copilot", "description": "default", "credential": { ... } }
// a second github-copilot account could live here
},
"active": { "github-copilot": "<id1>" }
}
Account.forService(serviceID) already returns an array, and create / activate / active per serviceID already exist (packages/core/src/auth.ts). The opencode.ai Console account even has full login / logout / switch CLI commands wired to it.
What's missing for Copilot specifically: the Copilot auth plugin's authorize flow (packages/opencode/src/plugin/github-copilot/copilot.ts) returns a single credential that lands on the one fixed github-copilot key, so re-running /connectoverwrites rather than adding a second account, and there's no switch exposed for it. So a meaningful chunk of this feature for OAuth providers like Copilot may be "wire the existing v2 multi-account API + a picker/switch into the provider auth flow" rather than building storage from scratch.
A concrete breakage that rotation causes today (worth designing for): rotating the Copilot credential mid-session breaks github-copilot/gpt-5.5 with 401 input item ID does not belong to this connection, because gpt-5.5's stateful Responses API itemId handles are bound to the credential that created them, and the session still references the old ones. Filed separately as #31236. If automatic rotation/failover is implemented here, it should also invalidate (or retry-without) the stale Responses API itemId references on credential change, otherwise auto-rotation would silently break in-flight gpt-5.5 sessions.
Activity
github-actions commentedon Feb 2, 2026
This issue might be a duplicate of existing issues. Please check:
Feel free to ignore if this addresses your specific case differently or if there are additional improvements needed beyond the closed issues.
mguttmann commentedon Feb 2, 2026
Thanks for flagging these!
This issue is the clean successor to #9971 (which I closed myself to split into focused PRs). Here's how this relates to the duplicates found:
rotating-fetch.tswith configurable cooldowns and automatic failoverThe PR implementing this is #11832 — all CI checks passing ✅
mguttmann commentedon Feb 2, 2026
mguttmann commentedon Feb 2, 2026
aydgn commentedon Feb 4, 2026
Here is a plugin with a similar purpose: https://github.com/NoeFabris/opencode-antigravity-auth/
It automatically switches accounts when a rate limit is reached.
mguttmann commentedon Feb 4, 2026
Thanks for sharing @aydgn! That's an interesting plugin, but it solves a different problem.
opencode-antigravity-authis specifically for authenticating against Google's Antigravity IDE to access Gemini and Claude models through Google's quota. It's a third-party auth plugin for one specific provider.This issue/PR is about native multi-account support for OpenCode's built-in OAuth providers — Copilot, Codex, and any other OAuth-based provider. It adds:
So it's more of a core infrastructure feature for OpenCode itself rather than a provider-specific plugin. Both can happily coexist though — you could use the Antigravity plugin for Google models and this PR's multi-account support for Copilot/Codex at the same time.
abien commentedon Feb 4, 2026
There might be a strategic consideration here: some providers may prefer that their subscriptions aren't used via third-party tools like OpenCode. Integrating this into the core might be perceived as conflicting with provider interests (e.g., Anthropic). Would it be better to implement this as a plugin? This gives users the choice while keeping the core engine provider-neutral.
mguttmann commentedon Feb 4, 2026
Valid concern @abien, but I think it's worth noting: OpenCode already has OAuth integration for Claude, Copilot and Codex built into its core. This isn't something new — it's been there from the start, and it's what enables users to connect their existing subscriptions.
This PR doesn't introduce OAuth support — it extends what's already built-in. It adds the ability to manage multiple accounts per provider and auto-relogin when tokens expire. If there were a philosophical problem with using provider subscriptions via OpenCode, that ship has already sailed — the entire auth infrastructure is a core feature.
As for the "provider interests" angle — the OAuth tokens get revoked or blocked from time to time, and new workarounds are found. That's been the cycle. If the stance were that this conflicts with provider interests, the existing single-account OAuth would need to be removed too. My PR just makes the existing experience more robust by adding failover and rotation.
That said, I do agree plugins are great for provider-specific things (like the Antigravity plugin @aydgn linked). But multi-account management for OpenCode's own built-in auth providers feels like core infrastructure to me.
aydgn commentedon Feb 4, 2026
I completely agree @mguttmann. Having it automatically switch to the next account would be ideal just like in the plugin I shared earlier. That would really provide the best experience.
blurskye commentedon Feb 18, 2026
when will this be merged :\
cavanaug commentedon Feb 22, 2026
I dont know about auto switching based on usage limits. But I definitely would like a way to switch between work copilot and personal copilot. Perhaps via an environment variable OPENCODE_COPILOT_USER.
Alternatively we could have something similar to NVIM_APPNAME where there would be a completely seperate config and state tracking. This would allow to keep the current single auth strategy and handle things with configuration/state isolation. Note: You cant do this with OPENCODE_CONFIG_DIR because that only isolates the config, it still keeps all state information in a shared location which would disallow separate auth strategy.
young5lee commentedon Mar 4, 2026
Is there any particular reason why it hasn’t been merged?
cavanaug commentedon Mar 4, 2026
I would really like to see #8963 merged. It would be of great help and is a nice foundational building block.
Heelc commentedon Mar 12, 2026
I need it
kqvanity commentedon Mar 13, 2026
Would great help as many plugins have to add the duplicate code for multiaccounting
saeedvaziry commentedon Mar 19, 2026
made a little script while waiting for the PR
https://github.com/saeedvaziry/oc-profile
vferreirati commentedon Apr 20, 2026
Hopefully this gets merged soon 👍
hildebrandt commentedon Apr 20, 2026
Please add this feature.
HicaroD commentedon Apr 25, 2026
This feature would be awesome for allowing parallel workflows running on different accounts.
Excited for it.
NaturalDevCR commentedon May 5, 2026
I'm exactly in that position, I do have my personal account, and a work account... this would be the perfect fit.
antongulin commentedon May 5, 2026
They might be afraid that users will misuse the tools provided by OpenAI and other companies, not directly, but through their usage. So, it’s better to use workarounds to achieve your goals on your own risk.
doomsday616 commentedon Jun 7, 2026
Adding a concrete real-world case + a source-level observation that might help scope this.
My scenario: several GitHub Copilot Business accounts with identical model/quota. I burn one down, then rotate to the next. Because Copilot has no multi-account switch, the only way to rotate is to overwrite the stored credential (edit
auth.json, which is migrated intoaccount.jsonon load). This is exactly the manual switching this issue wants to eliminate.Source-level note — the v2 storage already has the foundation, the Copilot plugin just doesn't use it:
account.json(version: 2, in~/.local/share/opencode) is already a multi-account structure:{ "version": 2, "accounts": { "<id1>": { "serviceID": "github-copilot", "description": "default", "credential": { ... } } // a second github-copilot account could live here }, "active": { "github-copilot": "<id1>" } }Account.forService(serviceID)already returns an array, andcreate/activate/activeperserviceIDalready exist (packages/core/src/auth.ts). The opencode.ai Console account even has fulllogin/logout/switchCLI commands wired to it.What's missing for Copilot specifically: the Copilot auth plugin's
authorizeflow (packages/opencode/src/plugin/github-copilot/copilot.ts) returns a single credential that lands on the one fixedgithub-copilotkey, so re-running/connectoverwrites rather than adding a second account, and there's noswitchexposed for it. So a meaningful chunk of this feature for OAuth providers like Copilot may be "wire the existing v2 multi-account API + a picker/switch into the provider auth flow" rather than building storage from scratch.A concrete breakage that rotation causes today (worth designing for): rotating the Copilot credential mid-session breaks
github-copilot/gpt-5.5with401 input item ID does not belong to this connection, because gpt-5.5's stateful Responses APIitemIdhandles are bound to the credential that created them, and the session still references the old ones. Filed separately as #31236. If automatic rotation/failover is implemented here, it should also invalidate (or retry-without) the stale Responses APIitemIdreferences on credential change, otherwise auto-rotation would silently break in-flight gpt-5.5 sessions.Hronom commentedon Sep 25, 2026
Please add this, I have personal and work account and I wanna have easy switch between them. There is no misuse for this case