Skip to content

feat(auth): multi-account OAuth support with auto-relogin - #11832

Closed
mguttmann wants to merge 3 commits into
anomalyco:devfrom
mguttmann:feat/oauth-multi-account
Closed

feat(auth): multi-account OAuth support with auto-relogin#11832
mguttmann wants to merge 3 commits into
anomalyco:devfrom
mguttmann:feat/oauth-multi-account

Conversation

@mguttmann

Copy link
Copy Markdown

Summary

  • Add support for multiple OAuth accounts per provider with automatic credential rotation
  • Implement browser-based auto-relogin for expired tokens using Puppeteer
  • Track per-request credentials with AsyncLocalStorage context

Closes#11830

Changes

Backend

FileDescription
auth/index.tsMulti-record OAuth store (add/remove/list accounts)
auth/rotating-fetch.tsAutomatic failover on rate limits or auth failures
auth/browser.tsPuppeteer-based session management for auto-relogin
auth/credential-manager.tsEvent-driven failover notifications
auth/context.tsAsyncLocalStorage for per-request credential tracking
config/config.tsoauth config block (cooldowns, retries, max attempts)
cli/cmd/auth.tsBrowser session management CLI commands
server/routes/provider.tsAccount CRUD, usage, browser session API endpoints
server/server.tsRoot-level auth routes
provider/provider.tsRotating-fetch integration

Frontend

FileDescription
settings-providers.tsxManage accounts, set active, view usage
session-context-tab.tsxShow active account per session
dialog-settings.tsxSettings tabs structure

SDK

  • Regenerated from server routes with all new endpoints

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate PRs Found

  1. feat(auth): OAuth Marathon - multi-account credential rotation (feat(auth): OAuth Marathon - multi-account credential rotation #8590)

  2. feat(openai-oauth) OpenAI OAuth multi account support (feat(openai-oauth) OpenAI OAuth multi account support #8536)

  3. feat(usage): unified usage tracking with auth refresh ([FEATURE] Add unified usage tracking via /usage (#9545) #9281) (feat: add OAuth provider usage tracking #9545)

I'd recommend reviewing #8590 most closely as it appears to address the same multi-account credential rotation feature set.

@mguttmann

Copy link
Copy Markdown
Author

Thanks for the duplicate analysis! Here's how this PR compares to the flagged ones:

PRStatusComparison
#8590 (OAuth Marathon)OpenSimilar goal. This PR builds on that concept with additional features: Puppeteer-based auto-relogin for expired tokens, AsyncLocalStorage per-request credential context, event-driven failover via credential-manager, and a complete Settings UI for managing accounts
#8536 (OpenAI multi-account)OpenOpenAI-specific. This PR is provider-agnostic — works with any OAuth provider, not just OpenAI
#9545 (usage tracking + auth refresh)OpenPartial overlap on auth refresh. This PR has a dedicated browser.ts (828 lines) for full browser session management, not just token refresh

Key differentiators of this PR:

  • 🔄 rotating-fetch.ts — Automatic failover with configurable cooldowns, retries, and max attempts
  • 🌐 browser.ts — Puppeteer-based auto-relogin for expired tokens (no manual re-auth needed)
  • 📊 Full account management UI in Settings (add/remove accounts, set active, view usage)
  • 🧵 auth/context.ts — AsyncLocalStorage for per-request credential tracking
  • ⚙️ oauth config block with tunable rotation parameters

This is a clean split from the closed #9972 — focused solely on multi-account + auto-relogin (YOLO mode is in separate PR #11833).

@mguttmann

Copy link
Copy Markdown
Author
image

@mguttmann

Copy link
Copy Markdown
Author
image

@dan-myles

Copy link
Copy Markdown

YO I NEED THIS

@mguttmann

Copy link
Copy Markdown
Author

Thanks! 🙌 If you want to try it now, you can build from the branch — it's fully working and all CI checks pass.

@mguttmann
mguttmannforce-pushed the feat/oauth-multi-account branch 2 times, most recently from bd271d0 to 050f2c4CompareFebruary 2, 2026 22:47
@NotFiliberto

Copy link
Copy Markdown

i need this too

@mguttmann
mguttmannforce-pushed the feat/oauth-multi-account branch from 050f2c4 to a02099fCompareFebruary 3, 2026 08:30
@NotFiliberto

Copy link
Copy Markdown

any change to have this merged in the main branch?

@mguttmann

Copy link
Copy Markdown
Author

Hey @NotFiliberto — I'd love to see it merged too! It's up to the OpenCode maintainers at this point. CI is green, the feature is complete, and it's been working well in my daily builds. Currently waiting on developer feedback / review. Fingers crossed! 🤞

@kfiramar

kfiramar commented Feb 4, 2026

Copy link
Copy Markdown

That'd be extremely helpful

@mguttmann
mguttmannforce-pushed the feat/oauth-multi-account branch 4 times, most recently from 82b0f3c to a0c9ca0CompareFebruary 5, 2026 09:38
@MiasmaAnagnorisis

Copy link
Copy Markdown

Thank you for implementing this! Really appreciate having legitimate multi-account OAuth rotation without needing workarounds.

@mguttmann
mguttmannforce-pushed the feat/oauth-multi-account branch 4 times, most recently from b2d82c0 to 484e508CompareFebruary 6, 2026 21:01
@rkdxodud-tyk

Copy link
Copy Markdown

Oh i need this

@mguttmann
mguttmannforce-pushed the feat/oauth-multi-account branch 2 times, most recently from 5f1e987 to 677c90dCompareFebruary 8, 2026 13:38
@mguttmann

Copy link
Copy Markdown
Author

Thanks for the feedback @RicardoMonteiroSimoes!

You raise a valid point about automatic failover. I'd be open to making it manual-only if that's what the maintainers prefer — the core value (switching between work/personal accounts without re-auth) would still be there.

That said, as long as there's no official feedback from the OpenCode developers, I'll keep the auto-switch functionality as-is. It's been working well in my daily builds and several community members have confirmed it works great for them too.

Unfortunately, it seems like this PR hasn't caught the maintainers' attention yet — no reviews or comments from the dev team so far. 🤷‍♂️

If any maintainers are reading this: I'm happy to adjust the implementation based on your feedback (e.g., remove auto-failover, make it a plugin, etc.). Just let me know what direction you'd prefer!

@RicardoMonteiroSimoes

Copy link
Copy Markdown

@mguttmann absolutely understandable, just thinking out loud from the PoV of a provider. To be fair their contribution guidelines do define that this should be first discussed in an issue... which exists, so who knows :)

@febryanvaldo

Copy link
Copy Markdown

Ahh never mind, just create my own account switcher without messing with OpenCode packages, so when OpenCode update, my account switcher will be good :D

image

...

image

@mguttmann
mguttmannforce-pushed the feat/oauth-multi-account branch from ed685f7 to 43f16aaCompareFebruary 18, 2026 06:34
@struct-eng-rigen

Copy link
Copy Markdown

Ahh never mind, just create my own account switcher without messing with OpenCode packages, so when OpenCode update, my account switcher will be good :D

image ... image

Why made your own ? I was wondering about building with this PR. Wasn't satisfactory for you ?

@febryanvaldo

febryanvaldo commented Feb 18, 2026

Copy link
Copy Markdown

Why made your own ? I was wondering about building with this PR. Wasn't satisfactory for you ?

Nope. If i'm using this PR, how about if there is a new OpenCode update?

@souhaiebtar

souhaiebtar commented Feb 18, 2026

Copy link
Copy Markdown

Ahh never mind, just create my own account switcher without messing with OpenCode packages, so when OpenCode update, my account switcher will be good :D
image

...
image

is it open source ? if not can you share it with us ?

@struct-eng-rigen

Copy link
Copy Markdown

session-context-tab.tsx Show active account per session

well how about it ? I guess you would just take the update

Claude Agent added 2 commits March 6, 2026 08:43
Add support for multiple OAuth accounts per provider with automatic
credential rotation and browser-based session management.
- Multi-account store: track multiple OAuth records per provider
- Credential rotation: automatically failover to next account on
rate limits or auth failures (rotating-fetch)
- Browser sessions: Puppeteer-based auto-relogin for expired tokens
- Credential manager: event-driven failover notifications
- AsyncLocalStorage auth context for per-request credential tracking
- Provider settings UI: manage accounts, set active, view usage
- Session context tab: show which account is active per session
- Config: oauth rotation settings (cooldowns, retries, max attempts)
- CLI: browser session management commands
- Server routes: account CRUD, usage, browser session endpoints
- SDK: regenerated with all new multi-account endpoints
Changed /auth/browser/sessions to /auth/browser-session to prevent
the @hey-api/sdk generator from creating duplicate Session2 class names
when both core session and browser session routes exist.
@mguttmann
mguttmannforce-pushed the feat/oauth-multi-account branch from 73e03be to 4f8c0bbCompareMarch 6, 2026 07:52
@kamushadenes

Copy link
Copy Markdown

Please merge that <3

@marcusquinn

Copy link
Copy Markdown

Might be useful to have some other time/token-%-use trigger for switching account when all sessions are idle, then just hitting the limit. So sharing token use per account evenly.

@saeedvaziry

Copy link
Copy Markdown
Contributor

This is a cool feature. is it gonna merge?

@NemesisHubris

Copy link
Copy Markdown

Have been having issue with this in resent builds.

@marcusquinn

Copy link
Copy Markdown

for anyone needing this, i've had it working reliably as an opencode plugin for some time in https://github.com/marcusquinn/aidevops/, including auto-rotate mid-session and with background workers

@MosfetWall

Copy link
Copy Markdown

Ahh never mind, just create my own account switcher without messing with OpenCode packages, so when OpenCode update, my account switcher will be good :D

image ... image

Any chance you are willing to opensource the plugin ?

@hildebrandt

Copy link
Copy Markdown

In the meantime, I’m using https://9router.com while I wait for this feature to be available.

@github-actionsgithub-actionsBot mentioned this pull request May 16, 2026
6 tasks
@mguttmannmguttmann closed this by deleting the head repository May 26, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Multi-Account OAuth Support with Auto-Relogin

20 participants

@mguttmann@dan-myles@NotFiliberto@kfiramar@MiasmaAnagnorisis@rkdxodud-tyk@patrick-zanzarini@dreadl0ck@tomasz-grabowski@IsraelAraujo70@lucashutch@Aaalice233@NemesisHubris@blurskye@febryanvaldo@RicardoMonteiroSimoes@struct-eng-rigen@souhaiebtar@kamushadenes@marcusquinn