Repository navigation
Description
Problem
When /exec spawns parallel agent groups (multiple implementation agents working simultaneously), all agents operate within the same issue worktree. If two agents in the same group edit overlapping files — or even the same file — one agent's changes can silently overwrite the other's, producing corrupted output or merge conflicts that surface only at commit time.
Current mitigation relies on the /spec phase to partition work into non-overlapping file sets per group. This works in practice (~67% parallel success rate) but is fragile: the spec author (an LLM) must correctly predict all file dependencies, and shared files like index.ts barrel exports or package.json are common collision points.
Claude Code now supports isolation: worktree in subagent definitions, which gives each agent its own copy of the repository. This could eliminate file conflicts structurally rather than relying on careful task partitioning.
Current Behavior
/execparallel groups: all agents share the issue worktree at../worktrees/feature/<issue>-<slug>/- Agents write to the same filesystem concurrently
- File conflicts are detected only after agents complete (if at all)
ClaudeCodeDriverusespermissionMode: "bypassPermissions"— agents can write anywhere
Desired Behavior
Each parallel group agent gets an isolated worktree. After all agents in a group complete, their changes are merged back into the issue worktree. Conflicts are detected and resolved (or reported) before proceeding to the next group.
Acceptance Criteria
1. Investigation and feasibility (P0)
- AC-1: Document how Claude Code's
isolation: worktreeinteracts with sequant's existing worktree management (../worktrees/feature/<issue>-<slug>/) - AC-2: Test whether
isolation: worktreecan nest inside an existing worktree (the issue worktree is already a worktree — can a sub-worktree be created within it?) - AC-3: Document the merge-back strategy: how do isolated agent changes return to the issue worktree? Options: cherry-pick, merge, diff-apply
- AC-4: Measure overhead: worktree creation/cleanup time for a typical repo size
2. WorktreeCreate hook integration (P0)
- AC-5: If built-in
isolation: worktreepath (<repo>/.claude/worktrees/<name>/) conflicts with sequant's convention, implement aWorktreeCreatehook to customize the path - AC-6: Sub-worktrees for parallel agents use naming convention:
../worktrees/feature/<issue>-<slug>/.exec-agent-<N>/(or equivalent that's clearly scoped to the parallel group) - AC-7:
.worktreeincludefile created (or documented) to carry environment files into sub-worktrees
3. Merge-back implementation (P1)
- AC-8: After all agents in a parallel group complete, changes are merged back into the issue worktree
- AC-9: If merge conflicts occur, they are detected and reported with file paths and conflict markers — not silently dropped
- AC-10: Merge-back strategy handles the common case: agents created new files (no conflict) and agents modified shared files (potential conflict)
- AC-11: If a merge conflict cannot be auto-resolved, the
/execskill reports it and continues with the non-conflicting changes, flagging the conflict for the next iteration
4. Cleanup (P1)
- AC-12: Sub-worktrees are removed after successful merge-back
- AC-13: Sub-worktrees are removed on agent failure (partial results are preserved in the issue worktree if merge-back already occurred)
- AC-14: Orphaned sub-worktrees from interrupted sessions are cleaned up by sequant's existing worktree cleanup scripts
5. Opt-in and fallback (P1)
- AC-15: Isolation is controlled by setting:
.sequant/settings.json→agents.isolateParallel: true|false(default:false— opt-in for v1) - AC-16: When disabled, behavior is identical to current (shared worktree)
- AC-17: CLI flag
--isolate-paralleloverrides setting
6. Skill integration (P2)
- AC-18:
/execSKILL.md parallel group section updated with isolation logic - AC-19: All three skill directories synced
- AC-20:
/execlogs which mode was used (shared vs. isolated) for debugging
Design Notes
Nested Worktree Question
The critical unknown: can git worktree add create a worktree rooted inside another worktree? Git documentation suggests this is supported (worktrees are just branches checked out at different paths), but edge cases around .git file resolution need testing. If nesting isn't supported, sub-worktrees would need to be siblings at the ../worktrees/ level.
Fallback: If nesting fails, use ../worktrees/exec-agents/<issue>-<slug>-agent-<N>/ as the sub-worktree path.
Merge-Back Strategy Comparison
| Strategy | Pros | Cons |
|---|---|---|
| git merge | Conflict detection built-in, preserves history | Requires branch per agent, more git operations |
diff-apply (git diff | git apply) |
Lightweight, no branch needed | No conflict markers, fails on overlap |
| cherry-pick | Preserves individual commits | Requires commits, complex with multiple |
| rsync + git add | Simple file copy, no git complexity | No conflict detection, last-write-wins |
Recommended: git merge with temporary branches. Each agent commits to its worktree's branch; merge-back uses git merge --no-ff into the issue branch. Conflicts produce standard markers that the next /exec iteration can resolve.
Interaction with Claude Code's Built-in Isolation
Two options:
- Use
isolation: worktreein agent definition — Claude Code manages sub-worktree lifecycle. Simpler but less control over path naming and merge-back. - Manage sub-worktrees in skill logic —
/execSKILL.md creates worktrees before spawning agents, passes path in prompt. More control, more complexity.
Option 2 is recommended for v1: sequant already has worktree management expertise, and merge-back logic needs custom handling that isolation: worktree auto-cleanup would interfere with.
Parallel Group Flow (With Isolation)
/exec parallel group:
1. For each agent in group:
a. git worktree add ../worktrees/exec-agents/<issue>-agent-<N> -b exec-agent-<N>
b. Spawn agent with cwd set to the sub-worktree path
2. Wait for all agents to complete
3. For each completed agent:
a. cd to issue worktree
b. git merge --no-ff exec-agent-<N> (from sub-worktree)
c. If conflict: record, continue with non-conflicting agents
d. git worktree remove ../worktrees/exec-agents/<issue>-agent-<N>
4. Report: N agents merged, M conflicts (if any)
5. Proceed to next group or sequential tasks
Out of Scope
- Isolation for
/qaagents — QA agents are read-only (they run checks but don't edit code) - Isolation for single-agent
/exec(non-parallel) — no conflict possible with one agent - Refactoring sequant's existing per-issue worktree management
- Agent teams as an alternative to parallel groups
Files Affected
.claude/skills/exec/SKILL.md— parallel group section updatetemplates/skills/exec/SKILL.md— mirrorskills/exec/SKILL.md— mirrorsrc/lib/settings.ts— addagents.isolateParallelsettingbin/cli.ts— add--isolate-parallelflagscripts/dev/cleanup-worktree.sh— handle exec-agent sub-worktree cleanup.worktreeinclude— new (if env file propagation needed)
References
- Claude Code worktree isolation: https://code.claude.com/docs/en/sub-agents (
isolation: worktree) WorktreeCreatehook: fires when worktree is created, can customize path/branch- Sequant worktree management:
scripts/dev/new-feature.sh,scripts/dev/cleanup-worktree.sh /execparallel groups:.claude/skills/exec/SKILL.md(lines 1491-1548)- Parallel success rate: 67% (vs. 72% single-issue baseline)
- Issue Improve multi-issue reliability: default to parallel worktrees and add spec retry logic #452: Improve multi-issue reliability: parallel worktrees (related, different scope)
Activity
admarble commentedon Apr 6, 2026
→ PROCEED — Worktree isolation eval for /exec parallel groups, clear ACs
spec → exec → qa · 20 ACs · -q (AC-1–AC-4 are investigation/feasibility — may pivot design)
Chain after #483 (settings.ts, bin/cli.ts overlap)
admarble commentedon Apr 7, 2026
Spec Plan — #485: Worktree Isolation for /exec Parallel Agent Groups
AC Checklist (20 items + 3 derived)
Investigation & Feasibility (P0)
isolation: worktreeinteraction with sequant worktree managementWorktreeCreate Hook (P0)
../worktrees/exec-agents/<issue>-<slug>-agent-<N>/.worktreeincludeor env file propagation to sub-worktreesMerge-back (P1)
Cleanup (P1)
Opt-in & Fallback (P1)
agents.isolateParallelsetting in.sequant/settings.json(default: false)--isolate-paralleloverrides settingSkill Integration (P2)
/execSKILL.md parallel group section updatedDerived
worktree-isolation.tsfunctionsdocs/reference/worktree-isolation.mdImplementation Plan
Phase 1 — Investigation (AC-1–4): Test nested worktrees, benchmark overhead, evaluate merge strategies, document findings.
Phase 2 — Settings & CLI (AC-15–17): Add
isolateParalleltoAgentSettingsinsettings.ts, wire--isolate-parallelflag inbin/cli.ts.Phase 3 — Core (AC-5–11, AC-21): Create
src/lib/worktree-isolation.tswith sub-worktree creation, env file propagation, merge-back viagit merge --no-ff, conflict detection, and fallback to shared mode.Phase 4 — Cleanup (AC-12–14): Post-merge cleanup, failure cleanup, orphan detection in
cleanup-worktree.sh.Phase 5 — Skill Integration (AC-18–20): Update exec SKILL.md with conditional isolation logic, sync all 3 directories, add mode logging.
Design Decisions
git merge --no-ff../worktrees/exec-agents/false)Verification Methods
Open Questions
git worktree addnest inside another worktree? Phase 1 will answer; fallback is sibling path.node_modulessharing: Symlink vs fresh install for sub-worktrees. Symlink preferred for speed.settings.ts/bin/cli.ts. Proceed; rebase after Add user-configurable agent overrides and graceful maxTurns handling #483 if needed.Recommended Workflow
Phases: spec → exec → qa
Quality Loop: enabled (20 ACs, scope concerns)
feat(#485): add worktree isolation for /exec parallel agent groups
admarble commentedon Apr 7, 2026
/fullsolve Complete
Issue: #485
Status: READY_FOR_MERGE
Summary
Key Changes
src/lib/worktree-isolation.ts— sub-worktree create, merge-back, cleanupagents.isolateParallelsetting +--isolate-parallelCLI flag/execSKILL.md updated with isolation logic (3 directories synced)cleanup-worktree.shhandles orphaned sub-worktreesdocs/reference/worktree-isolation.md— investigation + architecture docsInvestigation Results
git merge --no-ffprovides built-in conflict detection with standard markersIterations
PR: #500
Ready for human review and merge.
fix(#485): propagate --isolate-parallel flag, bridge TS API, add .wor…
feat(#485): add worktree isolation for /exec parallel agent groups (#500
admarble commentedon Apr 8, 2026
Documentation Generated
File:
docs/features/worktree-isolation.mdSections Included:
.worktreeincludeusage)Note: The existing
docs/reference/worktree-isolation.mdcovers internals (investigation results, merge strategy comparison, API reference). This new doc covers the user journey.Next Steps:
Ready to merge!
docs(#485): add user-facing worktree isolation documentation
docs: surface --isolate-parallel in README "What's new"