How to use multiple Codex CLI accounts on one machine
Logging in to a second Codex account replaces the first one's sign-in. With a separate home per account, you can switch without logging out.
Updated
Codex CLI keeps its sign-in and everything else in one home directory, ~/.codex.
Give each account its own CODEX_HOME, and link only the configuration back to ~/.codex. Then they all get the same config, hooks and skills.
Don't link the whole home. One account's daemon or memories would end up serving another.
clausona sets that up in three commands:
clausona init # register the homes already signed in
clausona add codex:work # a second account, with Codex's own login
csn use codex:work # plain `codex` now starts as that account
Set it up by hand with CODEX_HOME
With one home there's one auth.json. Logging out and in replaces it, and two accounts can't run at once.
CODEX_HOME tells Codex which home to use, so an account can have a separate one. Keep ~/.codex as the main home and link the configuration into the second:
# a home for the second account
mkdir -p ~/.codex-work
# link the configuration both accounts should share
for item in config.toml hooks.json AGENTS.md rules skills plugins agents prompts; do
[ -e ~/.codex/$item ] && ln -sn ~/.codex/$item ~/.codex-work/$item
done
# sign in to the second account in its own home
CODEX_HOME=~/.codex-work codex login
config.toml holds your MCP servers and Codex profiles, so they're shared too.
Then add an alias:
alias codex-work='CODEX_HOME=~/.codex-work codex'
Keep the home's path short. Codex's app-server daemon puts a Unix socket inside CODEX_HOME. On macOS and Linux, a socket path can be only about 100 bytes long. Under a deep path, the daemon's auto-update stops without saying so. ~/.codex-work is fine.
What must stay with the account
Codex keeps more than configuration in its home. Each release adds a little more.
These belong to one account (checked with Codex CLI 0.159):
auth.jsonis the sign-in..credentials.jsonandsecrets/hold other tokens.app-server-control/andapp-server-daemon/. Codex starts a background app-server daemon and finds it throughapp-server-control/. A home that links the main one's talks to the main account's daemon, so Codex runs on the wrong account. Stopping the daemon in one home also stops the other's.memories/andmemories_1.sqlitehold summaries of past conversations, which Codex adds to future prompts. Share them, and one account's conversations reach the other account's prompts.- The other SQLite databases, with their
-waland-shmfiles. They hold one account's queues, logs and state. .env. Codex loads it into its environment at start, so it may hold one account's API keys.packages/is the daemon's install, about 300 MB. Share it, and one updater would replace the daemon that all the homes run.
So link an explicit list of entries, as above. Don't link the whole home and leave a few files out.
That way, a file a new Codex version adds stays with its account until you decide otherwise.
Or let clausona set it up
clausona is a free, open-source CLI that sets up the homes this way. It does the same for Claude Code. Install it:
curl -fsSL https://github.com/larcane97/clausona/releases/latest/download/install.sh | bash
irm https://github.com/larcane97/clausona/releases/latest/download/install.ps1 | iex
Sign in to Codex once as usual, then:
clausona init # registers ~/.codex and other homes already signed in
clausona add codex:work # makes ~/.codex-work and runs Codex's own login
csn use codex:work # plain `codex` now starts as the work account
clausona links only the entries on its list into a home. The rest stays with the account.
An older clausona version may have set up a home that still links account state, such as the daemon's directories or memories. clausona doctor reports it.
clausona repair <profile> unlinks it and puts the account's copy back from a backup. Nothing is deleted along the way.
csn is the short name for clausona.
A shell hook sets CODEX_HOME for the run and starts the real codex. There's no wrapper around Codex and nothing running in the background.
A plain codex launch skips clausona itself. clausona runs on the first launch after you change something, such as csn use codex:work. clausona run starts it every time, routed or not.
Resume conversations across accounts
Codex keeps conversations in sessions/, with history.jsonl and session_index.jsonl beside them. Three databases go with them:
state_5.sqlite, which Codex uses to find threadsgoals_1.sqlite, which keeps a thread's/goalthread_history_1.sqlite, which indexes the conversation files
Resuming under another account needs all of these shared together.
The databases need care. Link only the database file, never its -wal or -shm, because SQLite keeps those beside the file the link leads to.
With clausona, it's one switch per account.
First quit Codex in that account and stop its daemon:
CODEX_HOME=~/.codex-work codex app-server daemon stop
On macOS and Linux, clausona refuses to move files while either is running.
Then turn on shared history:
clausona config codex:work --merge-sessions
From then on, on macOS and Linux, codex resume and codex resume --last find threads from all the accounts that share history. A resumed thread's goal comes back with it.
Unlike Claude Code, the account's earlier Codex conversations aren't copied into the shared history. They're set aside in ~/.clausona/backups/codex/<profile>/ and come back with --separate-sessions.
Memories still stay with their account.
On Windows, the thread store stays per account, because SQLite there names its log after the path it was opened by. So a thread from another account is resumed by its id.
Run two accounts at once, and check their usage
csn use codex:work sets the account that new codex launches use. To run one session under another account without changing that:
clausona run codex:default
clausona list shows the 5-hour and weekly limits of your Codex accounts next to your Claude Code ones. It reads them from Codex's usage endpoint, with the login stored for the account.
Optimize usage across multiple accounts with dynamic routing
With two accounts, it's easy to burn through one while the other sits unused.
clausona's dynamic routing picks the account for you, every time a run starts. It reads each account's current 5-hour and weekly usage and starts on one with room. Accounts take turns, so usage spreads across all of them instead of piling onto one.
You set it up as a route, a named group of your accounts. A route is for Claude Code unless you add --tool codex:
clausona route add cx --tool codex # every Codex account, taking turns
clausona route explain cx # who a run would get now, and why
clausona run codex --route cx # Codex starts on that account
An account at 80% or more of its 5-hour or weekly limit sits out while another is still under 80%. The run names the account it got on one line.
A route doesn't need every account. clausona route add cx-work --tool codex --from '*@work.example' takes only the Codex accounts on your work email. After clausona route dir ~/work cx-work, a plain clausona run codex anywhere under ~/work starts on one of them.
Plain codex isn't routed. It still starts on the account csn use set.
If every account in the route is used up, nothing starts, and clausona says when each one resets. The routing docs cover the rest, including waiting for an account to free up.
The pick happens once, when the run starts. A running session never moves to another account.
Keep the accounts to what they're for, such as work and personal use, within OpenAI's terms.
Common questions
How do I switch Codex CLI accounts without logging out?
Give every account a separate CODEX_HOME, and sign in to it once with CODEX_HOME=<dir> codex login. Codex starts as whichever account's home it's pointed at. With clausona, run clausona add codex:work, then csn use codex:work.
Which files in ~/.codex can be shared between accounts?
The configuration. That's config.toml and any *.config.toml, hooks.json, AGENTS.md, rules/, skills/, plugins/, agents/ and prompts/. Keep auth.json, the app-server daemon's directories, memories, the databases, .env and packages/ with their account.
Why not share the whole ~/.codex directory?
Codex keeps account state in its home. A shared app-server-control/ makes Codex talk to another account's daemon and run on that account. Shared memories put one account's past conversations into another account's prompts.
Are Codex and Claude Code setups shared with each other?
No. Codex accounts share ~/.codex's configuration, and Claude Code accounts share ~/.claude's. The two tools stay separate.
Does clausona switch accounts when one reaches its limit?
A running session never moves to another account. With a route, clausona picks the account when a run starts. clausona run codex --route cx gets one of the route's Codex accounts that still has quota left. clausona use and clausona run <profile> leave the choice to you. Keep the accounts to what they're for, such as work and personal use, within OpenAI's terms.
What if I already set CODEX_HOME myself?
clausona steps aside in that shell, and Codex uses the home you set.
Get clausona
It's free and open source. If it spares you a few logins a day, a star on GitHub helps others find it.
It works the same way for Claude Code. See how to use multiple Claude Code accounts.