Guide
CODEX_HOME, explained.
CODEX_HOME tells Codex where its state lives. By default that's ~/.codex. Change it and Codex behaves like a fresh install there.
What's inside
| In CODEX_HOME | What it is |
|---|---|
| auth.json | Your login: ChatGPT tokens, or an API key |
| config.toml | Model, approval and sandbox settings, MCP servers, profiles |
| AGENTS.md | Your personal instructions for every project |
| sessions/ | Transcripts of your sessions, so you can resume them |
| history.jsonl | Your prompt history |
| prompts/, skills/, rules/ | Custom prompts, skills and rules, if you use them |
| log/ | Logs |
What exactly is there depends on your Codex version and which features you use.
How to set it
mkdir -p ~/.codex-work # must exist before Codex starts
CODEX_HOME=~/.codex-work codex # one run
export CODEX_HOME=~/.codex-work # the rest of this shell
The folder has to exist already; Codex doesn't create it for you when the variable is set.
What people use it for
Several accounts
One folder per account, each signed in once. Work and personal run side by side. The full setup.
A clean test setup
Try a new MCP server or config.toml change in a throwaway folder without touching your real one.
CI and scripts
Point CI at a folder that holds only what the job needs, so a build never picks up your personal setup.
Things to know
- Keyring logins. If
cli_auth_credentials_storeinconfig.tomlsends your login to the system keyring instead ofauth.json, it's still kept per folder, so separate folders stay separate accounts. - Your shell wins. A
CODEX_HOMEexported in~/.zshrcapplies to every terminal. Prefer setting it per command or per alias. - The Codex app uses
~/.codextoo, and needs one more setting to run a second account. How.
Questions
What is CODEX_HOME?
An environment variable that sets the folder where Codex keeps its state: login, config, sessions, history and logs. It defaults to ~/.codex.
Does the CODEX_HOME folder have to exist?
Yes. When you set CODEX_HOME, create the folder first; Codex expects it to exist.
Can I share config.toml between two CODEX_HOME folders?
Yes, with a symlink from one folder to the other. Only the login and history then stay separate.
Switch for Codex does this with one click on a Mac: every account in its own Codex app window and in your terminal, all open at once, from the app or the menu bar. $9.99 once, no subscription.