Skip to content

One task, one branch, one worktree

2 min readAgentsFlower team

Abstract cover art: a ruled ledger with one highlighted row, representing one task owning one lane

Two coding agents working in the same checkout do not need to be malicious to break each other. One reformats a file the other is editing; one renames a symbol while the other still references it; a git stash meant as a scratch pad swallows a colleague’s draft. The failure is structural, not intentional — and structure is fixable.

The unit of work

AgentFlow’s unit of work is the Task File: a single Markdown contract in .agentflow/tasks/ that names a role, a branch, a worktree, the files the worker may touch, the acceptance criteria and the commands that prove them. One task means exactly one worker, in exactly one place.

The git discipline is deliberately boring:

  • One branch per task, named after it — t-002-landing-blog.
  • One worktree per task, outside the main checkout — the launcher creates it before the worker starts.
  • One commit per task, labeled [T-002] feat: ..., holding nothing but that task’s changes.
  • One fresh session per task — no context carried over from unrelated work.

Because each task’s Allowed files list is disjoint from every other open task’s, parallel workers can never legally write the same line. The overlap check happens at launch, before a process exists.

Why a worktree and not just a branch

A branch alone still shares the working directory. Two branches in one folder means constant switching, half-staged edits, and “did I commit that on the right branch?” mistakes — humans make them, agents make them faster.

A git worktree gives each task its own directory on the same repository: the task branch is checked out there, main stays untouched in the main folder, and git status in one never lies about the other. When the task is accepted, the worktree is removed and the branch deleted. Nothing lingers.

The end check

Isolation is enforced, not just hoped for. When a worker’s attempt ends, the launcher re-reads the worktree: the Task File copy inside it must be unmodified, the branch must hold only the task’s commit, and nothing may be left uncommitted. A worker that wrote outside its lane fails the check even if the code is beautiful.

The honest limitation matters too: this is a git-worktree boundary plus post-attempt verification, not a kernel sandbox. It catches drift and collisions reliably because both surfaces are small and auditable — every allowed path is written down before work begins.

What this buys the human

You can run several tasks in parallel and review each one as a clean, single-commit diff against main. The review question stops being “what did the agent do to my repository” and becomes “does this one commit do what the Task File asked” — a much smaller question, and one the checks have already half-answered.