How to Switch Codex Accounts in VS Code

In the native Codex extension, open the profile menu, select Log out, then choose Sign in with ChatGPT and authorize the other account in your browser. For Codex CLI in VS Code's integrated terminal, select a saved profile with aisw use codex <profile> and restart codex. These are different running processes; verify the panel account separately after a terminal switch.

Change the account in the native Codex extension

  1. Open the Codex extension's profile menu and check the current account or API-key status.
  2. Select Log out to clear the current credentials.
  3. Select Sign in with ChatGPT and complete the browser flow with the intended account. Check the profile menu again before continuing work.

See OpenAI's authentication documentation. The CLI and native extension share cached login details, so logging out of one can require signing in again in the other. Storage can be a file or the operating system credential store; do not assume every native login is an auth.json file that aisw can import.

AI Switcher's status bar is a separate extension. Its saved-profile workflow below applies to CLI processes launched from the integrated terminal. Start with the Codex CLI switch guide to add profiles. Native keyring-only and ephemeral sessions are not imported by aisw.

Why each VS Code terminal can be on a different Codex account

Codex looks for auth.json and config.toml in CODEX_HOME. If that variable is not set, it uses ~/.codex. In isolated state mode (the default), each aisw profile has its own Codex home under ~/.aisw/profiles/codex/<profile>. When you run aisw use, the shell hook exports that path into the current shell:

$ aisw use codex work-api-key --emit-env
export CODEX_HOME='/Users/you/.aisw/profiles/codex/work-api-key'

The export only reaches the shell that ran it. In a VS Code window with several terminals, you can end up with three different states:

  • The terminal where you switched points to the new profile.
  • A terminal where you ran aisw use earlier still exports the previous profile's CODEX_HOME. Codex started there uses the old account.
  • A terminal that never ran aisw use has no CODEX_HOME, so Codex reads ~/.codex. That holds whatever was last written there, which may not be the active profile. The hook does not set CODEX_HOME when a new shell starts.

aisw status reads the same environment, so run it in the terminal you are about to use. Here work-api-key is active in one terminal, while a second terminal with no CODEX_HOME still reads the older ~/.codex:

$ aisw status --tool codex
  Active        : work-api-key
  State mode    : isolated
  State         : credentials present, but live tool config does not match the active profile

That line means the active profile is correct, but this terminal would launch Codex with a different account. Run aisw use codex work-api-key in this terminal to fix it.

Switch the Codex account in a VS Code terminal

You need the shell hook so aisw use can export CODEX_HOME. Add eval "$(aisw shell-hook zsh)" to ~/.zshrc, or use the Bash, Fish or PowerShell version from the shell integration docs. Terminals that were already open will not have the hook. Open a new one, or run source ~/.zshrc in each.

aisw use codex work-api-key
aisw status --tool codex
codex

Switching to an API-key profile prints:

Codex CLI → work-api-key
────────────────────────

  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.

Read the line about shell integration closely. Without the hook, nothing exports CODEX_HOME, and aisw copies the credentials into ~/.codex instead. If you can't install the hook, for example in a VS Code task, run eval "$(aisw use codex work-api-key --emit-env)" in that shell before codex.

If Codex is already running in a terminal, it keeps the account it started with. Exit it, switch, and start it again.

ChatGPT login or API key: the choice changes how terminals behave

ChatGPT-managed profiles are the ones you add through codex login with aisw add codex personal. They have to use isolated mode. Codex refreshes ChatGPT tokens in place, so two Codex homes cannot safely share one set. aisw refuses the shared-mode switch:

shared-mode ChatGPT switching is unsupported for Codex profile 'personal'.
  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 personal --state-mode isolated

In VS Code this means a ChatGPT profile goes with the terminal. Run aisw use codex personal in every terminal you launch Codex from. That way, token refreshes are written to the profile's own CODEX_HOME and not to a shared ~/.codex.

API-key profiles, such as work-api-key, don't have that constraint. With --state-mode shared, aisw writes the key into ~/.codex and the hook unsets CODEX_HOME. Every terminal without an override then picks up the switch:

$ aisw use codex work-api-key --state-mode shared
  ...
  State mode    : shared

Effects
  ...
  Codex will keep shared local state and only switch account credentials.

The trade-off: in shared mode, Codex history and settings in ~/.codex are shared by every API-key profile. A terminal that still exports a CODEX_HOME from an earlier isolated switch will still use that profile. For the full comparison of the two auth types, see multiple Codex CLI accounts.

Why aisw sets cli_auth_credentials_store = "file"

Every Codex profile directory gets a config.toml containing:

cli_auth_credentials_store = "file"

When a profile is applied to ~/.codex, aisw sets the same line in your existing config.toml. If the line says "keyring", aisw replaces it with "file" and keeps your other settings. The reason: Codex keyring entries are keyed by a hash of the CODEX_HOME path. aisw cannot reconstruct that key, so it can only capture and switch credentials that Codex writes to auth.json.

This matters when you add a ChatGPT profile from a VS Code terminal. aisw add codex personal runs codex login with CODEX_HOME set to a temporary directory, then waits for auth.json to appear there. If the login finishes in the browser but nothing is written, aisw times out with:

Codex login timed out after <n>s. If auth.json was not written, verify that config.toml has cli_auth_credentials_store = "file" (not "keyring").

More on sign-in modes is in the Codex CLI login guide.

Switching from the AI Switcher extension

The AI Switcher extension for VS Code and Cursor shows the active profile in the status bar. From the AISW: Switch Profile picker, choosing a Codex profile runs aisw use codex <profile> --json as its own process and then verifies Codex. That updates the active profile and the Codex home the extension can see, which is normally ~/.codex.

The extension does not change the environment of terminals that are already open. It can't export CODEX_HOME into a shell it didn't start. After switching from the status bar, run aisw use codex <profile> once in the terminal where you'll run Codex. This step matters for isolated ChatGPT profiles. Then use AISW: Verify Active Accounts or aisw status --tool codex to confirm.

If a repository should always use one account, bind it to a context so the hook blocks codex when the wrong account is active. The extension also offers to switch when you open that workspace. To set this up, see one Codex account per repository.

Know which Codex account each terminal will use

Install aisw and the shell hook, then switch and check from the terminal that runs Codex.

Codex and VS Code questions

Direct answers about integrated terminals, CODEX_HOME, auth types, and the extension.

How do I switch Codex accounts in VS Code?

In the native Codex extension, open the profile menu, select Log out, then Sign in with ChatGPT and complete browser authorization for the other account. For the integrated terminal, run aisw use codex <profile> with the shell hook and restart codex. Verify the panel account separately after switching terminal profiles.

Why does Codex in another VS Code terminal still use the old account?

Each integrated terminal is its own shell. aisw use only changes CODEX_HOME in the shell where you ran it. A terminal that exported an earlier profile's CODEX_HOME keeps it, and a terminal with no CODEX_HOME reads ~/.codex. Run aisw use codex <profile> in that terminal too.

Can I switch a ChatGPT-login Codex profile in shared mode so every terminal follows?

No. aisw refuses shared mode for ChatGPT-managed Codex auth, because Codex refreshes those tokens in place and they cannot safely be shared by more than one owner. Use isolated mode and switch in each terminal. API-key profiles can use shared mode.

Does switching from the AI Switcher VS Code extension change my open terminals?

No. The extension runs aisw use codex <profile> as its own process and then verifies the result. It cannot change environment variables in terminals that are already open. Run aisw use codex <profile> once in the terminal you will launch Codex from.