-
Notifications
You must be signed in to change notification settings - Fork 6.9k
feat: Multi-Account OAuth Rotation with Settings UI and CLI Enhancements #9069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mguttmann
wants to merge
16
commits into
anomalyco:dev
Choose a base branch
from
mguttmann:feat/multi-account-oauth-rotation-and-settings
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: Multi-Account OAuth Rotation with Settings UI and CLI Enhancements #9069
mguttmann
wants to merge
16
commits into
anomalyco:dev
from
mguttmann:feat/multi-account-oauth-rotation-and-settings
+3,241
−102
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Non-network errors seen in logs: - AI_APICallError (402 deactivated_workspace) - AI_APICallError (500 server_error) - AI_LoadAPIKeyError / OpenAI API key is missing - ProviderInitError - ConfigInvalidError - ProviderAuthOauthCallbackFailed - NotFoundError - EditBuffer is destroyed
- Add getUsage() to fetch OAuth account status and health - Add fetchAnthropicUsage() to fetch Claude Max rate limits from Anthropic API - Add GET /auth/usage endpoint to expose usage data
- Add DialogAuthUsage component with rate limit visualization - Display Anthropic 5-hour and 7-day limits with progress bars - Show OAuth account status, cooldown state, and request counts - Add button in sidebar to open the dialog
- Add AuthUsageCommand to display rate limit info in terminal - Show account status, cooldown state, and request counts - Display Anthropic rate limits when available
The AI SDK's convertToModelMessages() does not accept 'step-start' as a valid UIMessagePart type. This caused AI_InvalidPromptError during session compaction. - Remove step-start from being added to UIMessage parts - Simplify the filter since step-start is no longer included - Fixes compaction breaking sessions with context overflow
## Summary Implements comprehensive multi-account OAuth support with automatic rate limit rotation, manual account switching, and a new Settings menu for the desktop app. ## Features ### Multi-Account OAuth Rotation (Backend) - Add `Auth.OAuthPool.setActive()` to manually switch active OAuth account - Add `Auth.OAuthPool.snapshot()` returns `activeID` for credential selection - Update `rotating-fetch.ts` to prefer `activeID` while keeping auto-rotation - Update `fetchAnthropicUsage()` to respect `provider.active[namespace]` - Update `getAccounts()` to correctly identify active account ### API Endpoints - Add `POST /auth/active` endpoint to switch active OAuth account - Returns updated `anthropicUsage` for immediate UI updates ### Desktop App - Settings Menu - New `DialogSettings` component with tabbed interface - **Providers Tab**: View connected providers, add new providers with search - **Provider Detail View**: Account list, usage stats, switch functionality - **About Tab**: GitHub, docs, Discord links, keyboard shortcuts - Inline provider search without leaving settings context ### Desktop App - Context Panel - Add Anthropic Rate Limits section in session context panel - Shows 5-hour, weekly (all models), weekly (sonnet) usage bars - Account switch buttons when multiple accounts configured - Only visible when current session uses Anthropic provider ### CLI Enhancements - `opencode auth usage`: Shows individual usage per OAuth account - `opencode auth switch`: Interactive command to switch active account - `opencode auth list`: Shows account count per provider - All provider lists now sorted alphabetically ## Technical Details ### Files Changed - `packages/opencode/src/auth/index.ts`: Core OAuth pool functions - `packages/opencode/src/auth/rotating-fetch.ts`: Credential selection - `packages/opencode/src/server/server.ts`: API endpoint - `packages/opencode/src/cli/cmd/auth.ts`: CLI commands - `packages/app/src/components/dialog-settings.tsx`: New settings UI - `packages/app/src/components/session/session-context-tab.tsx`: Context panel - `packages/app/src/pages/layout.tsx`: Settings button integration ### Auto-Rotation Flow 1. Request uses `activeID` (manually selected or first available) 2. On 429 rate limit → account gets cooldown, moved to back 3. Next request automatically uses next available account 4. Manual switch via UI/CLI updates `provider.active[namespace]` ### Anthropic Usage Stats Currently only Anthropic provides OAuth usage statistics. Other providers show multi-account switching but no usage bars. Contributions welcome for additional provider support.
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PRs Found#8590 - feat(auth): OAuth Marathon - multi-account credential rotation
#6905 - feat: display Anthropic and OpenAI OAuth usage in status dialog and sidebar
#5158 - add ratelimiter to opencode server
|
Author
Context on Related PRs
This PR represents the complete implementation of multi-account OAuth with:
All functionality has been tested and works together cohesively. |
- Add Auth.OAuthPool.removeRecord() to remove individual OAuth accounts - Add DELETE /auth/account API endpoint for Desktop app - Update CLI 'opencode auth logout' to select specific accounts - Add delete button with confirmation in Desktop Provider settings
This was referenced Jan 18, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 accountAuth.OAuthPool.removeRecord()- Delete individual OAuth accountsAuth.OAuthPool.snapshot()- ReturnsactiveIDfor credential selectionrotating-fetch.ts- PrefersactiveIDwhile preserving auto-rotation on 429fetchAnthropicUsage()- Respectsprovider.active[namespace]getAccounts()- Correctly identifies active accountAPI
POST /auth/active- Switch active account, returns updated usage dataDELETE /auth/account- Delete individual OAuth accountDesktop App
New Settings Menu (
DialogSettings):Context Panel:
CLI
opencode auth usage: Per-account usage with rate limitsopencode auth switch: Interactive account switchingopencode auth logout: Now supports selecting individual accounts to removeopencode auth list: Shows account countsDelete Individual Accounts
CLI
Desktop
In Settings → Providers → [Provider]:
Auto-Rotation Flow
Files Changed
auth/index.tsremoveRecord()auth/rotating-fetch.tsserver/server.ts/auth/activeand/auth/accountendpointscli/cmd/auth.tsdialog-settings.tsxsession-context-tab.tsxlayout.tsxsdk.gen.ts,types.gen.tsTesting
CLI
Desktop
Limitations
Checklist