[BUG] Bash tool working directory does not persist across calls for TeamCreate sub-agents

Resolved 💬 2 comments Opened Mar 16, 2026 by brandonbloom Closed Mar 17, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

The Bash tool docs state "Working directory persists across commands," but for agents spawned via TeamCreate, cd does not persist across separate Bash tool calls. Every call resets to the project root, regardless of the target path.

This is true even for directories within the project tree. The root agent does not have this problem — cd persists correctly for it within the project tree.

| Context | cd within project | cd outside project |
|---|---|---|
| Root agent | Persists ✅ | Reset (expected) |
| Sub-agent (TeamCreate) | Reset ❌ | Reset |

What Should Happen?

cd should persist across Bash tool calls for sub-agents the same way it does for the root agent.

Error Messages/Logs

# Sub-agent runs these as separate Bash tool calls:
$ pwd
/Users/me/Projects/myproject

$ cd /Users/me/Projects/myproject/Sources
(no output)

$ pwd
/Users/me/Projects/myproject    # ← should be /Users/me/Projects/myproject/Sources

Steps to Reproduce

  1. Create a team with TeamCreate
  2. Spawn a sub-agent with the Agent tool (with team_name set)
  3. Have the sub-agent run pwd → project root
  4. Have the sub-agent run cd <project-root>/Sources (standalone, no chaining)
  5. Have the sub-agent run pwd → project root again (should be Sources/)

Tested paths (all reset for sub-agents):

  • Plain subdirectory (Sources/, Sources/Core/)
  • Git worktree within project (.worktrees/024-selection-toolbar/)
  • Path outside project (/tmp)

All reset. The root agent correctly persists cd for the within-project cases.

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

Claude Code Version

2.1.76 (Claude Code)

Platform

AWS Bedrock

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

This forces sub-agents into compound commands like cd path && git status, which then trigger the "Compound commands with cd and git require approval to prevent bare repository attacks" permission prompt. Related issues:

  • #28240 — Permission prompt incorrectly triggers on cd instead of the actual command in compound bash statements
  • #30213 — Compound cd && git commands requiring approval

A cwd parameter on the Agent tool (to set the starting directory when spawning a teammate) would also help — even if persistence is fixed, agents currently have no way to declare their intended working directory at spawn time.

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗