feat: add multi-account support with automatic rate limit rotation #97
+1,229
−138
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
codex-accountscommand for add/list/remove operations outside OAuth flowProblem
Heavy users of the Codex plugin frequently hit ChatGPT's rate limits, causing interruptions. Users with multiple ChatGPT subscriptions (personal, work, etc.) have no way to leverage them for increased throughput.
Solution
This PR implements multi-account management that:
Changes
lib/accounts/manager.tsAccountManagerclass with round-robin rotation, rate limit trackinglib/accounts/storage.ts~/.opencode/openai-codex-accounts.jsonlib/accounts/cli.tsscripts/manage-accounts.jscodex-accounts add/list/remove)lib/types.tsManagedAccount,AccountStorage,OAuthAuthDetails,RateLimitStatelib/constants.tsMAX_ACCOUNTS = 10lib/auth/auth.tsisOAuthAuth()andaccessTokenExpired()helpersindex.tstest/accounts.test.tspackage.jsoncodex-accountsbin entryHow It Works
Authentication Flow
Refresh Token Format
Multiple accounts are encoded in the refresh token field:
Rate Limit Handling
Retry-AfterheaderCLI Management
Storage Locations
~/.local/share/opencode/openai-codex-accounts.json~/.local/share/opencode/openai-codex-accounts.json%APPDATA%/opencode/openai-codex-accounts.jsonTesting
Added comprehensive test suite in
test/accounts.test.tscovering:Backwards Compatibility