diff --git a/codex-cli/bin/codex.js b/codex-cli/bin/codex.js index 805be85af8..fdbf7486ec 100644 --- a/codex-cli/bin/codex.js +++ b/codex-cli/bin/codex.js @@ -73,9 +73,10 @@ const binaryPath = path.join(archRoot, "codex", codexBinaryName); function getUpdatedPath(newDirs) { const pathSep = process.platform === "win32" ? ";" : ":"; const existingPath = process.env.PATH || ""; + // Preserve caller PATH precedence by appending any additional dirs. const updatedPath = [ - ...newDirs, ...existingPath.split(pathSep).filter(Boolean), + ...newDirs, ].join(pathSep); return updatedPath; } diff --git a/codex-rs/arg0/src/lib.rs b/codex-rs/arg0/src/lib.rs index e70ff2df64..58d2d5b348 100644 --- a/codex-rs/arg0/src/lib.rs +++ b/codex-rs/arg0/src/lib.rs @@ -179,9 +179,11 @@ fn prepend_path_entry_for_apply_patch() -> std::io::Result { const PATH_SEPARATOR: &str = ";"; let path_element = path.display(); + // Append our temp dir to PATH rather than prepending to avoid + // disturbing user PATH ordering (e.g., virtualenvs, shims). let updated_path_env_var = match std::env::var("PATH") { Ok(existing_path) => { - format!("{path_element}{PATH_SEPARATOR}{existing_path}") + format!("{existing_path}{PATH_SEPARATOR}{path_element}") } Err(_) => { format!("{path_element}")