Skip to main content

Switch between OpenAI Codex CLI provider configurations (official ChatGPT login, third-party relays, multiple API keys). CLI + Alfred workflow.

Project description

codex-profile-switcher

PyPI CI

One-key switch between OpenAI Codex CLI configurations — official ChatGPT login, third-party relays, multiple API keys, whatever. CLI + optional Alfred workflow.

Each profile owns the provider slice of ~/.codex/config.toml (model, [model_providers.*], auth method) plus its own auth.json. Your local state (trusted projects, plugins, marketplaces, MCP servers, TUI prefs) is left untouched on every switch.

Install

Requires uv.

uv tool install codex-profile-switcher

This puts codex-switch on $PATH (default ~/.local/bin/). Run uv tool update-shell once if your shell can't find it.

Upgrade later with uv tool upgrade codex-profile-switcher; uninstall with uv tool uninstall codex-profile-switcher.

No-install (one-off)

uvx --from codex-profile-switcher codex-switch ls

uvx resolves and caches an ephemeral environment per invocation. Convenient for trying it out, slower for hot paths like Alfred — use uv tool install if you want the workflow to feel snappy.

Development version

Install directly from GitHub when you want the latest commit before it is released to PyPI:

uv tool install git+https://github.com/kadaliao/codex-profile-switcher.git

Alfred (optional)

After uv tool install, double-click alfred/codex-profile-switcher.alfredworkflow. Trigger with keyword cx.

The workflow calls $HOME/.local/bin/codex-switch; if uv tool install put the binary elsewhere (uv tool dir --bin to check), edit the two script blocks in the workflow's plist accordingly.

CLI

codex-switch              # interactive picker (↑/↓, enter to switch, q to cancel)
codex-switch ls           # list profiles, ★ marks the active one
codex-switch current      # print the active profile
codex-switch official     # switch back to official OpenAI ChatGPT login
codex-switch openai       # alias of `official`
codex-switch use [name]   # load <name>; omit for the picker
codex-switch save <name>  # snapshot the current ~/.codex state as <name>
codex-switch show <name>  # print <name>'s provider.toml + auth.json key names
codex-switch state <name> # show/set the session-state scope for a profile
codex-switch merge-history --dry-run
                           # preview history metadata changes without writing files
codex-switch doctor-history
                           # inspect current history provider/model state read-only
codex-switch rm <name>    # delete profile (the active one is protected)
codex-switch alfred-list  # JSON for Alfred Script Filter

The picker auto-falls back to a numeric menu when stdin/stdout aren't TTYs (pipes, scripts).

Official OpenAI shortcut

codex-switch official is the one-step way back to the official OpenAI ChatGPT login.

  • The tool keeps a hidden ~/.codex/profiles/.official/ snapshot for the official config/auth.
  • The first time you switch away from an official OpenAI session, that snapshot is refreshed automatically.
  • codex-switch openai is an alias if you prefer typing the provider name directly.

Shared history by default

After every use / official switch, codex-switch automatically aligns local Codex history metadata to the active provider and model identity.

  • You no longer need to remember merge-history during normal profile switching.
  • This keeps session history visible when moving between relay profiles and the official OpenAI login, including surfaces that filter by model id.
  • merge-history --keep-models still exists if you want a provider-only repair and need to preserve historical per-thread model ids.
  • merge-history --dry-run reports rollout files/lines, SQLite rows, and the backup path it would create without writing anything.
  • doctor-history is read-only and summarizes the active profile, current provider/model, session-state mode, SQLite threads distribution, recent threads, planned alignment counts, and provider/model drift.

Profile format

~/.codex/profiles/
├── .active                       # plaintext: name of the active profile
├── chatgpt-official/
│   ├── auth.json                 # full file copied into ~/.codex/auth.json
│   └── provider.toml             # empty = use ChatGPT login
└── myrelay/
    ├── auth.json                 # {"OPENAI_API_KEY": "sk-..."}
    └── provider.toml             # only provider-related keys (see examples/)

The following top-level keys + tables are owned by a profile (swapped on use); everything else in ~/.codex/config.toml is preserved:

  • model, model_provider, model_reasoning_effort, model_reasoning_summary, model_verbosity
  • wire_api, disable_response_storage, preferred_auth_method
  • [model_providers.*]

Adding a relay profile

  1. Configure the relay normally in ~/.codex/{config.toml,auth.json} and verify codex works.
  2. codex-switch save <name> — snapshots the provider slice + auth.json into a new profile.
  3. cx in Alfred (or codex-switch use <name>) to switch anytime.

Or build the files by hand — see examples/relay-profile/.

Env overrides

Var Default Purpose
CODEX_PROFILE_ROOT ~/.codex/profiles where profiles live
CODEX_HOME ~/.codex the codex config dir to write

Releasing

Packages are published on PyPI as codex-profile-switcher.

Automated releases use GitHub Actions and PyPI Trusted Publishing:

  1. Update version in pyproject.toml.

  2. Run uv run python -m unittest tests.test_cli and uv build.

  3. Commit the version bump and push main.

  4. Create and push a matching tag:

    git tag vX.Y.Z
    git push origin vX.Y.Z
    

The Publish to PyPI workflow verifies that the tag version matches pyproject.toml, runs tests, builds the wheel and sdist, checks the distributions, and publishes them to PyPI. Manual local publishing is still possible with uvx twine upload dist/* when needed.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codex_profile_switcher-0.5.0.tar.gz (147.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codex_profile_switcher-0.5.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file codex_profile_switcher-0.5.0.tar.gz.

File metadata

  • Download URL: codex_profile_switcher-0.5.0.tar.gz
  • Upload date:
  • Size: 147.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for codex_profile_switcher-0.5.0.tar.gz
Algorithm Hash digest
SHA256 25b75ce1138a1140a07a6453ceb40b12fb9734620106e0bfa8767f847ed8b53b
MD5 f84f4c37d9aab44d0fce115f1f8f83cc
BLAKE2b-256 86423c12843bac67bba5e330a20b097f97c16c23775a8378d7c29a9dd8bd4385

See more details on using hashes here.

File details

Details for the file codex_profile_switcher-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for codex_profile_switcher-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 066c098015312e1df3b1dbd42b2eb4c5fe3452434f816dc740f727c6974e5bb7
MD5 49030496f161104181b8352c4595c9a8
BLAKE2b-256 a2ae997daf71caad7d9ba3c3f698c4ba7a8cbd3cc31c807413000a2a2e55cbe0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page