Problem
When a sub-agent is spawned with worktree: true, shell commands that don't specify an explicit cwd run in the parent checkout's workspace instead of the sub-agent's worktree directory.
The BashTool's cwd resolution defaults to None when no cwd is provided, which falls through to the shared ShellManager's default_workspace (set to the parent workspace). The foreground execution path (execute_foreground_via_background) also always passed None as the working directory, so even if the cwd were resolved differently upstream, it was ignored.
Root Cause
Two issues in crates/tui/src/tools/shell.rs:
- No-op default:
BashTool's working_dir resolution returned None when no cwd was given, deferring to ShellManager.default_workspace instead of context.workspace.
- Missing thread:
execute_foreground_via_background hardcoded None as the working directory, so it couldn't receive a resolved directory even if one were provided.
- Default no-
cwd shell commands to context.workspace instead of None.
- Thread the resolved
working_dir through execute_foreground_via_background.
- Added regression test
default_cwd_uses_context_workspace_not_shell_manager_default.
Expected Behavior
Shell commands without an explicit cwd should run in the sub-agent's worktree directory when worktree: true is used.
/cc @fleitz
Problem
When a sub-agent is spawned with
worktree: true, shell commands that don't specify an explicitcwdrun in the parent checkout's workspace instead of the sub-agent's worktree directory.The
BashTool's cwd resolution defaults toNonewhen nocwdis provided, which falls through to the sharedShellManager'sdefault_workspace(set to the parent workspace). The foreground execution path (execute_foreground_via_background) also always passedNoneas the working directory, so even if the cwd were resolved differently upstream, it was ignored.Root Cause
Two issues in
crates/tui/src/tools/shell.rs:BashTool'sworking_dirresolution returnedNonewhen nocwdwas given, deferring toShellManager.default_workspaceinstead ofcontext.workspace.execute_foreground_via_backgroundhardcodedNoneas the working directory, so it couldn't receive a resolved directory even if one were provided.Fix (PR #4673)
cwdshell commands tocontext.workspaceinstead ofNone.working_dirthroughexecute_foreground_via_background.default_cwd_uses_context_workspace_not_shell_manager_default.Expected Behavior
Shell commands without an explicit
cwdshould run in the sub-agent's worktree directory whenworktree: trueis used./cc @fleitz