[BUG] Bash tool working directory does not persist across calls for TeamCreate sub-agents
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
- Create a team with
TeamCreate - Spawn a sub-agent with the
Agenttool (withteam_nameset) - Have the sub-agent run
pwd→ project root - Have the sub-agent run
cd <project-root>/Sources(standalone, no chaining) - Have the sub-agent run
pwd→ project root again (should beSources/)
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
cdinstead of the actual command in compound bash statements - #30213 — Compound
cd && gitcommands 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.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗