the runtime your coding agents live on
Rust agentagent-orchestrationaiai-agentsclaude-codeclicodexcoding-agentsdeveloper-toolsdevtoolsmultiplexerrustterminalterminal-multiplexerterminal-uitmuxtuiworkspace-manager
fix: follow foreground cwd for new terminals
Pitchfork-and-Torch4f7fcc48d1f7
diff --git a/src/app/api/layouts.rs b/src/app/api/layouts.rsindex 851221b49..0fdbaba09 100644--- a/src/app/api/layouts.rs+++ b/src/app/api/layouts.rs@@ -341,11 +341,8 @@ impl App {let follow_cwd = replace_target.and_then(|(_, tab_idx)| {let ws = self.state.workspaces.get(ws_idx)?;let tab = ws.tabs.get(tab_idx)?;- tab.cwd_for_pane(- tab.layout.focused(),- &self.state.terminals,- &self.terminal_runtimes,- )+ let pane_id = tab.layout.focused();+ tab.follow_cwd_for_pane(pane_id, &self.state.terminals, &self.terminal_runtimes)});self.resolve_new_terminal_cwd(follow_cwd.or_else(|| self.focused_pane_cwd_in_workspace(ws_idx)),@@ -399,7 +396,7 @@ impl App {.cwd.as_ref().map(PathBuf::from)- .or_else(|| self.cwd_for_pane_in_workspace(ws_idx, target_pane_id));+ .or_else(|| self.follow_cwd_for_pane_in_workspace(ws_idx, target_pane_id));let extra_env = super::env::normalize_launch_env(pane.env.clone()).map_err(|(_, message)| message.to_string())?;let direction = match direction {diff --git a/src/app/api/panes.rs b/src/app/api/panes.rsindex 9f64dd51d..58dbeb194 100644--- a/src/app/api/panes.rs+++ b/src/app/api/panes.rs@@ -53,7 +53,7 @@ impl App {};let (rows, cols) = self.state.estimate_pane_size();let split_cwd = params.cwd.map(std::path::PathBuf::from).or_else(|| {- let follow_cwd = self.cwd_for_pane_in_workspace(ws_idx, target_pane_id);+ let follow_cwd = self.follow_cwd_for_pane_in_workspace(ws_idx, target_pane_id);Some(self.resolve_new_terminal_cwd(follow_cwd))});let default_shell = self.state.default_shell.clone();diff --git a/src/app/creation.rs b/src/app/creation.rsindex 13fc0a8e6..734c57aa8 100644--- a/src/app/creation.rs+++ b/src/app/creation.rs@@ -38,21 +38,23 @@ impl App {.resolved_identity_cwd_from(&self.state.terminals, &self.terminal_runtimes)}- pub(super) fn cwd_for_pane_in_workspace(+ pub(super) fn follow_cwd_for_pane_in_workspace(&self,ws_idx: usize,pane_id: crate::layout::PaneId,) -> Option<PathBuf> {let ws = self.state.workspaces.get(ws_idx)?;let tab_idx = ws.find_tab_index_for_pane(pane_id)?;- ws.tabs- .get(tab_idx)?- .cwd_for_pane(pane_id, &self.state.terminals, &self.terminal_runtimes)+ ws.tabs.get(tab_idx)?.follow_cwd_for_pane(+ pane_id,+ &self.state.terminals,+ &self.terminal_runtimes,+ )}pub(super) fn focused_pane_cwd_in_workspace(&self, ws_idx: usize) -> Option<PathBuf> {let pane_id = self.state.workspaces.get(ws_idx)?.focused_pane_id()?;- self.cwd_for_pane_in_workspace(ws_idx, pane_id)+ self.follow_cwd_for_pane_in_workspace(ws_idx, pane_id)}pub(super) fn resolve_new_terminal_cwd(&self, follow_cwd: Option<PathBuf>) -> PathBuf {@@ -77,9 +79,10 @@ impl App {/// Create a workspace with a real PTY (needs event_tx).#[cfg(test)]pub(crate) fn create_workspace(&mut self) {- let follow_cwd = self- .workspace_creation_source()- .and_then(|ws_idx| self.seed_cwd_from_workspace(ws_idx));+ let follow_cwd = self.workspace_creation_source().and_then(|ws_idx| {+ self.focused_pane_cwd_in_workspace(ws_idx)+ .or_else(|| self.seed_cwd_from_workspace(ws_idx))+ });let initial_cwd = self.resolve_new_terminal_cwd(follow_cwd);if let Err(e) = self.create_workspace_with_events(initial_cwd, true) {error!(err = %e, "failed to create workspace");@@ -91,10 +94,10 @@ impl App {pub(crate) fn create_tab(&mut self) {let custom_name = self.state.requested_new_tab_name.take();let active_before = self.state.active;- let follow_cwd = self- .state- .active- .and_then(|ws_idx| self.seed_cwd_from_workspace(ws_idx));+ let follow_cwd = self.state.active.and_then(|ws_idx| {+ self.focused_pane_cwd_in_workspace(ws_idx)+ .or_else(|| self.seed_cwd_from_workspace(ws_idx))+ });let initial_cwd = self.resolve_new_terminal_cwd(follow_cwd);match self.create_tab_with_options(initial_cwd, true) {Ok(created_idx) => {diff --git a/src/app/input/mod.rs b/src/app/input/mod.rsindex e4da8bc9c..bcd5da984 100644--- a/src/app/input/mod.rs+++ b/src/app/input/mod.rs@@ -559,7 +559,8 @@ impl AppState {.and_then(|i| self.workspaces.get(i)).and_then(|ws| {let tab = ws.active_tab()?;- tab.cwd_for_pane(tab.layout.focused(), &self.terminals, terminal_runtimes)+ let pane_id = tab.layout.focused();+ tab.follow_cwd_for_pane(pane_id, &self.terminals, terminal_runtimes)});let cwd = Some(super::creation::resolve_new_terminal_cwd(&self.new_terminal_cwd,diff --git a/src/workspace/tab.rs b/src/workspace/tab.rsindex d1b39ff4f..ab9829d0c 100644--- a/src/workspace/tab.rs+++ b/src/workspace/tab.rs@@ -568,4 +568,14 @@ impl Tab {.get(terminal_id).and_then(|rt| rt.foreground_cwd())}++ pub fn follow_cwd_for_pane(+ &self,+ pane_id: PaneId,+ terminals: &HashMap<TerminalId, TerminalState>,+ terminal_runtimes: &TerminalRuntimeRegistry,+ ) -> Option<PathBuf> {+ self.foreground_cwd_for_pane(pane_id, terminal_runtimes)+ .or_else(|| self.cwd_for_pane(pane_id, terminals, terminal_runtimes))+ }}diff --git a/tests/api_ping.rs b/tests/api_ping.rsindex 242045483..aea8188a4 100644--- a/tests/api_ping.rs+++ b/tests/api_ping.rs@@ -705,6 +705,10 @@ fn pane_info_reports_foreground_cwd_without_changing_pane_cwd() {.as_str().unwrap().to_string();+ let workspace_id = created["result"]["workspace"]["workspace_id"]+ .as_str()+ .unwrap()+ .to_string();let command = format!("/bin/sh -c 'cd {} && printf %s $$ > {} && touch {} && sleep 30'",foreground.display(),@@ -788,6 +792,59 @@ fn pane_info_reports_foreground_cwd_without_changing_pane_cwd() {foreground.display().to_string());+ let split = send_request(+ &socket_path,+ &serde_json::json!({+ "id": "fg_split",+ "method": "pane.split",+ "params": {+ "target_pane_id": pane_id,+ "direction": "right",+ "focus": false,+ },+ })+ .to_string(),+ );+ assert_eq!(+ split["result"]["pane"]["cwd"],+ foreground.display().to_string()+ );++ let tab = send_request(+ &socket_path,+ &serde_json::json!({+ "id": "fg_tab",+ "method": "tab.create",+ "params": {+ "workspace_id": workspace_id,+ "focus": false,+ },+ })+ .to_string(),+ );+ assert_eq!(+ tab["result"]["root_pane"]["cwd"],+ foreground.display().to_string()+ );++ let explicit_tab = send_request(+ &socket_path,+ &serde_json::json!({+ "id": "fg_explicit_tab",+ "method": "tab.create",+ "params": {+ "workspace_id": workspace_id,+ "cwd": base,+ "focus": false,+ },+ })+ .to_string(),+ );+ assert_eq!(+ explicit_tab["result"]["root_pane"]["cwd"],+ base.display().to_string()+ );+cleanup_spawned_herdr(child, base);}