Skip to content

BashTool ignores context.workspace for default cwd — sub-agent worktrees run commands in parent checkout #4674

Description

@fleitz

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:

  1. No-op default: BashTool's working_dir resolution returned None when no cwd was given, deferring to ShellManager.default_workspace instead of context.workspace.
  2. 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.

Fix (PR #4673)

  • 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions