Instantly switch between multiple Codex accounts — save, swap, and manage auth profiles.
Project description
codexswitcher
Instantly switch between multiple Codex accounts — save, swap, and manage auth profiles.
[!WARNING] Not affiliated with OpenAI or Codex. Not an official tool.
Codex stores your authentication session in a single ~/.codex/auth.json file. This file is shared by both the Codex CLI (codex) and the Codex desktop app (codex app). If you use separate personal and business accounts, moving between them means logging out and logging back in every time — in both the CLI and the app.
codexswitcher fixes that. It keeps named snapshots of your auth.json so you can switch between them instantly — no re-login required. A single switch updates auth for both the terminal and the desktop app.
Features
- Works with both CLI & app — one switch covers
codexandcodex app - Instant switching — swap
auth.jsonwith one command - Interactive picker — select from your saved accounts
- Atomic file operations — temp file +
os.replace(), never a corrupt state - Auto-backup — current auth backed up before every switch
- Hash-based detection — SHA-256 comparison identifies the active account
- Byte-perfect copies — original file format preserved exactly
- Secure permissions —
chmod 600enforced on all auth files - Auto-migration — seamlessly upgrades data from older
CodexSwitchinstalls
Requirements
- Python 3.12+
- uv (recommended) or pip
Don't have uv? Install it in one line:
# On macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
# Or, from PyPI
pip install uv
Installation
# Clone and install as a global CLI tool
git clone https://github.com/MohamedMohana/CodexSwitcher.git
cd CodexSwitcher
uv tool install .
After this, codexswitcher is available everywhere.
Quick Start
There is no account limit — save as many as you need. The interactive picker lets you choose from all of them.
# 1. Log in and save each account (repeat for as many as you have)
codexswitcher login personal
codexswitcher login business
codexswitcher login client-acme
codexswitcher login client-globex
# 2. See all your saved accounts
codexswitcher list
# 3. Switch between them — directly by name or interactively
codexswitcher use personal # direct
codexswitcher use # interactive picker (choose from table)
# 4. Check which one is active
codexswitcher current
Commands
codexswitcher login [name]
Log into a Codex account. Automatically kills any stale codex login process before starting, so you never get "port already in use" errors.
If you pass a name, it saves the account right after login. If you omit the name, it prompts you after a successful login.
# Login and save in one step
codexswitcher login personal
# Login first, then decide whether to save
codexswitcher login
This command:
- Kills any lingering
codex loginserver on port 1455 - Runs
codex login - Prompts you to save the new account (or saves automatically if you passed a name)
codexswitcher save <name>
Save the current ~/.codex/auth.json as a named profile.
codexswitcher save personal
codexswitcher save business
codexswitcher save client-project
Import from another file (e.g. a backup or an export from another machine) with --from:
codexswitcher save laptop-backup --from ~/Downloads/auth.json
When using --from, the imported snapshot is saved but the currently-active account pointer is left alone.
codexswitcher use [name]
Switch to a saved account. Pass the name directly, or omit it for an interactive picker.
# Switch directly
codexswitcher use personal
# Interactive picker — shows a table and prompts you
codexswitcher use
After switching, restart Codex if it is already running. This applies to both:
- The CLI (
codex) - The desktop app (
codex app)
codexswitcher list
List all saved accounts. * marks the active one, ~ marks the recorded current when live auth differs.
codexswitcher list
┏━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Status ┃ Account ┃ Auth Info ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ * active │ personal │ mode=chatgpt, id=9a86901f… │
│ │ business │ mode=chatgpt, id=7c3b2a… │
│ │ client-acme │ mode=chatgpt, id=f1d3e8… │
│ │ client-globex│ mode=api-key, api-key=yes │
└──────────┴──────────────┴─────────────────────────────┘
codexswitcher current
Show which account is currently active.
codexswitcher current
✓ personal (active)
mode=chatgpt, id=9a86901f...
codexswitcher clone <source> <new-name>
Duplicate a saved account under a new name. Useful when you want to keep one profile as a pristine backup before experimenting.
codexswitcher clone personal personal-backup
codexswitcher rename <old> <new>
Rename a saved account. Also moves its backup snapshot and updates the recorded-current pointer if it was the active one.
codexswitcher rename personal home
codexswitcher remove [name]
Remove a saved account. Pass the name directly, or omit it for an interactive picker. Prompts for confirmation unless you pass -y.
# Remove by name
codexswitcher remove old-account
codexswitcher remove old-account -y # skip confirmation
# Interactive picker — shows a table and prompts you
codexswitcher remove
codexswitcher doctor
Run diagnostic checks and print a summary — useful when something looks off or before filing a bug report. Verifies the codex CLI is on PATH, auth.json parses, and that all saved profiles have 0600 permissions.
codexswitcher doctor
Exits non-zero if any check fails.
codexswitcher list --json
Emit the saved accounts as machine-readable JSON. Handy for scripts:
codexswitcher list --json | jq -r '.[] | select(.is_active) | .name'
Shell completion
Tab completion is available via Typer. Install for the current shell with:
codexswitcher --install-completion
Or print the script and install it yourself with --show-completion.
codexswitcher --version
Show the installed version.
codexswitcher -v
codexswitcher --version
How It Works
~/.codex/
├── auth.json ← Live auth (both codex CLI & app read this)
└── .codexswitcher/
├── accounts/
│ ├── personal.auth.json ← Saved snapshot
│ ├── business.auth.json ← Saved snapshot
│ ├── client-acme.auth.json ← Saved snapshot
│ └── client-globex.auth.json ← Saved snapshot
├── backups/
│ └── business-backup.auth.json ← Auto-backup before switch
└── .current ← Tracks active account name
When you run codexswitcher save personal, it copies auth.json → personal.auth.json.
When you run codexswitcher use personal, it:
- Backs up the current
auth.json(if linked to a saved account) - Copies
personal.auth.json→auth.json(atomic replace) - Updates the
.currentstate file
Since both the CLI and the desktop app read from the same auth.json, a single switch updates auth for both.
Configuration
All paths can be overridden with environment variables:
| Variable | Default | Description |
|---|---|---|
CODEX_HOME |
~/.codex |
Codex config directory |
CODEX_AUTH_FILE |
$CODEX_HOME/auth.json |
Live auth file path |
CODEXSWITCHER_DIR |
$CODEX_HOME/.codexswitcher |
codexswitcher storage directory |
Upgrading from CodexSwitch
If you previously used CodexSwitch (the older name), codexswitcher automatically migrates your saved accounts on first run:
- Your old
~/.codex/.codexswitch/directory is moved to~/.codex/.codexswitcher/ - All saved accounts and the active account state are preserved
- No manual steps needed — just run any
codexswitchercommand
Development
# Clone the repo
git clone https://github.com/MohamedMohana/CodexSwitcher.git
cd CodexSwitcher
# Install with dev dependencies
uv sync --all-extras
# Activate the virtual environment (optional — lets you run commands without 'uv run')
# macOS / Linux
source .venv/bin/activate
# Windows
.venv\Scripts\activate
# Run tests
pytest -v
# Lint
ruff check src/ tests/
# Run locally without installing
codexswitcher --help
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codexswitcher-1.1.0.tar.gz.
File metadata
- Download URL: codexswitcher-1.1.0.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1e54f2a6e2cdab0c79263aa682be8aa183c1283102844e6bae48b045473ffc2
|
|
| MD5 |
933a0db74def1a13b89aaa89bde85cab
|
|
| BLAKE2b-256 |
1d2e7377f5d526415e49d28d906825ceca784d45ef33d12ec96257072a8c2232
|
Provenance
The following attestation bundles were made for codexswitcher-1.1.0.tar.gz:
Publisher:
publish.yml on MohamedMohana/CodexSwitcher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codexswitcher-1.1.0.tar.gz -
Subject digest:
a1e54f2a6e2cdab0c79263aa682be8aa183c1283102844e6bae48b045473ffc2 - Sigstore transparency entry: 2117594390
- Sigstore integration time:
-
Permalink:
MohamedMohana/CodexSwitcher@0d4c8823aaadfe98000d5779fa0b33fed89d9cdc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MohamedMohana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0d4c8823aaadfe98000d5779fa0b33fed89d9cdc -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file codexswitcher-1.1.0-py3-none-any.whl.
File metadata
- Download URL: codexswitcher-1.1.0-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a83ed3ca978b1a70c0cecaeacc2c004c2e2611aa93c4a061318b0946660e7bc
|
|
| MD5 |
faee6cf5af1f0d7734c935f0daef8958
|
|
| BLAKE2b-256 |
6be214156c62c5421d28c92246b77f6c817ca3282ec2027de305214ac76eb253
|
Provenance
The following attestation bundles were made for codexswitcher-1.1.0-py3-none-any.whl:
Publisher:
publish.yml on MohamedMohana/CodexSwitcher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codexswitcher-1.1.0-py3-none-any.whl -
Subject digest:
7a83ed3ca978b1a70c0cecaeacc2c004c2e2611aa93c4a061318b0946660e7bc - Sigstore transparency entry: 2117594433
- Sigstore integration time:
-
Permalink:
MohamedMohana/CodexSwitcher@0d4c8823aaadfe98000d5779fa0b33fed89d9cdc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/MohamedMohana
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0d4c8823aaadfe98000d5779fa0b33fed89d9cdc -
Trigger Event:
workflow_dispatch
-
Statement type: