[FEATURE] Agent CWD parameter and forwarding agent name to WorktreeCreate hooks
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:
- No
cwdparameter 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/."
- Agent
namenot forwarded to WorktreeCreate hook — when usingisolation: "worktree", the hook receives an auto-generated slug (e.g.,agent-ac7e8aaf) instead of the agent'snameparameter. 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--branchnaming convention → hook receivesagent-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-gitcommand) - #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
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗