[BUG] Subagents inherit server cwd instead of parent session worktree 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?
When using claude remote-control –spawn worktree, each session correctly gets its own git worktree as its working directory. However, subagents spawned via the Agent tool from within those sessions inherit the claude remote-control server process's cwd instead of the parent session's worktree path.
The subagent's system prompt correctly shows the worktree as "Primary working directory", but the actual shell cwd for Bash commands points to the server's original directory.
This causes subagents to read/write files in the wrong directory silently — edits land in the main clone instead of the worktree branch.
What Should Happen?
Subagents should inherit the parent session's working directory (the worktree), not the server process's cwd.
Error Messages/Logs
Steps to Reproduce
- Start
claude remote-control –spawn worktree –no-create-session-in-dirfrom/data/repo - Create a session — it correctly gets worktree
/data/repo/.claude/worktrees/<session-id> - From that session, use the Agent tool to spawn a subagent
- In the subagent, run
pwdvia Bash tool - Result:
pwdreturns/data/repo(server cwd) instead of the worktree path
Claude Model
Not sure / Multiple models
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.92 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Non-interactive/CI environment
Additional Information
Setup: claude remote-control –spawn worktree –no-create-session-in-dir in Docker (node:22-slim), multiple concurrent sessions per server.
Workaround: PreToolUse hook on Bash that compares cwd (from hook JSON payload) against process cwd and warns via stderr. Companion .claude/rules/ file teaches agents to self-correct.
This issue was drafted with agent assistance (Claude Opus 4.6)
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗