[PR #9069] feat: Multi-Account OAuth Rotation with Settings UI and CLI Enhancements #12971

Closed
opened 2026-02-16 18:17:51 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9069

State: closed
Merged: No


Summary

Implements comprehensive multi-account OAuth support with automatic rate limit rotation, manual account switching, ability to delete individual accounts, and a new Settings menu for the desktop app.

Closes #9068

Changes

Backend - OAuth Pool Enhancements

  • Auth.OAuthPool.setActive() - Manually switch active OAuth account
  • Auth.OAuthPool.removeRecord() - Delete individual OAuth accounts
  • Auth.OAuthPool.snapshot() - Returns activeID for credential selection
  • rotating-fetch.ts - Prefers activeID while preserving auto-rotation on 429
  • fetchAnthropicUsage() - Respects provider.active[namespace]
  • getAccounts() - Correctly identifies active account

API

  • POST /auth/active - Switch active account, returns updated usage data
  • DELETE /auth/account - Delete individual OAuth account

Desktop App

New Settings Menu (DialogSettings):

  • Providers Tab: Connected providers, add new with search
  • Provider Detail: Account list, usage bars, switch functionality
  • Delete Button: Remove individual accounts with confirmation
  • About Tab: GitHub, docs, Discord, keyboard shortcuts

Context Panel:

  • Anthropic Rate Limits section (5h, 7d-all, 7d-sonnet bars)
  • Account switch buttons
  • Only visible for Anthropic sessions

CLI

  • opencode auth usage: Per-account usage with rate limits
  • opencode auth switch: Interactive account switching
  • opencode auth logout: Now supports selecting individual accounts to remove
  • opencode auth list: Shows account counts
  • All lists sorted alphabetically

Delete Individual Accounts

CLI

$ opencode auth logout

┌  Remove credential
│
◆  Select provider
│  ● Anthropic (oauth)
│
◆  Remove which account?
│  ○ Remove all accounts (3 accounts)
│  ○ Account 1
│  ○ Account 2 
│  ● Account 3
│
◐  Account removed. 2 accounts remaining.
│
└  Done

Desktop

In Settings → Providers → [Provider]:

  • Each account has a delete button (X icon)
  • Two-step confirmation to prevent accidents
  • Shows loading state during deletion
  • Auto-navigates back when last account is removed

Auto-Rotation Flow

1. Request with activeID (manually selected or first available)
2. On 429 rate limit:
   - Account gets cooldownUntil
   - Account moved to back of queue
   - Loop continues with next candidate
3. Next available account used automatically

Files Changed

Package File Description
opencode auth/index.ts Core OAuth pool functions incl. removeRecord()
opencode auth/rotating-fetch.ts Credential selection logic
opencode server/server.ts /auth/active and /auth/account endpoints
opencode cli/cmd/auth.ts CLI commands with logout account selection
app dialog-settings.tsx Settings dialog with delete buttons
app session-context-tab.tsx Context panel usage section
app layout.tsx Settings button
sdk sdk.gen.ts, types.gen.ts Regenerated

Testing

CLI

opencode auth list      # Shows providers with account counts
opencode auth usage     # Shows per-account stats with rate limits
opencode auth switch    # Interactive account switching
opencode auth logout    # Select individual accounts to remove

Desktop

  1. Click ⚙️ Settings button → Providers tab
  2. Click connected provider → View accounts and usage
  3. Switch accounts → Verify bars update
  4. Click X on account → Confirm deletion
  5. Open Anthropic session → Context panel shows rate limits

Limitations

  • Usage statistics: Anthropic only (OAuth API limitation)
  • Multi-account: Anthropic, OpenAI, GitHub Copilot
  • Other providers: Contributions welcome

Checklist

  • Backend OAuth pool enhancements
  • API endpoints for account switching and deletion
  • Desktop Settings menu with delete buttons
  • Context panel integration
  • CLI commands with logout account selection
  • Alphabetical sorting
  • Auto-rotation preserved
  • Local state updates (no full refresh on switch)
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9069 **State:** closed **Merged:** No --- ## Summary Implements comprehensive multi-account OAuth support with automatic rate limit rotation, manual account switching, ability to delete individual accounts, and a new Settings menu for the desktop app. Closes #9068 ## Changes ### Backend - OAuth Pool Enhancements - **`Auth.OAuthPool.setActive()`** - Manually switch active OAuth account - **`Auth.OAuthPool.removeRecord()`** - Delete individual OAuth accounts - **`Auth.OAuthPool.snapshot()`** - Returns `activeID` for credential selection - **`rotating-fetch.ts`** - Prefers `activeID` while preserving auto-rotation on 429 - **`fetchAnthropicUsage()`** - Respects `provider.active[namespace]` - **`getAccounts()`** - Correctly identifies active account ### API - **`POST /auth/active`** - Switch active account, returns updated usage data - **`DELETE /auth/account`** - Delete individual OAuth account ### Desktop App **New Settings Menu (`DialogSettings`):** - **Providers Tab**: Connected providers, add new with search - **Provider Detail**: Account list, usage bars, switch functionality - **Delete Button**: Remove individual accounts with confirmation - **About Tab**: GitHub, docs, Discord, keyboard shortcuts **Context Panel:** - Anthropic Rate Limits section (5h, 7d-all, 7d-sonnet bars) - Account switch buttons - Only visible for Anthropic sessions ### CLI - **`opencode auth usage`**: Per-account usage with rate limits - **`opencode auth switch`**: Interactive account switching - **`opencode auth logout`**: Now supports selecting individual accounts to remove - **`opencode auth list`**: Shows account counts - All lists sorted alphabetically ## Delete Individual Accounts ### CLI ```bash $ opencode auth logout ┌ Remove credential │ ◆ Select provider │ ● Anthropic (oauth) │ ◆ Remove which account? │ ○ Remove all accounts (3 accounts) │ ○ Account 1 │ ○ Account 2 │ ● Account 3 │ ◐ Account removed. 2 accounts remaining. │ └ Done ``` ### Desktop In **Settings → Providers → [Provider]**: - Each account has a delete button (X icon) - Two-step confirmation to prevent accidents - Shows loading state during deletion - Auto-navigates back when last account is removed ## Auto-Rotation Flow ``` 1. Request with activeID (manually selected or first available) 2. On 429 rate limit: - Account gets cooldownUntil - Account moved to back of queue - Loop continues with next candidate 3. Next available account used automatically ``` ## Files Changed | Package | File | Description | |---------|------|-------------| | opencode | `auth/index.ts` | Core OAuth pool functions incl. `removeRecord()` | | opencode | `auth/rotating-fetch.ts` | Credential selection logic | | opencode | `server/server.ts` | `/auth/active` and `/auth/account` endpoints | | opencode | `cli/cmd/auth.ts` | CLI commands with logout account selection | | app | `dialog-settings.tsx` | Settings dialog with delete buttons | | app | `session-context-tab.tsx` | Context panel usage section | | app | `layout.tsx` | Settings button | | sdk | `sdk.gen.ts`, `types.gen.ts` | Regenerated | ## Testing ### CLI ```bash opencode auth list # Shows providers with account counts opencode auth usage # Shows per-account stats with rate limits opencode auth switch # Interactive account switching opencode auth logout # Select individual accounts to remove ``` ### Desktop 1. Click ⚙️ Settings button → Providers tab 2. Click connected provider → View accounts and usage 3. Switch accounts → Verify bars update 4. Click X on account → Confirm deletion 5. Open Anthropic session → Context panel shows rate limits ## Limitations - Usage statistics: Anthropic only (OAuth API limitation) - Multi-account: Anthropic, OpenAI, GitHub Copilot - Other providers: Contributions welcome ## Checklist - [x] Backend OAuth pool enhancements - [x] API endpoints for account switching and deletion - [x] Desktop Settings menu with delete buttons - [x] Context panel integration - [x] CLI commands with logout account selection - [x] Alphabetical sorting - [x] Auto-rotation preserved - [x] Local state updates (no full refresh on switch)
yindo added the pull-request label 2026-02-16 18:17:51 -05:00
yindo closed this issue 2026-02-16 18:17:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12971