Sub topic 5
Choosing tasks that can run side by side
This chapter assumes you are comfortable with everyday Git (commit, branch, merge, diff) and basic shell use. It also assumes you have run a command-line coding agent on a single task. Worktrees remove file collisions during the work. They do not remove conflicts at merge time. The way you split the work decides whether the merge is easy or painful.
What makes two tasks independent
Two tasks are independent when an agent can finish one without needing the result of the other, and when they edit different parts of the code. Check three things before you start both.
- Files touched. The tasks should change different files, or at least different regions of a shared file.
- Interfaces. If task A changes a function signature that task B calls, B depends on A.
- Order. If B needs A's output to be correct (a new database column, a renamed module), run A first.
Overlap in a file is not always fatal. Two agents adding separate functions to the same file usually merge cleanly. Two agents rewriting the same function will not.
Good and poor candidates
| Task type | Parallel-friendly? | Reason |
|---|---|---|
| Add a new feature in its own module | Yes | New files rarely conflict |
| Write tests for existing code | Yes | Tests are separate from source |
| Fix unrelated bugs in different modules | Yes | Edits are far apart |
| Rename a function used everywhere | No | Touches many files others also edit |
| Change a shared data model | No | Other tasks depend on it |
| Reformat or lint the whole repo | No | Touches every file |
Estimate the overlap
Before you launch, list the files each task will probably change. A quick search helps you guess.
grep -rl "def charge_card" src/
grep -rl "from billing import" src/If the same file appears in two task lists, either reassign the work or accept that you will resolve that conflict by hand. Chapter 11 covers conflict resolution.
Write the tasks down
Each agent works alone, so give it a self-contained description. A short file per task works well, and the automation examples later in this tutorial refer to a TASKS.md file.
## auth
Goal: add rate limiting to the login endpoint.
Touch only: src/auth/, tests/auth/
Do not change: src/models/, shared config files.
Done when: `pytest tests/auth` passes.The "Touch only" and "Do not change" lines act as boundaries. Agents do not always respect them, so check the diff when the work is done (see the review chapter).
Handling dependent work
When tasks do depend on each other, you have two options.
- Sequence them. Run the foundation task, merge it into
main, then create the next worktrees from the updatedmain. - Split out the shared piece. Move the shared change (for example, the new interface) into its own early task. Then run the dependent tasks in parallel on top of it.
Exercise
Exercise
You plan three parallel tasks: (1) add a CSV export module, (2) rename get_user to fetch_user across the codebase, (3) add tests for the invoice module. Which task should not run in parallel with the others, and why?
Show answer
Task 2. The rename touches many files, including ones the other two tasks will edit or import from, so it will conflict at merge time. Run it before or after the other two. Tasks 1 and 3 touch separate new or test files and can run side by side.
Exercise
Two tasks both need a new status column on the orders table. How would you split the work?
Show answer
Make the column change its own task. Run it first and merge it into main. Then create the two worktrees from the updated main so both tasks start with the column already in place.