[FEATURE] Agent CWD parameter and forwarding agent name to WorktreeCreate hooks

Resolved 💬 3 comments Opened Mar 20, 2026 by rayners Closed Mar 24, 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

When spawning parallel agents in a multi-repo workspace (parent directory containing multiple independent git repos as subdirectories), there's no way to control which repo an agent operates in or to route isolation: "worktree" to a specific subdirectory repo.

Two specific gaps:

  1. No cwd parameter on the Agent tool — agents always inherit the parent session's working directory. There's no way to say "start this agent in ./service-a/."
  1. Agent name not forwarded to WorktreeCreate hook — when using isolation: "worktree", the hook receives an auto-generated slug (e.g., agent-ac7e8aaf) instead of the agent's name parameter. This prevents using naming conventions to route worktree creation to the correct repo.

Context & Testing

We tested this extensively in a workspace with ~15 independent service repos:

~/Code/platform/
├── service-a/    # independent git repo
├── service-b/    # independent git repo  
├── service-c/    # independent git repo

What we tried:

  • isolation: "worktree" on agents → worktrees the parent dir (not a git repo), fails
  • WorktreeCreate hook with service--branch naming convention → hook receives agent-ac7e8aaf, not the agent name, so routing logic can't work
  • Confirmed via debug logging that the hook input contains only: session_id, transcript_path, cwd, hook_event_name, name (auto-generated)

Current workaround: Pre-create git worktrees manually in each service repo, then spawn agents without isolation and embed absolute worktree paths in each agent's prompt. Works but is fragile — agents must remember to cd to the right path for every command.

Proposed Solution

Either or both of:

1. Add a cwd parameter to the Agent tool

{
  "name": "service-a-agent",
  "cwd": "service-a/",
  "isolation": "worktree",
  "prompt": "..."
}

The agent starts in service-a/, and isolation: "worktree" naturally creates a worktree in that repo. Simple, no hooks needed.

2. Forward the Agent name to the WorktreeCreate hook

Pass the Agent tool's name parameter (e.g., "service-a--feature-branch") as the name field in the WorktreeCreate hook input, instead of the auto-generated slug. This lets hooks implement custom routing:

NAME=$(echo "$INPUT" | jq -r '.name')
SERVICE="${NAME%%--*}"
git -C "$CWD/$SERVICE" worktree add ...

Option 1 covers the common case cleanly. Option 2 provides a hook escape hatch for complex workflows. Together they'd fully enable multi-repo agent parallelism.

Related Issues

  • #27590 — Multi-repo worktree-aware collaboration (user-facing /add-git command)
  • #35577 — Multi-repo workspace with coordinated worktrees
  • #35362 — General multi-repo workspace support (closed)

Those issues focus on user-facing multi-repo workflows. This issue is about the lower-level agent spawning primitives that would also enable building those workflows programmatically via teams and hooks.

Alternative Solutions

The manual workaround (pre-create worktrees, embed paths in prompts) works but is verbose and error-prone. No hook-based alternative exists today because the hook doesn't receive enough context to route correctly.

Priority

Nice to have - would make my workflow better

View original on GitHub ↗

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