# Share build caches across Git worktrees for parallel coding agents

> Let multiple Git worktrees reuse one build cache via block cloning so parallel agent runs skip redundant rebuilds.

- Category: [Software & DevOps](https://agentusehub.com/categories/software-and-devops)
- Tools: [Claude Code](https://agentusehub.com/tools/claude-code), [Other or custom](https://agentusehub.com/tools/other)
- Industry: Software
- Difficulty: Intermediate
- Cost: Free
- Source: [Hacker News](https://news.ycombinator.com/item?id=50753293)
- Published: 2026-12-03

## The problem it solves

“Share build caches across Git worktrees for parallel coding agents” is an intermediate Software & DevOps AI agent workflow from Software. It connects Claude Code and Other or custom in 5 steps. Setup takes about Not stated and running costs are about Not stated.

When reviewing or testing changes, switching between Git worktrees creates a separate build folder for each one, so the same dependencies get rebuilt repeatedly and disk space fills up fast. Running coding agents on two approaches in parallel makes this worse, since each worktree duplicates the build output and eats minutes of rebuild time before any real work starts.

## How it flows

Create worktrees → Point at shared cache → Clone blocks on write → Run agents in parallel → Rebuild only changed files

## Step-by-step setup

1. **Set up one warm build cache**: Pick a single worktree as the source of truth and run a full build there so the dependency and build cache directories are fully populated. This becomes the template that every other worktree will share instead of rebuilding from scratch.
2. **Create worktrees that reference the shared cache**: For each task or agent run, add a new Git worktree and configure its build cache path to point at the shared cache location rather than a fresh local folder. Use a tool that supports block cloning so the cache copies share disk blocks until a file is modified.
3. **Run agents in parallel on separate worktrees**: Launch each coding agent in its own worktree so two approaches can be tried at once without stepping on each other. Because the caches are shared, neither run pays the full dependency rebuild cost and disk usage stays close to a single build.
4. **Rebuild only what changed**: When a worktree modifies files, only those changed files take up extra disk space and only the affected build steps rerun. Verify the incremental build completes correctly before trusting the agent's output.
5. **Clean up worktrees when done**: Remove finished worktrees and their cache references so stale branches and partial builds do not accumulate. Keep the original warm cache intact so the next round of parallel runs starts fast.

## Example prompts

### Configure shared cache for worktrees

```text
In my repository at [REPO PATH], I want multiple Git worktrees to share a single build cache instead of each creating its own. Inspect the project's build configuration and identify which directories hold dependency and build caches. Then write a script that, for each new worktree created under [WORKTREE PARENT DIR], points the build cache at [SHARED CACHE PATH] using a copy-on-write or block-cloning mechanism available on my filesystem. Do not modify source files. Print the exact commands and any config changes needed, and explain how to verify that disk blocks are actually shared until files change.
```

### Run two agents in parallel worktrees

```text
Using the repository at [REPO PATH] with the shared build cache already configured at [SHARED CACHE PATH], create two Git worktrees named [WORKTREE A] and [WORKTREE B] from the current branch. In each, start a coding agent task: in [WORKTREE A] implement [APPROACH ONE] and in [WORKTREE B] implement [APPROACH TWO]. Make sure each worktree uses the shared cache so neither triggers a full dependency rebuild. After both finish, report the build time and disk usage for each worktree and summarize the differences between the two approaches so I can pick one.
```

## Frequently asked questions

### What does the “Share build caches across Git worktrees for parallel coding agents” workflow do?

Let multiple Git worktrees reuse one build cache via block cloning so parallel agent runs skip redundant rebuilds.

### Which tools do I need?

You need Claude Code and Other or custom.

### How long does it take to set up?

Plan for about Not stated. It is rated intermediate. The guide walks through 5 steps, starting with “Set up one warm build cache”.

### How much does it cost to run?

Expect about Not stated in running costs (Free range).

### What problem does it solve?

When reviewing or testing changes, switching between Git worktrees creates a separate build folder for each one, so the same dependencies get rebuilt repeatedly and disk space fills up fast. Running coding agents on two approaches in parallel makes this worse, since each worktree duplicates the build output and eats minutes of rebuild time before any real work starts.

---

Canonical: https://agentusehub.com/use-cases/share-build-caches-across-git-worktrees-for-parallel-coding-agents

More: https://agentusehub.com/llms.txt
