Spawn agents with cwd set to their worktree #86

Closed
opened 2026-01-10 18:39:38 +00:00 by HugoNijhuis · 1 comment
Owner

Problem

When using /spawn-issues to implement multiple issues in parallel, the orchestrator creates git worktrees as sibling directories:

  • Main repo: /path/to/repo
  • Worktrees: /path/to/repo-issue-X, /path/to/repo-pr-Y

However, spawned agents (issue-worker, pr-fixer, code-reviewer) have their cwd locked to the main repo directory. When they try to access files in their worktree, they get permission denied because the worktree path is outside their sandbox.

Current Behavior

Agent spawned with cwd: /path/to/aether
Agent tries: cd ../aether-pr-49 or Read /path/to/aether-pr-49/file.go
Result: "Permission denied (prompts unavailable)"

The agents get stuck in infinite retry loops.

Expected Behavior

Agents should be spawned with their cwd set to the worktree they'll be working in:

Agent spawned with cwd: /path/to/aether-pr-49
Agent tries: Read file.go
Result: Success

Proposed Solution

  1. The Task tool should accept an optional cwd parameter to set the agent's working directory
  2. The spawn-issues skill should pass the worktree path as cwd when spawning workers/fixers/reviewers

Workaround

For now, worktrees could be created inside the repo (.worktrees/pr-49), but this loses the clean isolation of sibling directories.

Affected Skills

  • spawn-issues
  • issue-worker
  • pr-fixer
  • code-reviewer
## Problem When using `/spawn-issues` to implement multiple issues in parallel, the orchestrator creates git worktrees as sibling directories: - Main repo: `/path/to/repo` - Worktrees: `/path/to/repo-issue-X`, `/path/to/repo-pr-Y` However, spawned agents (issue-worker, pr-fixer, code-reviewer) have their cwd locked to the main repo directory. When they try to access files in their worktree, they get permission denied because the worktree path is outside their sandbox. ## Current Behavior ``` Agent spawned with cwd: /path/to/aether Agent tries: cd ../aether-pr-49 or Read /path/to/aether-pr-49/file.go Result: "Permission denied (prompts unavailable)" ``` The agents get stuck in infinite retry loops. ## Expected Behavior Agents should be spawned with their cwd set to the worktree they'll be working in: ``` Agent spawned with cwd: /path/to/aether-pr-49 Agent tries: Read file.go Result: Success ``` ## Proposed Solution 1. The Task tool should accept an optional `cwd` parameter to set the agent's working directory 2. The spawn-issues skill should pass the worktree path as cwd when spawning workers/fixers/reviewers ## Workaround For now, worktrees could be created inside the repo (`.worktrees/pr-49`), but this loses the clean isolation of sibling directories. ## Affected Skills - spawn-issues - issue-worker - pr-fixer - code-reviewer
Author
Owner

is it maybe smarter to have the coordinator part in spawn-issues be the one to set up the worktrees for the background agents and clean them up after?

is it maybe smarter to have the coordinator part in spawn-issues be the one to set up the worktrees for the background agents and clean them up after?
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: flowmade-one/architecture#86