Managing multiple ChatGPT accounts in the Codex CLI can be useful for separating work and personal contexts, testing different configurations, or simply keeping conversations organized. However, doing this safely requires careful handling of credentials and switching only at appropriate moments. CodexMarathon provides a native, safe multi-account manager built directly into a custom build of the Codex CLI. It ensures that account changes happen only when no turn is running, preserving the integrity of active conversations and authentication state.
This article explains how to install and use CodexMarathon to manage multiple accounts, the safety model behind its switching mechanism, and the commands you need to get started.
What Is CodexMarathon?
CodexMarathon is a native feature of a custom Codex Rust CLI. It adds multi-account Marathon controls directly to the CLI, allowing you to sign in to more than one ChatGPT account and switch between them at safe boundaries. The release installer also installs and starts the private codexmarathon-accountd user service automatically—you do not need to run a controller command or configure a Marathon socket environment variable.
The tool stores managed account profiles, lets you sign in to multiple accounts, and switches only when all account-bound work is idle. Credential snapshots are opaque, protected by Codex’s configured credential storage, and never appear in status output, logs, or transition records. This design keeps your authentication data secure and your workflow predictable.
Installation and Setup
CodexMarathon is distributed as one package: the modified codex CLI, the private account metadata daemon, and its systemd user units are installed and started together. The installer enables the user service and socket, enables user lingering for operation after logout, and verifies the account API before reporting success.
To install, run:
curl -fsSL https://raw.githubusercontent.com/Lem0nTree/codexmarathon/main/scripts/install.sh | sh
If you need to use a non-default Codex state directory, pass an absolute path:
curl -fsSL https://raw.githubusercontent.com/Lem0nTree/codexmarathon/main/scripts/install.sh \
| CODEXMARATHON_CODEX_HOME=/srv/codex-state sh
The default remains $HOME/.codex. The local API socket always stays under $XDG_RUNTIME_DIR and does not move with CODEX_HOME.
After installation, you can verify the setup with codex marathon status. The CLI and the daemon work together seamlessly—no separate daemon, SDK, or plugin installation is required.
Safe Switching Mechanics
The core safety guarantee of CodexMarathon is that it never changes an active model response, tool call, or subagent turn. A switch waits until all account-bound work is idle. The source identity is checked again before a transition, and the target profile is validated and persisted atomically before Codex updates its in-memory credentials.
If a transition fails or is uncertain, it is recorded as such and requires reconciliation—Marathon never guesses that a credential change succeeded. This means you can rely on the fact that your active conversation is never interrupted mid-turn, and your credentials are never left in an inconsistent state.
Only managed ChatGPT authentication profiles are switchable initially. API keys, external bearer authentication, workload identity, and other unsupported provider modes are rejected for Marathon switching. This keeps the scope clear and avoids accidental misuse.
Using Marathon from the Shell
The native workflow is straightforward. You can manage accounts directly from the shell:
codex marathon status
codex marathon login personal --device-code
codex marathon login work --device-code
codex marathon on
codex marathon switch work
The login command supports both browser-link and device-code flows. For a headless machine such as an AWS instance, use a device code:
codex marathon login work --device-code
Codex prints a verification URL and one-time code. Open the URL on your own machine, enter the code, and complete the ChatGPT sign-in. Once Codex receives the native login completion, it stores that identity under the work alias.
You can also import an already active identity with codex marathon import <alias>. The switch command resolves an alias or account ID and changes the active identity only when no turn is running.
Interactive Commands
Inside a running Codex session, you can use the same controls as slash commands:
/marathon
/marathon status
/marathon on
/marathon off
/marathon import personal
/marathon login work
/marathon login work browser
/marathon login work device-code
/marathon switch work
Running /marathon displays the current native state and a help panel. It also explains the available account, login, enabled-state, and switching commands.
The login panel asks whether to use a browser link or a device/auth code. On a headless server, choose device code, open the displayed verification URL on another machine, and enter the one-time code. After native login completes, the identity is saved under the requested alias.
Status Line and Monitoring
You can configure the status line with the marathon and marathon-accounts items. They display whether native Marathon is enabled and the number of managed accounts. This gives you a quick visual cue about your current account state without interrupting your workflow.
For more detailed monitoring, the CLI provides:
codex marathon accounts
codex marathon status
These commands show only aliases, IDs, quota summaries, enabled state, and transition state. Credential snapshots are never printed.
Safety Model and Best Practices
CodexMarathon’s safety model is built around a few key principles:
- Turn-boundary switching: A switch is accepted only when all account-bound work is idle. This prevents mid-turn credential changes that could corrupt a conversation.
- Atomic persistence: Target credentials are validated and written atomically before Codex updates its in-memory authentication. A failed or uncertain transition is recorded as such and requires reconciliation.
- Opaque credentials: Credential snapshots are protected by Codex’s configured credential storage and never appear in status output, logs, or transition records.
- Provider support: Only managed ChatGPT authentication profiles are switchable. Unsupported modes are rejected.
To use CodexMarathon safely, follow these best practices:
- Always use the
--device-codeflow on headless servers to avoid exposing browser sessions. - Keep your aliases meaningful (e.g.,
personal,work) to avoid confusion. - Use
codex marathon offto disable automatic management while keeping profiles stored. - Regularly check
codex marathon statusto ensure transitions are clean and no reconciliation is pending.
Conclusion
CodexMarathon brings safe, native multi-account management to the Codex CLI. By switching only at safe turn boundaries and keeping credentials opaque, it lets you work with multiple ChatGPT accounts without risking conversation integrity or authentication state. Whether you’re on a local machine or a headless server, the installation is simple, and the commands are intuitive.
For more details, visit the CodexMarathon blog and the GitHub repository. There you’ll find architecture documentation, build instructions, and the full feature list.