Overview
Codex Multi-Auth implements enterprise-grade storage safety features to protect your OAuth credentials and account data from corruption, concurrent access issues, and data loss.Storage v3 Format
The latest storage format provides improved structure and reliability.Per-Family Active Index
Tracks separate active accounts for each model family (GPT-5.x, Codex variants) to support family-specific routing.
Structured Rate Limits
Stores rate limit reset times per quota key (
codex:gpt-5-o1, codex:claude-5-sonnet) for accurate cooldown tracking.Enhanced Metadata
Includes accountId source tracking, account labels, cooldown reasons, and per-account enable/disable flags.
Backward Compatible
Automatically migrates v1 and v2 storage formats on first load with zero data loss.
Storage Structure
Field Reference
| Field | Type | Description |
|---|---|---|
version | number | Storage format version (always 3) |
activeIndex | number | Global active account index |
activeIndexByFamily | object | Per-model-family active account mapping |
accountId | string | Unique account identifier from OAuth |
accountIdSource | enum | Source of accountId: token, id_token, org, manual |
email | string | Account email (case-insensitive dedupe) |
accountLabel | string | User-assigned label for account |
refreshToken | string | OAuth refresh token (encrypted at rest) |
accessToken | string | Cached access token |
expiresAt | number | Token expiry timestamp (ms since epoch) |
enabled | boolean | Account enable/disable flag |
addedAt | number | Account creation timestamp |
lastUsed | number | Last successful request timestamp |
lastSwitchReason | enum | Why account was last switched: rate-limit, initial, rotation |
rateLimitResetTimes | object | Per-quota-key rate limit reset times |
coolingDownUntil | number | Cooldown expiry timestamp |
cooldownReason | enum | Cooldown trigger: auth-failure, network-error, rate-limit |
Atomic Write Strategy
All storage operations use atomic writes to prevent corruption from crashes or interruptions.Write-Ahead Logging (WAL)
- Crash recovery from WAL journal if main file corrupted
- Checksum validation prevents partial write corruption
- Platform-safe atomic rename (handles Windows EBUSY/EPERM)
Backup Files
Automatic backup before each write:- Primary file (
accounts.json) - WAL journal (
.wal) if primary corrupted - Backup file (
.bak) if both primary and WAL fail
Concurrency Safety
- Race conditions from concurrent plugin instances
- Partial writes from overlapping operations
- Lost updates from read-modify-write conflicts
Storage Locations
Global Storage
Default location for all accounts:- No project root detected
- Working outside a git repository
- Explicitly configured via
setStoragePathDirect()
Project-Scoped Storage
Per-project account isolation:- Working inside a git repository
- Project root detected via
.gitdirectory - Automatic
.gitignoreentry added for.codex/
Worktree Support
Linked worktrees share accounts via identity root resolution:- Detect
.gitfile (linked worktree indicator) - Parse
gitdir:path from.gitfile - Read
commondirto find repository root - Validate bidirectional gitdir reference
- Use common repository root for storage key
Automatic Migrations
Seamless upgrades from legacy formats:V1 → V3 Migration
Worktree-Keyed Storage Migration
Legacy worktree-specific storage is automatically migrated to shared repository storage:- Detect legacy worktree storage file
- Load and normalize legacy accounts
- Merge with current repository storage (dedupe by email/accountId)
- Persist merged storage to identity root
- Delete legacy file on success
- Retry-safe: preserves legacy file if merge fails
Deduplication
Automatic duplicate removal on every load:By Account Key
By Email (Case-Insensitive)
- Most recent
lastUsedtimestamp - If tied, most recent
addedAttimestamp
Error Handling
Storage Errors
| Code | Platform | Hint |
|---|---|---|
EACCES | Windows | Check antivirus exclusions for ~/.codex folder |
EPERM | Windows | Ensure write permissions, close editors accessing file |
EBUSY | Windows | File locked by another process, close conflicting programs |
ENOSPC | All | Disk full, free up space and retry |
EACCES | Linux/Mac | Run chmod 755 ~/.codex to fix permissions |
Retry Logic
Windows-specific retry for filesystem locks:Import/Export
Export Accounts
- Includes all accounts with full metadata
- Preserves v3 format structure
- Permissions:
0o600(owner read/write only) - Overwrites existing file (use
--no-forceto prevent)
Import Accounts
- Deduplicates by accountId and email
- Preserves most recent versions
- Fails if result exceeds max accounts (50)
- Validates schema before applying
Best Practices
Data Safety Recommendations
- Enable Backups: Keep
storageBackupEnabled: true(default) - Regular Exports: Run
codex auth exportbefore major operations - Monitor WAL: Persistent
.walfiles indicate write failures - Verify Migrations: Check account count after automatic migrations
- Gitignore: Ensure
.codex/is in.gitignoreto prevent credential leaks - Permissions: Storage files use
0o600(owner-only access) - Cleanup: Run
codex auth fixto deduplicate after imports
Related Settings
storageBackupEnabled- Enable/disable automatic backups (default:true)CODEX_PROJECT_ROOT- Override project root detection- Account limits defined in
ACCOUNT_LIMITS.MAX_ACCOUNTS(50)
Related Commands
codex auth fix- Repair storage issuescodex auth doctor- Diagnose storage health