Codex CLI Account Switcher: Switch Accounts

Codex CLI · CLI v0.3.11 · Desktop v0.2.1 · Updated September 23, 2026

Save each Codex CLI account as an aisw profile, then run aisw use codex <profile> to switch. aisw applies the profile's credentials where Codex CLI reads them, and with the shell hook installed it also points CODEX_HOME at that profile's own directory, so there's no logging out and no manual auth.json copying.

Codex CLI keeps one active account in auth.json or a system keyring under CODEX_HOME, with no built-in concept of saved, named accounts. OpenAI’s Codex configuration schema documents those storage modes and the CODEX_HOME location. Switching normally means logging out and back in, or backing up and restoring that file by hand. aisw is a Codex CLI account switcher that wraps that process in a single command.

Before you start

Install aisw if you haven’t already:

Terminal window
brew tap burakdede/tap && brew install aisw

CLI method

1. Capture the account you’re currently signed into.

Terminal window
aisw init

If Codex CLI is already signed in when you run this, init detects it and offers to import it as a named profile right in the prompt, accept it and skip the next command. Otherwise, or if you already ran init on this machine before, capture it explicitly:

Terminal window
aisw add codex work --from-live

Re-running aisw init later is safe; it just re-detects live accounts and reports current state without touching profiles you’ve already saved. For a durable Codex profile that survives future ChatGPT-managed token refreshes cleanly, sign in directly into the named profile instead of relying on --from-live long-term, see the next step.

2. Add a second account.

Interactively, using Codex CLI’s own OAuth flow:

Terminal window
aisw add codex personal

Or from an API key already in OPENAI_API_KEY, which keeps the key out of your shell history:

Terminal window
aisw add codex work-api-key --from-env

The Codex CLI login guide covers each sign-in method in detail.

3. Switch between them.

Terminal window
aisw use codex work

aisw prints what it changed:

Codex CLI → work
────────────────
Auth : api-key
Codex auth : API key
Backend : file
State mode : isolated
Effects
Live tool configuration updated.
Active profile updated.
Codex will use isolated profile state when shell integration is active.
Backup created before switching.

Switching back is the same command with the other name, aisw use codex personal. By default, aisw backs up the current credentials before it overwrites them.

4. Confirm which account is active, then start Codex.

Terminal window
aisw status --tool codex
aisw verify
codex

status shows the active profile and state mode; verify checks that the live Codex credentials match the profile aisw recorded:

Codex CLI
Status : pass
Active : work

Switch Codex accounts without logging out

You never need codex logout to change accounts. Sign in once per account when you add it, and after that aisw use codex <profile> is the whole switch. Run codex login again only when a saved session has expired and you need to refresh it.

Two things happen when you switch:

  • aisw writes the profile’s credentials to the location Codex CLI reads, so a plain codex launch picks up the new account.
  • If the shell hook is installed, aisw also sets CODEX_HOME to the profile’s own directory in the current shell. That is isolated mode, the default, and it keeps each account’s auth.json and refreshes separate.

Install the hook once (zsh shown; bash, fish and PowerShell are covered in the shell integration docs):

Terminal window
eval "$(aisw shell-hook zsh)"

Without the hook, you can apply the same exports by hand:

Terminal window
eval "$(aisw use codex work --emit-env)"

Switching is not a hot swap. A codex process that is already running keeps the account and environment it started with, so quit it and start a new one after you switch.

Isolated or shared mode when you switch

aisw use codex accepts --state-mode isolated or --state-mode shared. Isolated is the default and the right choice for ChatGPT sign-ins. Shared mode keeps Codex’s standard directory and swaps only the credential, which works for API-key profiles:

Terminal window
aisw use codex work-api-key --state-mode shared

For a ChatGPT-managed profile, aisw refuses shared mode with:

shared-mode ChatGPT switching is unsupported for Codex profile 'work'.
Codex refreshes ChatGPT auth in place, and those refresh/session tokens are not safely shareable across multiple live owners.
This is an expected upstream limitation, not an aisw corruption bug.
Use isolated mode instead: aisw use codex work --state-mode isolated

Run the suggested command. If the profile came from --from-live, sign in again directly inside the profile for a durable setup. Why the profile-owned CODEX_HOME matters is covered in depth in multiple Codex CLI accounts with isolated CODEX_HOME.

Switching in VS Code or on Windows

The commands are the same on macOS, Linux and Windows. In VS Code, switch in the integrated terminal, then start a new codex session there; an extension or terminal that was already running keeps its old environment. Switching Codex accounts in VS Code walks through the editor-specific cases.

When Codex is one of several tools

If a client or job also uses Claude Code or Gemini CLI, switching Codex alone leaves the other tools on the old account. Group the profiles into a context and switch them together with aisw context use <name>; profiles vs contexts explains when each fits. To stop codex from launching under the wrong account in a given repository, bind the directory to its context with workspace guardrails.

Desktop method

The current public AI Switcher Desktop release covers macOS, Windows x64, and Linux x64. Download the matching build from /download/, then follow the same switch flow below.

AI Switcher Desktop Profiles screen showing named Codex CLI profiles and their authentication state
  1. Open AI Switcher Desktop and go to Overview.
  2. In the Codex CLI column, select the profile you want active and click Activate.
  3. Or press ⌘K for Quick Switch and type the profile name.

The CLI and Desktop read the same profiles, so a switch in one shows up in the other.

What switching does not do

aisw changes which saved account Codex CLI uses on your machine. It does not sign you in on OpenAI’s side, pool usage across accounts, or get around plan limits, and it does not proxy Codex traffic.

Common problems

If aisw add codex <name> --from-live fails to read the current credentials, Codex CLI may be using a keyring backend aisw doesn’t have permission to read yet, re-run the command after granting keyring access when your OS prompts for it. For anything else, aisw doctor diagnoses common environment issues.

If codex still shows the old account after a switch, it was started before the switch, or the shell hook isn’t loaded in that terminal. Run aisw verify, then start a new codex process.

If add fails with an error naming a different existing profile, that Codex account is already saved under that name, aisw checks the underlying OpenAI identity, not just the profile name, and won’t create a duplicate. Use the existing profile or remove it first if you actually want to re-add it under a new name.

If add fails with “profile already exists” instead, that’s a name collision rather than an account duplicate, pick a different name. When capturing with --from-live, you can add --yes to overwrite the existing profile’s stored credential.

Frequently asked questions

How do I change the account Codex CLI uses?

Save each login as a named profile with aisw add codex <profile>, then run aisw use codex <profile> to change accounts. Start a new codex session afterwards so it reads the new credentials. Use codex login only when you add or refresh an account.

Can I switch Codex CLI accounts without logging out?

Yes. Once an account is saved as a profile, aisw use codex <profile> activates it without running codex logout or signing in again. Check the result with aisw status, then start a new codex process.

Do I need to copy auth.json to switch Codex accounts?

No. Each profile keeps its own credential under ~/.aisw, and aisw use applies it for you. With the shell hook installed, isolated mode sets CODEX_HOME to the profile's directory, so you never rename or overwrite auth.json by hand.

Does switching change a Codex session that is already running?

No. A running codex process keeps the credentials and environment it started with. Switch first, then start a new codex process, in VS Code or any other terminal, on macOS, Linux and Windows alike.

Why does aisw use codex <profile> --state-mode shared fail for my ChatGPT login?

Codex refreshes ChatGPT-managed auth in place, and those refresh tokens are not safe to share between profiles, so aisw blocks shared mode for them. Use aisw use codex <profile> --state-mode isolated, which is the default, or an API key if you need shared mode.

Where does Codex CLI store credentials that aisw manages?

Depending on your install, Codex CLI stores credentials in auth.json or in a system keyring. aisw detects which one your install uses and writes profiles to that same location.

Can aisw import a Codex CLI account I'm already signed into?

Yes, where the credential file is readable. Use aisw add codex <name> --from-live to capture the account that's currently active.

Make your next account switch a single command.

Install aisw, run aisw init, and the accounts you are signed into become named profiles.

brew install burakdede/tap/aisw