中文文档 | English
A cross-platform tool for managing multiple OpenAI Codex accounts. Switch instantly between accounts without re-logging in!
- 🔄 Instant Switching: Switch between accounts in seconds, no re-login required
- 🎯 Auto-naming: Automatically generates
codex1,codex2,codex3... as default names - 🌍 Cross-platform: Works on macOS, Linux, and Windows (Git Bash/WSL)
- 💾 Zero Sensitive Data: Only backs up
auth.json, tokens auto-refresh - 📦 Portable: Clone to a new machine and use directly, no re-login needed
- 🎨 Colored Output: Clear visual feedback
- ✅ Bypass single-account rate limits
- ✅ Separate work and personal accounts
- ✅ Use different Codex subscriptions for different projects
- ✅ Sync account configs across multiple machines
cd ~
git clone https://github.com/zongmin-yu/codex-switch.git
cd codex-switch
chmod +x codex-switch# Make sure you're logged into your first account
codex login
# Save as codex1 (auto-naming)
./codex-switch save
# Or use a custom name
./codex-switch save work# Logout from current account
codex logout
# Login with your second account
codex login
# Save as codex2 (auto-naming)
./codex-switch save
# Or use a custom name
./codex-switch save personal# Switch to codex1
./codex-switch switch codex1
# Switch to work account
./codex-switch switch work
# List all accounts
./codex-switch list# Auto-naming (codex1, codex2, codex3...)
./codex-switch save
# Custom name
./codex-switch save my-work-account
./codex-switch save school./codex-switch switch codex1
./codex-switch switch work
# Short command
./codex-switch sw codex1./codex-switch list
# Output example:
# Available profiles:
# codex1 (active) - [email protected]
# codex2 - [email protected]./codex-switch delete codex3
./codex-switch rm old-account./codex-switch rename codex1 work
./codex-switch mv codex2 personal# Add to ~/.zshrc or ~/.bashrc
echo 'export PATH="$HOME/codex-switch:$PATH"' >> ~/.zshrc
source ~/.zshrc
# Now you can use it anywhere
codex-switch list
codex-switch switch work# Add to ~/.zshrc or ~/.bashrc
alias cx='codex-switch'
# Usage
cx list
cx sw work# Temporary change
CODEX_ACCOUNT_BACKUP_DIR=/path/to/custom/dir ./codex-switch save
# Permanent change (add to ~/.zshrc)
export CODEX_ACCOUNT_BACKUP_DIR="$HOME/Dropbox/codex-backups"# On machine A
cd ~/codex-switch
git add backups/*.json
git commit -m "Add codex accounts"
git push
# On machine B
cd ~
git clone https://github.com/zongmin-yu/codex-switch.git
cd codex-switch
chmod +x codex-switch
# Switch directly, no login needed!
./codex-switch switch codex1# Just copy the backups/ directory
scp -r ~/codex-switch/backups user@remote:~/codex-switch/✅ Safe to commit:
codex-switchscript itselfREADME.mddocumentation.gitignorefile
❌ DO NOT commit:
backups/*.jsonfiles (contains your auth tokens).envor other files with secrets
# Don't commit account backups
backups/*.json
# But keep directory structure
!backups/.gitkeepIf you want to sync backups with Git, you have two options:
-
Use a Private Repository (Recommended)
# Create a private repo to sync account configs git remote add origin [email protected]:zongmin-yu/my-codex-accounts.git
-
Use Encryption
# Use git-crypt or GPG to encrypt backups/ directory git-crypt init echo "backups/*.json filter=git-crypt diff=git-crypt" >> .gitattributes
Reason: Codex not installed or never logged in
Solution:
# Install Codex
npm install -g @openai/codex
# Or use bun
bun install -g @openai/codex
# Login
codex loginReason: Token expired (usually after 30 days)
Solution:
# Re-login and save
codex login
./codex-switch save codex1Reason: jq tool not installed
Solution (optional, script functionality not affected):
# macOS
brew install jq
# Ubuntu/Debian
sudo apt install jq
# CentOS/RHEL
sudo yum install jq~/codex-switch/
├── codex-switch # Main script
├── README.md # English documentation
├── README_CN.md # Chinese documentation
├── backups/ # Account backup directory
│ ├── .gitkeep # Keeps directory structure
│ ├── codex1.json # First account
│ ├── codex2.json # Second account
│ └── work.json # Custom named account
└── .gitignore # Git ignore config
Issues and Pull Requests are welcome!
MIT License - Feel free to use!
Inspired by this Reddit post.
Made with ❤️ for Codex power users
Feel free to open an issue if you have any questions!