Worktree-isolated agent's worktree is cleaned at turn end while its background children still reference it
An agent spawned with isolation: "worktree" that dispatches its own background subagents and ends its turn (to be resumed on their completion) has its worktree auto-cleaned at turn end — while the background children still reference that path.
Observed effects mid-run (11-agent research orchestration, WSL2/ext4):
- Bash tool refusing all calls in affected children (cwd gone)
- Write guard refusing the shared-checkout path, stranding one child's completed output in a recreated stub tree
- git commands in the emptied directory resolving to the PARENT repository (no .git left in the stub), so child git reads silently hit the wrong tree
- Recreating the worktree at the same path restores children, but each subsequent parent turn-end cleans it again
Related same-root-cause behavior: once the parent's turn ends, its background children's completion notifications re-home to the root session instead of resuming the parent — a wave-based orchestrator silently stops orchestrating.
Ask: tie worktree lifetime to the agent's lifetime including live background children, not to its turn — or document the constraint and have the Agent tool warn when a worktree-isolated agent backgrounds children.
🤖 Generated with Claude Code
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗