Want AI to work in parallel? First give each one its own workspace

Running multiple AI agents on one project is hard.

If you give several agents access to the same folder, they will overwrite your files. They will mess up your project state. You end up with a broken mess.

You need isolation.

There are two ways to use AI in parallel:

  • Read-only tasks: One agent reads logs while another reads docs. They can share one workspace.
  • Write tasks: Multiple agents edit code. They must have separate workspaces.

I tried using separate folder clones to solve this. It failed because of disk space. Large projects with many dependencies take up gigabytes. Cloning them multiple times wastes storage.

I switched to git worktree.

Git worktree allows you to have multiple working directories for one repository. They all share the same .git history. This saves disk space and stays organized.

Here is how to use it with AI:

  1. Subagent parallelism: Tell the AI to run tasks in parallel. It can create its own worktree automatically.

  2. Manual parallelism: If you open several AI terminals yourself, the AI does not know about the others. You must tell it: "Another AI is editing this directory. Work in worktree mode."

The workflow follows these steps:

  • Split tasks into independent parts.
  • Assign each part to a unique worktree.
  • Use a lead agent to merge changes back to the main branch one by one.
  • Verify the code after every merge.
  • Delete the worktree once the task is done.

Cleanup is vital. Forgotten worktrees eat your disk space. I added a rule to my AI instructions: verify all commits are in the main branch before deleting a worktree. This prevents losing work.

Do not use worktrees for tiny tasks. If you only change one file, stay in one workspace. Use worktrees for complex features.

One rule stays the same: never work on the trunk directly. Always start on a new branch. This keeps your main code clean and safe.

Git worktree is an old tool. But for parallel AI workflows, it is the perfect solution.

Are you interested in why AI does not stop us from feeling exhausted at the end of the day? Let me know in the comments.

Source: https://dev.to/kanfu-panda/want-ai-to-work-in-parallel-first-give-each-one-its-own-workspace-40ch

Optional learning community: https://t.me/GyaanSetuAi