mcdx — switch between Codex auth profiles
mcdx is a small CLI for switching between saved
OpenAI Codex login credentials, so you can
use personal and work accounts on the same machine.
It manages only:
~/.codex/auth.json
It does not copy config.toml, sessions, history, SQLite state, plugins, skills,
or temporary runtime files. Runtime state and config.toml stay owned by Codex
itself — after a switch, mcdx asks Codex to restart its app-server daemon so
the new credentials are actually picked up.
Requirements
- Python 3.10+
- The
codexCLI on yourPATH(used bymcdx add, and to reload the app-server daemon afteradd/switch)
Install
# Recommended: pipx (isolated environment, mcdx lands on your PATH)
pipx install mcdx
# Or plain pip
pip install --user mcdx
Published on PyPI.
Install from a clone
git clone https://github.com/zackaryjing/multi-account-codex
mkdir -p ~/.local/bin
ln -sf "$PWD/multi-account-codex/mcdx.py" ~/.local/bin/mcdx
chmod +x multi-account-codex/mcdx.py
Make sure ~/.local/bin is on your PATH.
Usage
mcdx save-current main # save your current login as a profile
mcdx add alt # log in with Codex device auth, saved as a profile
mcdx list # list saved profiles (* marks the active one)
mcdx current # show the active profile
mcdx switch main # switch the active Codex auth
mcdx use main # alias for switch
mcdx update main # log in again to refresh an expired profile
mcdx remove old-name # delete a profile
mcdx rename a b # rename a profile
mcdx proxy set http://127.0.0.1:10808 # proxy for codex logins and daemon restarts
mcdx daemon restart # restart the Codex app-server daemon (picks up the proxy)
mcdx doctor # check paths, Codex binary, proxy and daemon status
mcdx add, mcdx update, and mcdx switch accept:
| Flag | Effect |
|---|---|
-y, --yes |
answer yes to prompts, including the daemon restart |
--no-daemon-restart |
leave the Codex app-server daemon running as it is |
Where things live
Profiles are stored under:
~/.local/share/mcdx/profiles/<name>/
Each profile contains an auth.json copy and metadata.json. Credentials are
not encrypted — the profiles directory is created with 0700 permissions.
Environment overrides:
| Variable | Default | Purpose |
|---|---|---|
MCDX_CODEX_HOME |
~/.codex |
Codex home directory |
MCDX_DATA_HOME |
~/.local/share/mcdx |
mcdx data directory |
MCDX_CODEX_BIN |
codex |
Codex binary for add and daemon restarts |
MCDX_PROXY |
(unset) | proxy URL for codex subprocesses, overriding the stored config |
Proxy
On machines that can only reach chatgpt.com through a local proxy (e.g.
v2rayN/Clash behind mirrored WSL networking), both codex login and the
long-lived app-server daemon need the proxy in their environment. Configure it
once per machine:
mcdx proxy set http://127.0.0.1:10808
mcdx then injects http_proxy/https_proxy/all_proxy into every codex
subprocess it spawns:
mcdx add/mcdx updatedevice-auth logins- app-server daemon restarts (after
add/switch/update, andmcdx daemon restart)
Since daemons inherit their environment at spawn time, mcdx daemon restart is
also the recovery command when a daemon was started elsewhere without the
proxy and codex hangs on network errors.
mcdx cannot affect codex processes you start yourself — launch those with the
proxy already in your shell environment (or through a wrapper that exports
it). mcdx proxy show displays the active value, mcdx proxy clear removes
it, and MCDX_PROXY overrides the stored config for one invocation.
Behavior
mcdx add <name>temporarily moves the active auth aside, runscodex login --device-auth, saves the resultingauth.json, and leaves the new profile active.mcdx update <name>re-runs that login flow for an existing profile and replaces its credentials in place, so an expired profile can be refreshed withoutremove+add. On failure the profile and the active auth are left untouched.mcdx switch <name>saves the current auth as_lastbefore switching.- Duplicate credentials are detected by
account_idandauth.jsonSHA-256. - An interrupted
add/updateis rolled back immediately for catchable exits (Ctrl+C, SIGTERM/SIGHUP from a closing terminal) and on the nextmcdxrun for a hard kill, via a journal under the data directory. - Codex keeps a long-lived app-server daemon that reads
auth.jsononce at startup, and sessions talk to that daemon rather than to the file. Afteradd/switch, mcdx therefore runscodex app-server daemon restart; without it the daemon keeps serving the previous account no matter whatauth.jsonsays. mcdx asks first (default yes) when it can, and never restarts a daemon that is not running. Restarting interrupts any codex sessions live on that daemon, so scripts should pass-yto accept that, or--no-daemon-restartand reload later.
Development
python3 tests.py # run the test suite
License
Metadata
Release files for mcdx 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mcdx-0.4.0.tar.gz | 12.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcdx-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.6 kB
Release files / mcdx-0.4.0.tar.gz
| Download URL | mcdx-0.4.0.tar.gz |
|---|---|
| Size | 12.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f050ef3b6e327522b68f34a808e0aa54c3c621f8562d8b34aef71737f7fe95e
|
|
BLAKE2b-256 checksum How to use checksums |
229ae1bde4dea759fad5debec7ec2cf280a3d49d0bfaf26cb9175d63a0b17450
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.2
|
Release files / mcdx-0.4.0-py3-none-any.whl
| Download URL | mcdx-0.4.0-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e6e192e9d3ba24c251ec958d2ee9844cc51b18426159e6f9ade1cde53a135be
|
|
BLAKE2b-256 checksum How to use checksums |
1b64bf3225e135984cbb099781424d5f01a361bf007e203d07c3e1dddd529c16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.2
|
Security for mcdx 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.