Skip to main content

Loading…

Skip to main content
HomeProjectsPostsContact
Justin Tsugranes LogoJustin Tsugranes Logo

Justin Tsugranes

HomeProjectsPostsContact

Stay in the loop

Occasional notes on what I'm building, lessons earned, and the studio behind it.

By subscribing, you agree to receive No spam. Unsubscribe in one click anytime. from Justin Tsugranes. No spam. Unsubscribe anytime. Privacy Policy

© 2026 Total Ventures LLC. All rights reserved.

Privacy PolicyTerms of ServiceCookie Policy
Parallelizing Claude Code: Git Worktrees and Agent Workflows | Justin Tsugranes | Justin Tsugranes
Xinf

Parallelizing Claude Code: Git Worktrees and Agent Workflows

Stop fighting git locks. Learn how to run multiple Claude Code agents concurrently using git worktrees and ephemeral branches for conflict-free agentic engineering.

Justin Tsugranes·June 22, 2026·5 min read
On this page
  1. The Git Lock Bottleneck
  2. Why Worktrees are the Answer
  3. The Agent-Worktree Script Architecture
  4. Step 1: Isolation
  5. Step 2: Context Injection
  6. Step 3: The Ephemeral Lifecycle
  7. Handling Dependencies and Environment
  8. Managing the Merge Churn
  9. Monitoring Agent Progress
  10. The Result: Agentic Engineering at Scale

When you move from using one AI agent to orchestrating a fleet, the bottleneck shifts from the LLM's context window to your local file system. If you have tried running multiple instances of Claude Code in a single directory, you have seen the errors: .git/index.lock exists, or one agent overwrites the progress of another because they are both contending for the same HEAD.

In my studio, I run a fleet of agents to handle the work of a team. To keep the machine moving, I had to solve the contention problem. The solution isn't more complex branching logic; it is physical isolation through git worktrees. This is how I parallelize four or more Claude Code agents without merge conflicts or file loss.

The Git Lock Bottleneck

Standard claude-code-workflows usually involve opening a terminal, starting the agent, and letting it work on your current branch. This works for a single task. But as an operator, your goal is to have multiple tasks moving at once.

The moment you open a second terminal and try to run another agent in the same directory, you hit a wall. Git is designed to protect the integrity of the repository, which means it locks the index during writes. If Agent A is mid-commit or mid-stage, Agent B will fail. Even if you manage to avoid the lock, having two agents modifying the same working directory is a recipe for chaos. They will delete each other's temporary files, get confused by unexpected state changes, and eventually produce a merge conflict that requires twenty minutes of human intervention to fix.

I found through trial that you cannot treat an agent like a human developer who "knows" what else is happening in the room. You have to give the agent its own room.

Why Worktrees are the Answer

Git worktrees allow you to have multiple branches checked out simultaneously in separate directories while sharing the same .git history. Unlike a simple git clone, worktrees are linked to the main repository. This means you don't have to manage multiple copies of your dependencies or re-download gigabytes of history.

For claude-code-workflows, worktrees provide the necessary isolation. Each agent gets its own directory, its own index, and its own HEAD. They can run git add, git commit, and git reset as much as they want without ever seeing the other agents.

The Agent-Worktree Script Architecture

I use a script to automate the creation and destruction of these agent environments. The goal is to make spawning an agent as cheap as opening a new tab.

Step 1: Isolation

The script starts by creating a new directory outside of your main working path. I typically keep an agents/ folder in my project root (ignored by git).

``bash git worktree add -b agent-task-xyz ./agents/task-xyz main ``

This command does three things: it creates a new branch (agent-task-xyz), creates a new directory (./agents/task-xyz), and checks out that branch into that directory.

Step 2: Context Injection

Before starting Claude Code, the script copies in any necessary local context that isn't tracked by git—usually .env files or local configuration overrides. This ensures the agent has a functional environment to run tests or build the project.

Step 3: The Ephemeral Lifecycle

The script then initializes the Claude Code session within that specific directory. I pass the initial task description directly to the agent so it can start working immediately.

``bash cd ./agents/task-xyz && claude-code "Implement the new billing logic..." ``

Once the agent signals it is done, the script doesn't just leave the worktree there. It waits for my signal to review.

RecommendedFree

Free download

Get the Launch Checklist →
If this resonated

The studio is where the rest of it lives.

Total Ventures is the umbrella — the products, the resources, the strategy session.

totalventures.io

Studio Notes

How I’m building the studio.

The operator’s log — systems, decisions, and what’s working.

JT

Written by

Justin Tsugranes

Founder, Total Ventures

Solo-founder building a multi-brand product studio with AI agents. Writing about building, operating, and shipping.

ShareXLinkedInFacebook
#claude-code-workflows#git worktrees#agentic engineering#AI agents#software automation

On this page

  1. The Git Lock Bottleneck
  2. Why Worktrees are the Answer
  3. The Agent-Worktree Script Architecture
  4. Step 1: Isolation
  5. Step 2: Context Injection
  6. Step 3: The Ephemeral Lifecycle
  7. Handling Dependencies and Environment
  8. Managing the Merge Churn
  9. Monitoring Agent Progress
  10. The Result: Agentic Engineering at Scale

Handling Dependencies and Environment

One nuance of the worktree approach is dependency management. If your project relies on a massive node_modules folder, running npm install in every worktree will eat your disk space and your time. I use pnpm with a shared store, which makes the "install" step in a new worktree nearly instantaneous and storage-efficient.

If you are using standard npm or yarn, you might consider symlinking your node_modules from the main directory, though this can lead to version mismatches if an agent tries to upgrade a package. The goal is to ensure the agent can run the build and test commands locally without interfering with your primary development environment.

Managing the Merge Churn

The biggest risk with parallel agents is the "long-lived branch" trap. If four agents work for three hours on four separate branches, the final merge back into main will be a nightmare. To solve this, I enforce an ephemeral-branch discipline. No agent branch lives longer than a single discrete task. If a task is too big, I break it down into smaller sub-tasks that can be completed in under thirty minutes.

When an agent finishes:

  1. I perform a quick visual diff of the worktree.
  2. I run the test suite within that worktree.
  3. I merge the ephemeral branch into main using a squash commit.
  4. I delete the worktree and the branch.

``bash git worktree remove ./agents/task-xyz git branch -D agent-task-xyz ``

This keeps the main branch moving forward in small, clean increments. If two agents' work conflicts, I catch it at the merge step of the second agent. Because the tasks are small, the conflict is usually trivial to resolve.

Monitoring Agent Progress

Running four agents means monitoring four streams of output. I use a terminal multiplexer like tmux to keep each agent session visible. I can toggle between windows to see if an agent is stuck in a loop or waiting for permission to run a command. This operator's view allows me to provide the necessary judgment calls—the "yes" to a risky refactor or the "no" to a hallucinated dependency—without being the one typing the code.

The Result: Agentic Engineering at Scale

By moving to this model, I have been able to scale my output without increasing my stress. I can have one agent refactoring a legacy module, another writing unit tests for a new feature, and a third updating documentation—all running at the same time.

This is the core of agentic engineering. It is not about finding a smarter model; it is about building a better system for the models we have. The cost of compute is falling, but the cost of human coordination remains high. By using git worktrees to automate that coordination, I stay in the owner’s seat while the machine does the heavy lifting.

Optimizing your claude-code-workflows is a prerequisite for running a studio as a single operator. If you are still fighting git locks, you are working for the machine. You want the machine working for you.

How are you handling file contention when running multiple agents?

Resources

Launch Checklist + the Builder’s Playbook bundle.

  • Strategy session

    A focused hour on your repo, stack, and monetization.

  • The brands

    The portfolio of products I’m building, end to end.