Overview
Codex Multi-Auth implements a multi-account OAuth system that allows you to authenticate and manage multiple OpenAI accounts simultaneously. This enables seamless account rotation, load distribution, and quota management across your team’s accounts.OAuth Flow Architecture
PKCE (Proof Key for Code Exchange)
The plugin uses PKCE (RFC 7636) for secure OAuth authentication without client secrets:PKCE Implementation
The PKCE flow is implemented inlib/auth/auth.ts:220-243:
- S256 hashing of code verifier prevents interception attacks
- State parameter prevents CSRF attacks
- Local callback server (127.0.0.1:1455) keeps tokens on your machine
- No client secret required or stored
Token Management
Token Structure
Each authenticated account stores:JWT Decoding
Account identity is extracted from JWT tokens (lib/auth/auth.ts:139-154):
sub→accountIdemail→emailexp→ token expiry validation
Token Refresh
Automatic Refresh
Access tokens are automatically refreshed before expiry using the refresh queue to prevent race conditions:Refresh Guardian
The Proactive Refresh Guardian (lib/proactive-refresh.ts) refreshes tokens before they expire:
- Refreshes when < 5 minutes remaining
- Uses refresh lease to prevent concurrent refreshes
- Falls back to on-demand refresh if proactive refresh fails
Multi-Account Management
Adding Accounts
Add multiple accounts using:--force-new-login flag sets prompt=login to prevent browser session reuse.
Account Deduplication
Accounts are deduplicated by:- Refresh token (exact match)
- Account ID (from JWT)
- Email (case-insensitive, normalized)
Storage Locations
- Project-Scoped
- Global Fallback
.gitdirectorypackage.json- Other project markers
Security Considerations
Token Redaction
Sensitive parameters are automatically redacted in logs:OAuth Configuration
The plugin uses these OAuth constants (lib/auth/auth.ts:7-12):
openid- OpenID Connect authenticationprofile- User profile informationemail- User email addressoffline_access- Refresh token grant
Related Concepts
Account Rotation
Learn how accounts are selected and rotated based on health scores
Session Affinity
Understand how sessions stick to specific accounts
Quota Management
See how quotas are tracked and managed per account
Commands Reference
View all available CLI commands