Skip to content

feat: Multi-Account OAuth Support with Auto-Relogin #11830

@mguttmann

Description

@mguttmann

Summary

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
  • Credential manager (auth/credential-manager.ts): Event-driven failover notifications
  • Auth context (auth/context.ts): AsyncLocalStorage for per-request credential tracking
  • Config: oauth rotation settings (cooldowns, retries, max attempts)
  • CLI: Browser session management commands
  • Server routes: Account CRUD, usage, browser session endpoints

Frontend (packages/app)

  • Provider settings: Manage accounts, set active, view usage
  • Session context tab: Show which account is active per session

SDK

  • Regenerated with all new multi-account endpoints

Related

Split from #9971 (closed) for cleaner review.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions