Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After a switch, new Codex CLI sessions can keep using the previous account.
~/.codex/auth.jsonholds the new account, but the CLI does not read it.Root cause
Codex CLI 0.160.0 runs interactive sessions on a shared app-server daemon (
codex app-server --listen unix:// --managed-daemon) unless--no-daemonis passed. The daemon loadsauth.jsononce, when it starts, and keeps those credentials in memory. The switcher only rewritesauth.jsonand counts everycodex app-serverprocess as a background process, so the daemon keeps serving the old account until it restarts.Reproduced with a separate
CODEX_HOME: the daemon still reported account A afterauth.jsonchanged to account B, and reported B only after a restart.Fix
auth.jsonchanges, stop the managed daemon with$CODEX_HOME/packages/app-server-daemon/current/bin/codex app-server daemon stop. The next CLI session starts a new daemon, which loads the new account.$CODEX_HOME/app-server-daemon/daemon.pid. The pid must belong to a process withapp-serverand--managed-daemonin its command line.check_codex_processesreturnscli_daemon_running, and the header shows a "CLI daemon running" badge.Stop, not restart: a daemon that the switcher starts inherits the GUI app environment (on macOS a minimal
PATH), which then reaches MCP servers and tools. A daemon that the CLI starts gets the terminal environment.Limits: Unix only; on Windows the detection returns false. Stopping the daemon ends work that still runs on it, for example a headless
codex execor a remote-control session. Interactive CLI sessions already block the switch.Testing
cargo test(new unit tests for pid file parsing and command matching),pnpm build,pnpm test.CODEX_HOME. It found the daemon, stopped it, and then reported no daemon. A new CLI session started a fresh daemon.