Skip to content

feat: seamless account switching without restarting the app#103

Open
Loongphy wants to merge 16 commits into
mainfrom
app-command
Open

feat: seamless account switching without restarting the app#103
Loongphy wants to merge 16 commits into
mainfrom
app-command

Conversation

@Loongphy
Copy link
Copy Markdown
Owner

@Loongphy Loongphy commented May 14, 2026

Description

This PR introduces codex-auth app support, enabling seamless Codex App account switching without requiring a restart of the desktop application.

By leveraging the official CODEX_CLI_PATH environment variable for each launch, this integration routes the Codex App through a customized, enhanced version of the codex-cli binary (named codext) that handles active session hot-swapping, cache invalidation, and UI synchronization automatically.


Key Features

  • Dynamic Account Switching: Switch accounts/workspaces without restarting the desktop application.
  • One-Shot Launches: Launch the Codex App with transient overrides for CODEX_HOME and CODEX_CLI_PATH.
  • Out-of-the-Box Setup: Automatically resolves, downloads, and caches the latest pre-compiled managed binary from Loongphy/codext for the target platform, eliminating manual setup.
  • Platform-Aware Launching: Select the Windows, WSL, or macOS app backend while keeping launch-specific configuration scoped to that process.

Technical Implementation

Non-Invasive Hooking via CODEX_CLI_PATH

The Codex desktop app launches its local app-server through a backend helper CLI, allowing its location to be overridden via the CODEX_CLI_PATH environment variable.

Rather than modifying the closed-source desktop application bundle or installing a persistent app patch, this PR utilizes this built-in hook by setting CODEX_CLI_PATH for the launched process to point to a custom, optimized binary replacement for the original codex-cli - specifically, the forked codext build from Loongphy/codext.

Core Engine Enhancements (Loongphy/codext@a504dcc)

  1. Safe-Boundary Reloading: Credentials and auth states are reloaded from storage at safe request boundaries - specifically right before thread/start, thread/resume, and turn/start. Reloads are explicitly deferred while a turn is actively running to prevent hot-swapping in-flight requests.
  2. Session & Connection Invalidation: ChatGPT account or workspace changes within the same auth mode are treated as complete auth changes. When a state change is detected:
    • The app-server invalidates model transport (WebSocket) caches across all tracked threads to prevent the next turn from accidentally reusing an old session.
    • It refreshes cloud requirements and residency states.
    • It emits an AccountUpdated event so that the desktop user interface instantly aligns with the new account snapshot.

Managed CLI Resolution

When --codex-cli-path is omitted, codex-auth app resolves the latest compatible codext release asset for the selected platform, caches it under CODEX_HOME/accounts/codext-cli, and uses that managed binary as the launch-specific CODEX_CLI_PATH target. The command does not reuse an unrelated CODEX_CLI_PATH value from the current shell.


Usage & CLI Reference

Command Syntax

# Launch the app with one-shot overrides
codex-auth app [--app-path <path>] [--codex-cli-path <path>] [--codex-home <path>] [--platform win|wsl|mac] [--std]

Command Details

  • codex-auth app: Launches the Codex App. By default, it starts the app quietly via the platform GUI launcher without locking the terminal.

Options & Parameters

Parameter Description
--app-path <path> Overrides the auto-detected Codex App installation path (defaults to the OpenAI.Codex AppX package on Windows, and com.openai.codex bundle on macOS).
--codex-cli-path <path> Sets the path to the replacement CLI binary for this launch. Overrides CODEX_CLI_PATH to use the custom codext binary. If omitted, codex-auth automatically resolves and downloads the latest compatible codext asset.
--codex-home <path> Overrides the CODEX_HOME directory for cache resolution and launching.
--platform <win|wsl|mac> Selects the backend platform. On Windows, omitting this will read .codex-global-state.json and auto-select wsl if runCodexInWindowsSubsystemForLinux is true; otherwise, it defaults to win.
--std Directs the launch to attach standard output/error (stdout/stderr) directly to the current terminal window for real-time debugging.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 14, 2026

Open in StackBlitz

@loongphy/codex-auth-darwin-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-arm64@0ac965b

@loongphy/codex-auth-darwin-x64

npx https://pkg.pr.new/@loongphy/codex-auth-darwin-x64@0ac965b

@loongphy/codex-auth-linux-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-arm64@0ac965b

@loongphy/codex-auth-linux-x64

npx https://pkg.pr.new/@loongphy/codex-auth-linux-x64@0ac965b

@loongphy/codex-auth-win32-arm64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-arm64@0ac965b

@loongphy/codex-auth-win32-x64

npx https://pkg.pr.new/@loongphy/codex-auth-win32-x64@0ac965b

@loongphy/codex-auth

npx https://pkg.pr.new/@loongphy/codex-auth@0ac965b

commit: 0ac965b

@Loongphy Loongphy changed the title feat: add Codex app CLI override command feat: seamless account switching without restarting the app May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant