Research date: 2026-05-18.
Versions checked:
- Codex CLI: local
@openai/codex/codex-cli 0.130.0. - Gemini CLI: npm
@google/gemini-cli 0.42.0. - Claude Code: npm
@anthropic-ai/claude-code 2.1.143.
The most reliable shape is process-level isolation: start each CLI with a profile-specific config/home directory and profile-specific environment. Do not hot-swap the credential file under an active process unless the CLI explicitly supports a dynamic credential provider.
| CLI | Independent environments | Dynamic credentials | External hot swap while running |
|---|---|---|---|
| Codex | Yes: CODEX_HOME, preferably with file-backed auth. |
Yes for custom providers via model_providers.<id>.auth.command; built-in OpenAI login mainly supports cached auth plus token refresh. |
Not a supported identity-switch mechanism. Start a new process for a different account. |
| Gemini | Yes: GEMINI_CLI_HOME, with caveats for keychain-backed saved API keys. |
Limited: environment variables and stored auth are selected at launch; no general model-auth helper equivalent was found. | Not reliable. Interactive /auth exists, but external file/env swaps are not a supported live switch. |
| Claude | Yes on Linux/Windows: CLAUDE_CONFIG_DIR. macOS credentials use Keychain, so use env tokens, a separate OS user/keychain, or explicit reauth for strict separation. |
Yes: apiKeyHelper, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY, and CLAUDE_CODE_OAUTH_TOKEN; apiKeyHelper refreshes on an interval or HTTP 401. |
Helper-based rotation works. Editing credential files or parent env does not reliably change an already-running process. |
Use directories outside the repo:
~/.ai-cli-profiles/
codex/work/
config.toml
auth.json
gemini/work/
.gemini/
settings.json
oauth_creds.json
.env
claude/work/
settings.json
.credentials.json
Recommended launch approach:
CODEX_HOME="$HOME/.ai-cli-profiles/codex/work" codex
GEMINI_CLI_HOME="$HOME/.ai-cli-profiles/gemini/work" GEMINI_FORCE_FILE_STORAGE=true gemini
CLAUDE_CONFIG_DIR="$HOME/.ai-cli-profiles/claude/work" claudeTreat profile directories as secrets. Do not commit them, sync them casually, or share them between simultaneous processes unless the tool documents safe concurrent access.
Codex supports ChatGPT login, API-key login, and enterprise access tokens. The
CLI and IDE extension share cached login details. OpenAI documents that cached
login details live in either a plaintext auth.json under CODEX_HOME
(~/.codex by default) or in the OS credential store. The setting is:
cli_auth_credentials_store = "file" # file | keyring | autoFor profile isolation, prefer file; keyring storage may be shared outside the
profile directory depending on the OS credential store implementation.
Codex also supports command-backed bearer tokens for custom model providers:
[model_providers.proxy.auth]
command = "/usr/local/bin/get-token"
args = ["codex-proxy"]
refresh_interval_ms = 300000That is the clean dynamic-credential path for proxy/custom provider use. For
the built-in OpenAI provider, docs guarantee normal cached login reuse and
ChatGPT token refresh during use, not arbitrary account switching by replacing
auth.json.
Already-running instance assessment:
- Changing
CODEX_HOMEonly affects new child processes launched with that environment. - Editing or symlink-swapping
auth.jsonunder a running process is not a documented live-switch path and can race with token refresh writes. - Use a new process for a different profile/account.
- Use
model_providers.<id>.auth.commandwhen the requirement is live token rotation for a custom provider.
Gemini CLI supports Sign in with Google, Gemini API keys, and Vertex AI. Official docs state:
- Sign in with Google caches credentials locally.
- API-key mode can use
GEMINI_API_KEY. - Vertex AI can use ADC,
GOOGLE_APPLICATION_CREDENTIALS, orGOOGLE_API_KEYwithGOOGLE_CLOUD_PROJECTandGOOGLE_CLOUD_LOCATION. GEMINI_CLI_HOMEchanges the root for user-level config/storage; Gemini creates a.geminidirectory inside it..envfiles are loaded from the first matching location; they are not merged.
Source inspection of @google/gemini-cli@0.42.0 found:
- Default Google OAuth cache path:
$GEMINI_CLI_HOME/.gemini/oauth_creds.jsonor~/.gemini/oauth_creds.json, mode0600. GEMINI_FORCE_ENCRYPTED_FILE_STORAGE=truemoves OAuth storage through Gemini's hybrid token storage.- Native keychain is preferred where available;
GEMINI_FORCE_FILE_STORAGE=trueforces the encrypted file fallback, stored asgemini-credentials.jsonunder the Gemini home. - Saved API keys use the same hybrid token storage service name
gemini-cli-api-key; directGEMINI_API_KEYper process is the simpler isolation path.
Already-running instance assessment:
- Parent shell env changes cannot affect an already-running process.
- Gemini caches OAuth clients in process and has an API-key cache, so changing files underneath a running instance is not a reliable account switch.
/authopens a dialog to change auth method, but that is an interactive reauth flow and some auth changes require restart.- Use a new
GEMINI_CLI_HOMEprocess for account isolation.
Anthropic's current Claude Code docs are explicit about storage:
- macOS: encrypted macOS Keychain.
- Linux:
~/.claude/.credentials.jsonwith mode0600. - Windows:
%USERPROFILE%\.claude\.credentials.json. - On Linux/Windows,
CLAUDE_CONFIG_DIRmoves.credentials.jsonunder that directory.
Claude Code auth precedence is:
- Cloud-provider credentials when
CLAUDE_CODE_USE_BEDROCK,CLAUDE_CODE_USE_VERTEX, orCLAUDE_CODE_USE_FOUNDRYis set. ANTHROPIC_AUTH_TOKEN.ANTHROPIC_API_KEY.apiKeyHelper.CLAUDE_CODE_OAUTH_TOKEN.- Subscription OAuth credentials from
/login.
For dynamic credentials, apiKeyHelper is the best-documented mechanism. It can
return an API key from a vault or token service and is refreshed by default after
5 minutes or on HTTP 401. The interval is controlled by
CLAUDE_CODE_API_KEY_HELPER_TTL_MS.
Already-running instance assessment:
apiKeyHelpersupports credential rotation during a running process.ANTHROPIC_API_KEY,ANTHROPIC_AUTH_TOKEN, andCLAUDE_CODE_OAUTH_TOKENare process environment values; changing the parent shell after launch does not update the running process./logoutand login flows can reauthenticate interactively, but external file replacement is not a safe live-switch strategy.
Use these rules:
- Prefer new process per account/profile. This is robust for all three CLIs.
- Prefer per-process env for API keys/tokens instead of saved keychain entries when you need deterministic isolation.
- Force file-backed storage when keychain storage would collapse profiles into one OS account.
- Use dynamic helpers only where supported:
- Codex custom providers:
model_providers.<id>.auth.command. - Claude:
apiKeyHelper. - Gemini: no general equivalent found for model auth; use new processes.
- Codex custom providers:
- Avoid symlink flips or overwriting credential files under running processes. They can be stale, ignored, or overwritten by refresh logic.
- OpenAI Codex authentication: https://developers.openai.com/codex/auth
- OpenAI Codex config reference: https://developers.openai.com/codex/config-reference
- Gemini CLI authentication: https://geminicli.com/docs/get-started/authentication/
- Gemini CLI configuration: https://geminicli.com/docs/reference/configuration/
- Gemini CLI commands:
@google/gemini-cli@0.42.0bundled docs,docs/reference/commands.md - Anthropic Claude Code authentication: https://code.claude.com/docs/en/authentication
- Anthropic Claude Code settings: https://code.claude.com/docs/en/settings
- Anthropic Claude Code environment variables: https://code.claude.com/docs/en/env-vars