Topic 2 of 5 · 5 min read
Splitting parallel work by file area
Goal: Split a set of tasks across parallel agents so no two agents edit the same files or shared contract.
Before you start any agent, write down which files each one may edit, and settle every shared contract first, so the branches cannot collide.
Check yourself · 1 of 3
What should you decide before starting parallel agents that will use the same data type?
Why it matters
Separate worktrees stop agents from overwriting each other while they work. They do not stop two branches from editing the same lines. Those clashes appear later, as merge conflicts, or worse as code that merges cleanly and is wrong. The cheapest conflict is the one the plan made impossible.
How to do it
- List the tasks and the files each one will likely touch. Ask the agent for a read-only plan first if you do not know.
- Find the overlaps. Shared candidates are the usual suspects: a types file, a database schema, a router, a config, a shared utility, a lock file.
- Freeze the shared contract before anyone starts. Decide the function signature, the API shape or the table columns, write it down, and merge it first or hand it to every agent as fixed text.
- Assign areas by module, layer or directory. One agent owns
api/export/, another ownsui/search/. Write the owned paths into each agent's brief, and say plainly: "Do not edit files outside these paths. If you need a change elsewhere, stop and report it." - Give shared files a single owner, or leave them to a human step after the merge.
Before and after
Weak plan: "Agent A adds CSV export. Agent B adds search filters." Both need a new field on the Order type, both edit routes.ts, and both add a migration with the next number. Three conflicts, and two migrations that both claim version 42.
Fixed plan:
Step 0 (me, first): add Order.exportedAt and the search index column in one migration. Merge to main.
Agent A owns: src/export/**, tests/export/**
Agent B owns: src/search/**, tests/search/**
Nobody else edits: src/routes.ts, src/types/order.ts, db/migrations/**
If a task needs those files: stop, write the request in NOTES.md.
Now the two agents have nothing to fight over, and the shared pieces landed once.
What goes wrong
- Splitting by feature when the code is shared. Two features may both depend on one utility that each agent quietly rewrites.
- Assuming an agent stays in its lane. Without a written boundary, agents "helpfully" edit a nearby file. Check the diff for paths outside the area.
- Contracts that drift. If agent B guesses the shape A will return, they merge cleanly and fail at runtime. Freeze the contract as text, not as hope.
- Generated and lock files.
package-lock.jsonand generated clients change in every branch. Plan who regenerates them, and when.
Examples
Two migrations with one number
Two agents each create db/migrations/042_*.sql. They merge without a text conflict because the filenames differ, but the migration runner refuses to start. A single agent or a human owns migrations, and the schema change lands before the others begin.
Split by layer
A feature needs an API route, a screen and tests. The plan fixes the response shape in a short spec file. One agent owns the route, another the screen, and both code against the spec, not against each other's unfinished work.
Key points
- Worktrees prevent live collisions; only a written split of files prevents merge collisions.
- List the files each task will touch, then look for overlaps in shared types, schemas, routers, configs and lock files.
- Freeze shared contracts first, as text or a merged change, before any agent starts.
- Write each agent's owned paths into its brief and tell it to stop and report if it needs anything outside them.
- Check each finished diff for paths outside the agent's assigned area.
Common mistakes
- Assigning two features that both change the same shared file.
- Writing the task split but not the owned paths into each agent's brief.
- Leaving the shared contract for the agents to agree between themselves.
- Not checking finished diffs for edits outside the assigned area.
Check yourself · 2 of 3
Which split of two tasks is least likely to collide?
Check yourself · 3 of 3
An agent in its own area needs a change to a shared config file. What should its brief tell it to do?
Practice items, not counted towards your mastery.
Start here
- git-worktree documentation (opens in a new tab)DocsFree
Official reference for add, list, remove and prune: one repository, several working folders.
- Common workflows (Claude Code docs) (opens in a new tab)DocsFree
A vendor's own section on running parallel sessions with worktrees.
- Embracing the parallel coding agent lifestyle (Simon Willison) (opens in a new tab)ArticleFree
A practitioner's account of why review speed, not agent speed, is the limit.
More for this topic
- Small CLs (Google Engineering Practices) (opens in a new tab)ArticleFree
Why small, self-contained changes are reviewed faster and merge with fewer surprises.