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.
Pull Request: Multi-Account Support with Automatic Failover
🎯 Goal
Implement multi-account support for OpenCode Anthropic authentication with automatic failover when rate limits are encountered.
📋 Issue Reference
Closes #23
🚀 Features Added
✅ Core Multi-Account Functionality
retry-afterheaders✅ CLI Management Tool (
multi-auth-cli.mjs)✅ In-Session Status Tool
✅ Backwards Compatibility
🧪 Testing
CLI Tool Tests
Example Output
📁 Files Added
Core Implementation
index-multi-auth.mjs- Enhanced plugin with multi-account support and failover logicmulti-auth-config.js- Configuration structures and utility functionsmulti-auth-cli.mjs- Standalone CLI management toolDocumentation & Migration
README-MULTI-AUTH.md- Comprehensive user documentationIMPLEMENTATION-SUMMARY.md- Technical implementation detailsmigrate-multi-auth.mjs- Migration and test setup toolConfiguration
package.json- Updated with"type": "module"for ES modules🔄 How Automatic Failover Works
Rate Limit Detection: When a request returns 429 status:
retry-afterheader for wait timeAccount Switching: If auto-failover is enabled:
Token Refresh: Automatically refreshes expired tokens before making requests
Fallback: If all accounts are rate-limited, returns appropriate error message
🏗️ Architecture
Configuration Storage
Accounts are stored in
~/.config/opencode/multi-auth.json:{ "type": "multi-oauth", "accounts": [ { "id": "account-1234567890", "label": "Personal", "access": "oauth_access_token", "refresh": "oauth_refresh_token", "expires": 1704067200000, "rateLimitedUntil": null, "mode": "max" } ], "currentAccountIndex": 0, "autoFailover": true }Rate Limit Tracking
rateLimitedUntiltimestamps for each account🎓 GSoC Contribution
This implementation demonstrates:
📊 Impact
For Users
For Developers
🔧 Installation & Usage
Quick Start
Migration
Existing single-account users are automatically migrated when adding their first multi-account.
🧪 Development Testing
✅ Checklist
🎉 Ready for Review
This implementation provides a complete solution for multi-account support with automatic failover, making it perfect for users with multiple Claude subscriptions who want uninterrupted productivity. The code is well-documented, thoroughly tested, and ready for production use.