Summary
When running parallel batch execution (cf work batch run --strategy parallel), give each task its own git worktree instead of having multiple agents modify files in the same working directory. Inspired by Gastown's polecat worktree model, but much simpler.
Motivation
Currently parallel batch execution runs multiple agents in the same workspace directory. This creates race conditions: two agents editing the same file, conflicting git add operations, and verification gates that can't tell which agent broke what.
Gastown solves this with per-agent worktrees — git's built-in mechanism for multiple working directories sharing a single .git object store. This is fast (no full clone), isolated (each worktree has its own branch), and mergeable (standard git merge/rebase).
Keep it simple: We don't need Gastown's persistent polecat pools, sandbox repair, or worktree lifecycle daemons. Just: create worktree before task, run agent in it, merge results after.
Design
For serial execution: no change
Single tasks continue working in the main workspace directory. No overhead.
For parallel execution: worktree per task
cf work batch run task-1 task-2 task-3 --strategy parallel
Creates:
<workspace>/
├── .git/ # shared object store
├── .codeframe/
│ └── worktrees/
│ ├── task-1/ # git worktree on branch cf/task-1
│ ├── task-2/ # git worktree on branch cf/task-2
│ └── task-3/ # git worktree on branch cf/task-3
└── <normal working dir> # main branch, untouched during parallel run
Lifecycle (per task in parallel batch)
git worktree add .codeframe/worktrees/<task-id> -b cf/<task-id>
- Run agent with
cwd set to the worktree path
- Agent modifies files in isolation
- Verification gates run inside the worktree
- On success: merge worktree branch back to main (or create PR)
- Cleanup:
git worktree remove .codeframe/worktrees/<task-id>
Conflict handling
- If merge has conflicts: create a blocker with the conflict details
- Let the human resolve, or re-run the task on top of the merged result
- For simple conflicts: attempt automatic resolution (ours/theirs for non-overlapping changes)
Scope
New module: core/worktrees.py
class TaskWorktree:
def create(self, workspace_path: Path, task_id: str, base_branch: str = "main") -> Path:
"""Create an isolated worktree for a task. Returns worktree path."""
def merge_back(self, workspace_path: Path, task_id: str) -> MergeResult:
"""Merge worktree branch back to base. Returns success/conflict."""
def cleanup(self, workspace_path: Path, task_id: str) -> None:
"""Remove worktree and delete branch."""
Changes to existing files
core/conductor.py — in parallel strategy, create worktrees and pass worktree paths to agents
core/runtime.py — accept optional working_directory override for agent execution
cli/app.py — add --isolate flag to batch run (default: True for parallel, False for serial)
Acceptance Criteria
Dependencies
Complexity Note
This is deliberately simpler than Gastown's model:
- No persistent polecat pools (worktrees created and destroyed per batch)
- No sandbox reuse across batches (fresh worktree each time)
- No daemon-managed lifecycle (CLI-driven)
- No three-layer identity/sandbox/session split (just a worktree)
Summary
When running parallel batch execution (
cf work batch run --strategy parallel), give each task its own git worktree instead of having multiple agents modify files in the same working directory. Inspired by Gastown's polecat worktree model, but much simpler.Motivation
Currently parallel batch execution runs multiple agents in the same workspace directory. This creates race conditions: two agents editing the same file, conflicting
git addoperations, and verification gates that can't tell which agent broke what.Gastown solves this with per-agent worktrees — git's built-in mechanism for multiple working directories sharing a single
.gitobject store. This is fast (no full clone), isolated (each worktree has its own branch), and mergeable (standard git merge/rebase).Keep it simple: We don't need Gastown's persistent polecat pools, sandbox repair, or worktree lifecycle daemons. Just: create worktree before task, run agent in it, merge results after.
Design
For serial execution: no change
Single tasks continue working in the main workspace directory. No overhead.
For parallel execution: worktree per task
Creates:
Lifecycle (per task in parallel batch)
git worktree add .codeframe/worktrees/<task-id> -b cf/<task-id>cwdset to the worktree pathgit worktree remove .codeframe/worktrees/<task-id>Conflict handling
Scope
New module:
core/worktrees.pyChanges to existing files
core/conductor.py— in parallel strategy, create worktrees and pass worktree paths to agentscore/runtime.py— accept optionalworking_directoryoverride for agent executioncli/app.py— add--isolateflag to batch run (default: True for parallel, False for serial)Acceptance Criteria
cwdset to worktree path--no-isolateflag disables worktrees for parallel (old behavior)Dependencies
cwdbefore_taskhook runs in worktreeComplexity Note
This is deliberately simpler than Gastown's model: