Repository navigation
Description
Requested behavior
When starting an interactive Codex CLI session and accepting the existing update prompt, automatically launch the updated CLI after the package manager exits successfully. Keep the existing skip choice. Preserve the original command-line arguments and working directory.
Current behavior
The user starts codex, accepts the offered npm update, and must type the original command again after the update completes. This adds an unnecessary manual step before the intended interactive session begins.
Environment reported locally: npm installation, macOS arm64, codex-cli 0.157.1. The update flow was reported by the user; I inspected the implementation but did not perform a real upgrade during this investigation.
Source analysis
At commit 1cc7e23, codex-rs/cli/src/main.rs handles the TUI's update_action, calls run_update_action, and then returns. After a successful package-manager operation, run_update_action prints Update ran successfully! Please restart Codex. and returns without relaunching.
Source:
codex/codex-rs/cli/src/main.rs
Lines 765 to 836 in 1cc7e23
| if let Some(action) = update_action { | |
| run_update_action(action, cli_executable)?; | |
| } | |
| Ok(()) | |
| } | |
| /// Run the update action and print the result. | |
| fn run_update_action( | |
| action: UpdateAction, | |
| cli_executable: Option<&std::path::Path>, | |
| ) -> anyhow::Result<()> { | |
| if let UpdateAction::Daemon(source) = action { | |
| let executable = cli_executable | |
| .ok_or_else(|| anyhow::anyhow!("Cannot locate the launching Codex CLI"))?; | |
| println!("Updating the local background server..."); | |
| let status = std::process::Command::new(executable) | |
| .args(source.command_args()) | |
| .env(codex_app_server_daemon::telemetry::HANDOFF_ENV, "1") | |
| .status()?; | |
| anyhow::ensure!( | |
| status.success(), | |
| "Daemon update failed with status {status}" | |
| ); | |
| println!("Relaunch Codex to reconnect."); | |
| return Ok(()); | |
| } | |
| println!(); | |
| let cmd_str = action.command_str(); | |
| println!("Updating Codex via `{cmd_str}`..."); | |
| let status = { | |
| #[cfg(windows)] | |
| { | |
| let (cmd, args) = action.command_args(); | |
| let cmd = if action == UpdateAction::StandaloneWindows { | |
| // These args contain PowerShell metacharacters, so do not let | |
| // PATHEXT select a batch shim for this action. | |
| "powershell.exe" | |
| } else { | |
| cmd | |
| }; | |
| let path_env = | |
| std::env::var_os("PATH").ok_or_else(|| anyhow::anyhow!("PATH is not set"))?; | |
| let command_path = resolve_windows_update_command_from_path(cmd, &path_env)?; | |
| // Do not let a project-local command or package-manager config | |
| // influence the updater after the user accepts the update prompt. | |
| let update_cwd = tempfile::tempdir()?; | |
| // Resolve through PATH without consulting the project cwd. When | |
| // this returns a .cmd/.bat shim, std::process::Command routes the | |
| // absolute path through the system command processor. | |
| std::process::Command::new(command_path) | |
| .args(args) | |
| .current_dir(update_cwd.path()) | |
| .status()? | |
| } | |
| #[cfg(not(windows))] | |
| { | |
| let (cmd, args) = action.command_args(); | |
| let command_path = crate::wsl_paths::normalize_for_wsl(cmd); | |
| let normalized_args: Vec<String> = args | |
| .iter() | |
| .map(crate::wsl_paths::normalize_for_wsl) | |
| .collect(); | |
| std::process::Command::new(&command_path) | |
| .args(&normalized_args) | |
| .status()? | |
| } | |
| }; | |
| if !status.success() { | |
| anyhow::bail!("`{cmd_str}` failed with status {status}"); | |
| } | |
| println!("\n🎉 Update ran successfully! Please restart Codex."); | |
| Ok(()) |
Suggested scope and validation
Implement the handoff in the interactive startup-update path, rather than unconditionally in the shared update function: explicit codex update should not replay its own arguments and enter an update loop.
Resolve the newly installed CLI entrypoint after the update, retaining arguments as OS strings and preserving the current directory and terminal. Account for npm launchers and replaced/versioned executable paths. On update failure, cancellation, or restart failure, provide a clear result without repeated restarts. Skip should retain its existing behavior.
Suggested coverage: successful update launches the new CLI exactly once; original arguments (including spaces) and working directory survive; skip and failed/cancelled updates do not relaunch; explicit codex update does not recursively restart itself. Cover supported platforms and package-manager entrypoints.
This request is limited to the startup CLI update flow, not restoring an active conversation or restarting the desktop app/background daemon.
Activity