From 154fd14d1d87d1ae34c13684f78779079835c72c Mon Sep 17 00:00:00 2001 From: jimmyfraiture Date: Thu, 4 Sep 2025 16:09:22 -0700 Subject: [PATCH] .zshrc not included in bash -l --- codex-rs/core/src/codex.rs | 12 ++++++++++++ codex-rs/core/src/shell.rs | 10 +++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/codex-rs/core/src/codex.rs b/codex-rs/core/src/codex.rs index 547721ce0c..067d112ba1 100644 --- a/codex-rs/core/src/codex.rs +++ b/codex-rs/core/src/codex.rs @@ -106,6 +106,8 @@ use crate::safety::SafetyCheck; use crate::safety::assess_command_safety; use crate::safety::assess_safety_for_untrusted_command; use crate::shell; +use crate::shell::Shell; +use crate::shell::ShellSnapshot; use crate::turn_diff_tracker::TurnDiffTracker; use crate::user_instructions::UserInstructions; use crate::user_notification::UserNotification; @@ -286,6 +288,7 @@ pub(crate) struct Session { codex_linux_sandbox_exe: Option, user_shell: shell::Shell, show_raw_agent_reasoning: bool, + shell_snapshot: Option, } /// The context needed for a single turn of the conversation. @@ -408,6 +411,11 @@ impl Session { ..Default::default() }; + let shell_snapshot = match &default_shell { + Shell::Zsh(zsh) => zsh.shell_snapshot.clone(), + _ => None, + }; + // Handle MCP manager result and record any startup failures. let (mcp_connection_manager, failed_clients) = match mcp_res { Ok((mgr, failures)) => (mgr, failures), @@ -476,6 +484,7 @@ impl Session { codex_linux_sandbox_exe: config.codex_linux_sandbox_exe.clone(), user_shell: default_shell, show_raw_agent_reasoning: config.show_raw_agent_reasoning, + shell_snapshot, }); // Dispatch the SessionConfiguredEvent first and then report any errors. @@ -948,6 +957,9 @@ impl Session { impl Drop for Session { fn drop(&mut self) { self.interrupt_task(); + if let Some(shell_snapshot) = &self.shell_snapshot { + shell::delete_shell_snapshot(&shell_snapshot.path); + } } } diff --git a/codex-rs/core/src/shell.rs b/codex-rs/core/src/shell.rs index 19ef567c90..05a6b04fcb 100644 --- a/codex-rs/core/src/shell.rs +++ b/codex-rs/core/src/shell.rs @@ -24,12 +24,6 @@ impl ShellSnapshot { } } -impl Drop for ShellSnapshot { - fn drop(&mut self) { - delete_shell_snapshot(&self.path); - } -} - #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] pub struct PowerShellConfig { exe: String, // Executable name or path, e.g. "pwsh" or "powershell.exe". @@ -318,8 +312,10 @@ async fn regenerate_zsh_snapshot( capture_script.push_str(&format!("{profile_sources}; ")); } + let zshrc = home.join(".zshrc"); + capture_script.push_str( - "setopt posixbuiltins; export -p; { alias | sed 's/^/alias /'; } 2>/dev/null || true", + &format!("source {}/.zshrc; setopt posixbuiltins; export -p; {{ alias | sed 's/^/alias /'; }} 2>/dev/null || true", zshrc.display()), ); let output = tokio::process::Command::new(shell_path) .arg("-lc")