Skip to content

zongmin-yu/codex-switch

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) - [email protected]
#   codex2 - [email protected]

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 [email protected]: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

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages