Working concurrently without collisions

Lesson 32 of 35 · Working with AI coding agents

Two agents can have separate conversations while editing the same directory. If each reads an old version of a file and then writes changes, one result can overwrite the other. Even edits to different files may conflict when both depend on a shared interface or update the same generated output.

Divide work and verify the handoff

For a small documentation change, one worker might review terminology without editing while another drafts the page. For independent code changes, assign explicit file ownership and describe the interface that joins the pieces. Ask each worker to report its working directory, changed files, tests, and unresolved assumptions. Do not treat a report as proof of isolation: inspect the actual changes and run relevant checks after integration.

Shared starting point
   ├── Worker A: payment validation ── changes + evidence ──┐
   └── Worker B: receipt layout ────── changes + evidence ──┤
                                                           ↓
                                       review → integrate → test together

Separate directories reduce accidental file collisions. A Git worktree is a working directory linked to the same repository, allowing different branches to be checked out in different directories. See the Git worktree documentation. Each worker can make changes in its own worktree, after which a person or coordinating agent reviews and integrates them using the project’s normal Git workflow. Uncommitted files in one working directory are not automatically copied into another; agree on a starting commit and how changes will be handed off.

A worktree is not a sandbox. Linked worktrees share repository data, and processes may still reach the same external databases, credentials, network, ports, or files outside the working directory. Two test servers can compete for a port or alter the same test database even when their code is separate. Use separately scoped test resources and appropriate access controls. Protect existing work before creating or removing working directories, and inspect uncommitted changes before cleanup.

A file watcher monitors configured changes and may trigger a reload or another action. It can help a tool notice an edit, but it cannot decide how to reconcile two conflicting edits. Excluding a path from watcher events does not necessarily exclude it from search or prevent a direct read. Watcher settings, search filters, and filesystem permissions are separate controls.

Parallelism is worthwhile only if the tasks are independent enough and the integration cost is acceptable. If the interface is still being designed, settle it first or work sequentially; merging incompatible assumptions is not a speedup.