The Windows app originally switched accounts by copying only ~/.codex/auth.json.
That was not sufficient for current Codex Desktop builds.
Two separate state layers were involved:
-
CLI identity state in
~/.codexauth.json.codex-global-state.json.codex-global-state.json.bak
-
Desktop browser/session state in the Codex MSIX package cache
%LOCALAPPDATA%\\Packages\\OpenAI.Codex_*\\LocalCache\\Roaming\\Codex
The original switch flow updated only auth.json, so Codex Desktop could reopen with:
- a stale
creator_idin.codex-global-state.json, or - stale browser/session state under the MSIX package cache.
That produced two visible failures:
- switch completed but Codex Desktop still showed the login screen
- in some cases Codex Desktop was terminated but not relaunched because the restart script failed while copying session files
windows/codexcontrol_windows/account_manager.py
- After copying the target
auth.json, the switch flow now rewritescreator_idin:.codex-global-state.json.codex-global-state.json.bak
- The rewrite is account-aware and replaces the previous provider account id with the target account id.
windows/codexcontrol_windows/file_locations.py
- Added discovery of the active Codex MSIX package under:
%LOCALAPPDATA%\\Packages\\OpenAI.Codex*
- Added resolution of the live desktop session root:
LocalCache\\Roaming\\Codex
- Defined the session entries that need to be preserved/restored during account switching.
windows/codexcontrol_windows/codex_desktop.py
-
The restart script now:
- stops Codex Desktop
- backs up the current desktop session into the managed home of the account being switched away from
- restores the target account's saved desktop session when available
- relaunches Codex Desktop
-
The script was also hardened:
- file-path handling for session file copies was fixed
- backup/restore runs per entry with logging instead of failing the whole restart on the first copy error
- when the target account has no saved desktop session yet, the script no longer wipes the current live session state
If a target account does not yet have a saved desktop-session snapshot, the first switch to that account may still require Codex Desktop to reconcile login/session state on its own.
After that account has been active once and its desktop session has been backed up, subsequent switches are expected to behave more consistently.
windows/codexcontrol_windows/account_manager.pywindows/codexcontrol_windows/app.pywindows/codexcontrol_windows/codex_desktop.pywindows/codexcontrol_windows/file_locations.pywindows/tests/test_account_manager.pywindows/tests/test_codex_desktop.py