Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Codex Multi-Account Manager πŸš€

δΈ­ζ–‡ζ–‡ζ‘£ | English

A cross-platform tool for managing multiple OpenAI Codex accounts. Switch instantly between accounts without re-logging in!

✨ Features

  • πŸ”„ 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

πŸ“‹ Use Cases

  • βœ… Bypass single-account rate limits
  • βœ… Separate work and personal accounts
  • βœ… Use different Codex subscriptions for different projects
  • βœ… Sync account configs across multiple machines

πŸš€ Quick Start

1. Clone the Repository

cd ~
git clone https://github.com/zongmin-yu/codex-switch.git
cd codex-switch
chmod +x codex-switch

2. Save Your First Account

# 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

3. Save Your Second Account

# 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

4. Switch Between Accounts

# Switch to codex1
./codex-switch switch codex1

# Switch to work account
./codex-switch switch work

# List all accounts
./codex-switch list

πŸ“– Command Reference

save [name] - Save Current Login

# Auto-naming (codex1, codex2, codex3...)
./codex-switch save

# Custom name
./codex-switch save my-work-account
./codex-switch save school

switch <name> - Switch Account

./codex-switch switch codex1
./codex-switch switch work

# Short command
./codex-switch sw codex1

list - List All Accounts

./codex-switch list

# Output example:
# Available profiles:
#   codex1 (active) - alice@example.com
#   codex2 - bob@company.com

delete <name> - Delete Account

./codex-switch delete codex3
./codex-switch rm old-account

rename <old> <new> - Rename Account

./codex-switch rename codex1 work
./codex-switch mv codex2 personal

πŸ”§ Advanced Usage

Add to PATH (Recommended)

# 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

Create Alias (Even More Convenient)

# Add to ~/.zshrc or ~/.bashrc
alias cx='codex-switch'

# Usage
cx list
cx sw work

Custom Backup Directory

# 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"

🌍 Use on a New Machine

Method 1: Git Sync (Recommended)

# 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

Method 2: Manual Copy

# Just copy the backups/ directory
scp -r ~/codex-switch/backups user@remote:~/codex-switch/

⚠️ Security Notes

What's Safe to Commit to GitHub?

βœ… Safe to commit:

  • codex-switch script itself
  • README.md documentation
  • .gitignore file

❌ DO NOT commit:

  • backups/*.json files (contains your auth tokens)
  • .env or other files with secrets

Recommended .gitignore

# Don't commit account backups
backups/*.json

# But keep directory structure
!backups/.gitkeep

Private Repository Option

If you want to sync backups with Git, you have two options:

  1. 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
  2. Use Encryption

    # Use git-crypt or GPG to encrypt backups/ directory
    git-crypt init
    echo "backups/*.json filter=git-crypt diff=git-crypt" >> .gitattributes

πŸ› Troubleshooting

Error: Codex config directory not found

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 login

"Unauthorized" After Switching

Reason: Token expired (usually after 30 days)

Solution:

# Re-login and save
codex login
./codex-switch save codex1

Can't Recognize Email and Account Type

Reason: 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

πŸ“‚ Directory Structure

~/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

🀝 Contributing

Issues and Pull Requests are welcome!

πŸ“œ License

MIT License - Feel free to use!

πŸ™ Acknowledgments

Inspired by this Reddit post.


Made with ❀️ for Codex power users

Feel free to open an issue if you have any questions!

About

No description, website, or topics provided.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages