Isolating Multiple Codex CLI Accounts on macOS Using CODEX_HOME
On macOS with zsh, you can avoid repetitive login/logout when using several Codex CLI accounts by copying the ~/.codex directory, setting distinct CODEX_HOME paths, and creating alias commands, allowing each account to maintain separate configurations, contexts, and quotas while sharing project rules via AGENTS.md.
If you need to use different Codex accounts for different projects, the most annoying part is not starting the CLI but repeatedly switching login states.
Background
Codex CLI normally uses a single local configuration and login state, which works fine for a single‑account workflow. When multiple accounts are required, they would otherwise share the same configuration directory, causing interference. The goal is not to open several terminals but to let each command use a separate Codex configuration directory.
Implementation Process
The idea is simple: copy the ~/.codex directory multiple times and point CODEX_HOME to a different directory when launching Codex.
# Prepare two new Codex configuration directories
cp -R ~/.codex ~/.codex-work1
cp -R ~/.codex ~/.codex-work2
# Open the zsh configuration file
sublime ~/.zshrcThen add the following aliases to ~/.zshrc:
alias codex-work1='CODEX_HOME=$HOME/.codex-work1 codex'
alias codex-work2='CODEX_HOME=$HOME/.codex-work2 codex'After saving, reload the shell configuration: source ~/.zshrc You can now invoke the aliases, for example:
codex → personal main account
codex-work1 → work account A
codex-work2 → work account BAll three commands run the same Codex CLI binary, but each uses a different CODEX_HOME directory.
Clarifications
01 Will using multiple accounts in parallel introduce account‑related risks?
The method does not bypass any account policies; it merely isolates local configuration and login state. Each account must still be logged in normally.
The advantage over manual login/logout is that each account has a fixed entry point, making it clear which environment you are in.
02 Will task performance degrade?
The account itself does not change the model’s capabilities. What matters is whether the appropriate context is provided and whether project rules are consistent.
Project‑wide rules are stored in AGENTS.md within the repository. Codex reads AGENTS.md from both the Codex home and the project directory and merges them, ensuring that multiple accounts working on the same repo share the same project‑level context.
Prompt caching in OpenAI is an optimization for latency and cost; it does not affect the final output and is not shared across organizations.
Therefore, explicit context files such as AGENTS.md, README, task descriptions, and any information you provide in the conversation remain the reliable source of truth.
03 How to reduce reliance on global configuration?
Copying the directory also copies the current login state. If you copy while logged in, the new directory may inherit that state, so after switching to an alias you should verify the login status and re‑login if necessary.
Prefer to keep shared project rules in the repository (e.g., AGENTS.md) and isolate account‑specific settings such as MCP, Skills, or personal preferences as needed.
Final Notes
This technique is suitable for users who frequently switch Codex CLI accounts. It is simple, requires no extra tools, and does not modify the Codex CLI itself.
Do not share these configuration directories with others.
Multiple directories can cause configuration drift (plugins, MCP, preferences may differ).
Reduce dependence on global configuration by maintaining shared rules in the repository, e.g., AGENTS.md.
If you only switch accounts occasionally, manual login/logout is acceptable. For daily switching, using distinct CODEX_HOME paths saves considerable effort.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Eric Tech Circle
Backend team lead & architect with 10+ years experience, full‑stack engineer, sharing insights and solo development practice.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
