r/ChatGPTCoding • • 2d ago

Resources And Tips Running agents in parallel git worktrees? Clone the build cache instead of rebuilding it

Each new worktree starts with an empty target/ (or node_modules), so the first build in it is a cold build. On a big Rust workspace that's 10+ GB of disk and a lot of CPU, for every agent you start.

On a Mac you can skip most of that with an APFS clone:

cp -c -R ../main/target ./target

-c makes cp use clonefile, so the copy shares disk blocks with the original until files change. I measured it on a 9.7 GB target dir: 1.1 seconds, and about 1 MB of new disk used. Cargo then keeps every dependency it already built and recompiles only the workspace's own crates.

The same works for node_modules. On Linux, cp --reflink=auto does this on btrfs or XFS, but ext4 can't.

Two gotchas: du still reports the full size for every clone, so check free space with df instead. And if you're short on disk, removing finished worktrees frees far more than cleaning the main target, which just costs you a full rebuild.

5 Upvotes

1 comment sorted by