[BUG] Subagents inherit server cwd instead of parent session worktree directory

Resolved 💬 5 comments Opened Apr 15, 2026 by haynzz Closed May 24, 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?

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

  1. Start claude remote-control –spawn worktree –no-create-session-in-dir from /data/repo
  2. Create a session — it correctly gets worktree /data/repo/.claude/worktrees/<session-id>
  3. From that session, use the Agent tool to spawn a subagent
  4. In the subagent, run pwd via Bash tool
  5. Result: pwd returns /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)

View original on GitHub ↗

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