[BUG] Subagent Bash tool CWD does not inherit from Task launch context AND every workaround is blocked by security checks
Preflight Checklist
- [x] I have searched existing issues and the closest match (#33576) was closed-for-inactivity and locked, with the auto-close note explicitly directing users to file a new issue if still relevant.
- [x] This is a single bug report.
- [x] I am using the latest version of Claude Code.
What's Wrong?
Same bug reported in #33576 (now locked) and #35023 (closed as duplicate of #33576): subagents launched via the Task tool have their Bash tool CWD reset between calls, defaulting away from the parent session's working directory. Re-filing per the auto-close instruction since the bug remains active in current Claude Code versions and is still actively biting users.
Why this is more than a "use the workarounds" issue
All standard workarounds are blocked:
| Workaround | Why it doesn't work |
|---|---|
| cd X then git Y as separate calls | CWD doesn't persist between subagent Bash calls (this bug) |
| cd X && git Y (compound) | Blocked by Claude Code's bare-repository injection protection |
| bash -c 'cd X && git Y' | Same blocker (subshell variant) |
| git -C X Y | Blocked by many teams' shell-safety rules |
| GIT_WORK_TREE=X git Y env vars | Same — env vars change git's behavior subtly |
The result is subagents that can write code, run tests, and use Read/Edit/Write fine, but cannot do any git operations in a non-default directory. Every multi-worktree workflow loses its agent productivity.
Reproduction
- From a project root, create a git worktree at
../worktree/test. - Launch a subagent (any specialist or
general-purpose) and instruct it to commit a change to a file in../worktree/test. - Observe: subagent attempts
cd ../worktree/testthengit status;cdeither silently doesn't persist orgit statusis blocked due to compound-form interactions.
Today (2026-04-25) I observed this with 5 of 5 subagents I dispatched — backend-engineer, frontend-engineer, infra-devops-specialist, and an audit + execute pair on the same dispatch. Even pwd && git status (no cd at all) was rejected for one of them.
Suggested Fix
Two complementary paths, ideally both:
- Restore CWD inheritance / persistence in subagents, matching main-thread Bash tool behavior. The main thread's Bash tool already persists CWD across calls; subagents should too.
- Add the
cwd:parameter to Task (already requested at #12748). Even with #1 fixed, an explicit dispatch-time CWD removes ambiguity and helps with worktree workflows where the subagent's "starting directory" differs from the parent's.
Related
- #33576 — original bug, locked
- #35023 — TeamCreate variant, closed as duplicate of #33576
- #12748 — feature request for
cwd:parameter on Task tool (open)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗