[FEATURE] `Agent(cwd: ...)` is silently accepted but does not change the spawned subagent's working directory; LSP remains anchored to the parent session

Resolved 💬 1 comment Opened May 27, 2026 by jcmuller Closed Jun 27, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

In Claude Code v2.1.152, the Agent tool accepts a cwd parameter without raising a schema error, but the spawned subagent's actual working directory is the parent session's launch cwd, not the value passed. Because the LSP feature is rooted at the parent session's launch cwd and there is one lsp-mux per session, subagents that are meant to operate inside a sibling worktree have no way to get an LSP rooted there. This blocks correct code-intelligence for any workflow that runs multiple workers in separate worktrees of the same repository, which is the pattern the team-coordinator skill is built around.

Current behavior

  1. Spawn a subagent with Agent(subagent_type: "team-coder", cwd: "/abs/path/to/worktree", ...).
  2. The call succeeds. No warning, no schema rejection.
  3. Inside the subagent, pwd prints the parent session's cwd, not /abs/path/to/worktree.
  4. The session header in the subagent's pane shows the parent's cwd.
  5. LSP(operation: "hover", filePath: "/abs/path/to/worktree/some_file.rb", ...) returns a result, because the mux happily resolves absolute paths anywhere on disk. But the diagnostics that come back are from the parent session's working copy (e.g. files modified in the main checkout), not from the worktree.
  6. ps -fC lsp-mux --no-headers | xargs -n1 pwdx shows exactly one mux, anchored at the parent session's cwd. The cwd argument does not cause a second mux to start.

Proposed Solution

a. Agent.cwd actually sets the spawned subagent's working directory. Document the parameter in the public tools reference.

b. The LSP feature is workspace-aware. Each subagent gets an LSP runtime rooted at its own cwd, or the existing mux gains multi-workspace support keyed by file path with on-demand server start.

c. If neither (a) nor (b) is in scope, document the current cwd behavior so callers do not assume it does what its name implies, and document that LSP is session-anchored.

Alternative Solutions

n/a

Priority

High - Significant impact on productivity

Feature Category

CLI commands and flags

Use Case Example

Develop using agent teams with their own workspace.

Additional Context

Reproduction

$ cd ~/main-checkout
$ claude

inside the session:

Agent(
subagent_type: "Explore",
cwd: "/abs/path/to/sibling-worktree",
prompt: "Print your pwd and exit."
)

the subagent reports pwd = ~/main-checkout, not the sibling worktree.

Version: Claude Code v2.1.152, Opus 4.7. Reproduced with gh-agents:team-coder and likely reproduces with any subagent type since the mechanism is in the parent process.

Impact

The team-coordinator workflow (one coordinator session, N coder subagents in N sibling jj worktrees) cannot deliver correct cross-file LSP results to its workers today. Hover and go-to-definition return data anchored to the wrong tree; find-references skips changes that exist only in worker worktrees. The workaround is launching a separate claude subprocess per worktree, which gives up Agent/SendMessage/team-membership ergonomics and forces the user to rebuild coordination over IPC.

Suggested doc fix regardless

Add an "LSP" section to the settings reference enumerating: how the LSP root is chosen, whether multiple roots are supported, lazy vs eager server start, and whether per-subagent rooting is possible. None of this is currently documented.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗