[BUG] Sub-agents (Explore, Plan, general-purpose) Bash tool defaults to /root instead of inheriting parent session's working directory
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?
Sub-agents spawned via the Agent tool (including built-in types like Explore, Plan, and general-purpose) have their Bash tool CWD set to /root instead of inheriting the parent session's working directory.
This causes sub-agents to run commands like:
find /root -type f -name "*.md" -path "*metabase/docs*" 2>/dev/null | head -20
find /root -type d -name "metabase" 2>/dev/null
…when they should be searching from the actual project directory (e.g., /Users/espassculture/Development/git-repos/passculture/data-gcp).
The Glob and Grep tools do use the correct working directory, so only the Bash tool is affected. This creates a pattern where the sub-agent wastes turns finding nothing via find/ls, then eventually falls back to Glob/Grep which work correctly.
What Should Happen?
Sub-agents should inherit the parent session's working directory for all tools, including Bash. The Bash tool CWD in sub-agents should match the parent's CWD (or the project root), not default to /root.
Steps to Reproduce
- Start Claude Code in a project directory (e.g.,
/Users/me/Development/my-project) - Launch an Explore agent:
````
Agent(subagent_type="Explore", prompt="Find all markdown files related to docs in this project")
- Observe the Explore agent's Bash commands — they reference
/rootas the base path:
``bash``
find /root -type f -name "*.md" 2>/dev/null | head -20
ls /root/
- The agent finds nothing, wastes several turns, then falls back to Glob/Grep (which correctly use the project directory)
Expected Behavior
The Explore agent should run:
find /Users/me/Development/my-project -type f -name "*.md" 2>/dev/null | head -20
Or simply:
find . -type f -name "*.md" 2>/dev/null | head -20
(with CWD correctly set to the project directory)
Error Messages/Logs
No errors — the commands succeed but search the wrong directory, returning empty results silently.
Claude Model
Sonnet (default) — but applies to all models
Is this a regression?
Unknown — may have always been present
Claude Code Version
2.1.74 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Pycharm terminal
Additional Information
Key observation: Glob and Grep tools in sub-agents correctly use the parent's working directory. Only the Bash tool defaults to /root. This suggests the issue is specific to how the Bash tool's CWD is initialized in sub-agent processes, not a global directory inheritance problem.
Related issues:
- #26429 — Expose project root to Task subagents (
CLAUDE_PROJECT_DIR) - #25140 —
memory: projectresolves relative to subagent's perceived root - #11239 — Plan agent uses main branch path instead of worktree directory
- #31940 — AgentDefinition should support
cwdandadditionalDirectories
This may share root cause with #26429 — sub-agents don't receive proper directory context from the parent session.
This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗