δΈζζζ‘£ | 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) - alice@example.com
# codex2 - bob@company.com./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 git@github.com: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!