cc-switch codex manages multiple OpenAI Codex CLI authentication configurations, supporting both OAuth (chatgpt) and API Key modes.
💡 All examples in this doc use the
cxalias (=cc-switch codex). Install the alias from the main README; if you haven't, just replacecxwithcc-switch codex.
# Import from an existing auth.json
cx add work --from-file # default: ~/.codex/auth.json
cx add work --from-file ~/.codex/auth.json # explicit path also supported
# Create interactively
cx add personal -i
# Create with an API key
cx add api-test --api-key sk-xxx
# Enter interactive mode
cx
# Switch to a configuration and launch Codex
cx use work| Command | What it does |
|---|---|
cc-switch codex |
Enter interactive mode (TUI) |
cc-switch codex add <name> |
Add new configuration |
cc-switch codex list |
List all configurations |
cc-switch codex use <name> |
Switch and launch Codex |
cc-switch codex remove <name...> |
Delete configurations |
# Import — alias is required (here: 'work')
cx add work --from-filecx add my-config -i
# Prompts:
# Auth mode (chatgpt/apikey) [chatgpt]:
# ID Token:
# Access Token:
# Refresh Token:
# Account ID:cx add api-only --api-key sk-xxxxxxxxcx add work --from-file -f# Enter the interactive selection interface
cxNavigation:
↑↓/jk: move up / down1-9: quick-select configuration on current pageN/PageDown: next pageP/PageUp: previous pageEnter: confirm selection, switch and launch CodexE: edit the selected configurationQ: quit without savingEsc: cancel
Each configuration displays:
- Auth mode (apikey / chatgpt)
- Account ID (chatgpt mode)
- API Key prefix (apikey mode)
- Last refresh time (if any)
# Switch and launch Codex
cx use work
# Switch and send a prompt
cx use work "Write a Python script for me"
# Switch and continue the most recent session
cx use work -c
# Switch and resume a specific session
cx use work -r <session-id>In interactive mode, select a configuration and press E to enter edit mode.
Editable fields:
| # | Field | Description |
|---|---|---|
| 1 | alias_name | Alias |
| 2 | auth_mode | Auth mode (chatgpt / apikey) |
| 3 | OPENAI_API_KEY | API key |
| 4 | id_token | ID token |
| 5 | access_token | Access token |
| 6 | refresh_token | Refresh token |
| 7 | account_id | Account ID |
| 8 | last_refresh | Last refresh time |
Edit mode controls:
- Enter a field number to modify it
- Press Enter to keep the current value; enter a space to clear optional fields
S: save changesQ: discard and go back
# List all Codex configurations (JSON format)
cx list
# Plain text format
cx list -p
# Remove a single configuration
cx remove work
# Remove multiple configurations
cx remove work personal testUses OpenAI account OAuth authentication with the following tokens:
id_token- identity tokenaccess_token- access tokenrefresh_token- refresh tokenaccount_id- account ID
Best for users with a ChatGPT Plus / Team / Enterprise subscription.
Uses an OpenAI API Key:
OPENAI_API_KEY- API key
Best for users on the pay-as-you-go API.
Codex configurations are stored alongside Claude configurations in ~/.claude/cc_auto_switch_setting.json.
When switching, the tool writes ~/.codex/auth.json, which the Codex CLI reads for authentication.