Problem
Today worktree creation is manual (git worktree add ...) and error-prone. The worktree=true agent parameter fails when the workspace root is not a git repo (e.g., /Volumes/VIXinSSD/CW contains codewhale/ as the git repo). Worktrees accumulate indefinitely — after a 40-agent session, 40 worktrees with their own build artifacts consume significant disk space.
Scope
Add a worktree pool manager that:
- Auto-detect git root — Walk up from the agent's cwd to find the actual
.git directory, even if the workspace root isn't a git repo
- Worktree lifecycle — Create on agent start, auto-delete on agent completion (with configurable TTL for inspection)
- Shared build cache — All worktrees share a single
target/ directory via CARGO_TARGET_DIR to avoid 40× build artifact duplication
- Name collision resolution — Auto-generate unique worktree names, no manual
fix-3985 → w3-3984 gymnastics
- Concurrency limits — Cap simultaneous worktrees to avoid filesystem pressure
- Cleanup on session end — Prune all session worktrees when the parent exits
Non-goals
- Not changing git-worktree semantics. This is a management layer, not a git replacement.
- Not auto-committing or pushing from worktrees. Agents still control their own git operations.
Acceptance
worktree=true works regardless of whether the workspace root is a git repo
- 30+ concurrent agents each get an isolated worktree without name collisions
- Build artifacts are shared via a common target directory
- Worktrees are auto-cleaned within 5 minutes of agent completion
- Disk usage for 30 concurrent agents is <2× single-worktree usage
- Tests: create/destroy 10 worktrees in parallel, verify isolation and cleanup
Related
Problem
Today worktree creation is manual (
git worktree add ...) and error-prone. Theworktree=trueagent parameter fails when the workspace root is not a git repo (e.g.,/Volumes/VIXinSSD/CWcontainscodewhale/as the git repo). Worktrees accumulate indefinitely — after a 40-agent session, 40 worktrees with their own build artifacts consume significant disk space.Scope
Add a worktree pool manager that:
.gitdirectory, even if the workspace root isn't a git repotarget/directory viaCARGO_TARGET_DIRto avoid 40× build artifact duplicationfix-3985→w3-3984gymnasticsNon-goals
Acceptance
worktree=trueworks regardless of whether the workspace root is a git repoRelated