Subagents should inherit their worktree's cwd + permission scope across tool calls (instead of resetting to the main repo dir)

Open 💬 0 comments Opened Jun 22, 2026 by yucizhou

Summary

Since agent teams were consolidated into in-process subagents (~v2.1.178+), a subagent that is meant to operate inside a git worktree does not stay scoped to that worktree. Its Bash working directory defaults back to the main repository directory on tool calls, and it does not inherit the worktree's permission/sandbox scope (e.g. the worktree's .claude/settings.local.json).

Request: make a worktree-assigned subagent inherit (a) its worktree as the persistent working directory and (b) the worktree's permission/sandbox rules, applied on every tool-call round — rather than resetting to the main repo dir each round.

Current behavior

  • Under the previous team model, each teammate effectively ran rooted in its own worktree (separate process / split context), so the worktree's settings and filesystem boundary applied to it.
  • With in-process subagents, a subagent intended to work in .../.claude/worktrees/<name> has its Bash cwd default to the main repo root. Relative-path operations therefore resolve against the main tree:
  • file writes/saves via relative paths land in the main working tree
  • git commands run against the main checkout / main branch instead of the worktree branch
  • The subagent also does not pick up the worktree's settings.local.json (permissions, sandbox), so per-worktree guardrails aren't enforced for it.

Why this matters

  • The isolation guarantee that motivates worktrees (a teammate cannot accidentally touch the main tree / main branch) is lost for in-process subagents.
  • The only reliable workaround today is to launch a separate claude process rooted in each worktree, which defeats the convenience of spawning subagents via the Agent tool and complicates parallel multi-worktree workflows.
  • Agent(isolation: "worktree") exists, but the ask is that whatever worktree a subagent is assigned to becomes its persistent cwd + permission scope for the subagent's lifetime, not just a one-time setup at creation.

Proposed behavior

When a subagent is created for / dispatched into a worktree (via isolation: "worktree", or into an existing worktree path), it should:

  1. Use that worktree directory as its working directory, persisted across all tool calls (not reset to the main repo root each round).
  2. Inherit and enforce that worktree's permission + sandbox configuration (.claude/settings.local.json) on every tool call.

Read-only / exploration subagents in different worktrees should remain able to run in parallel — this request is about making writes/commits correctly scoped, not about serializing concurrent worktree work.

Acceptance criteria

  • A subagent dispatched into worktree X: pwd resolves under worktree X on every Bash call; relative-path writes land in worktree X; git operates on worktree X's branch.
  • The worktree's settings.local.json permission/hook scope is applied to that subagent's tool calls.
  • Multiple subagents in distinct worktrees run concurrently, each correctly scoped.

Environment

  • Claude Code 2.1.185, Linux

View original on GitHub ↗