cargo-worktree-builds
БесплатноБез исполняемых скриптовНе проверенShare one CARGO_TARGET_DIR across parallel git-worktree agents so Rust deps compile once. Use when worktrees run cargo concurrently, rebuild deps N times, or…
от laurigates★ 61 звезда на GitHubОб этом скилле
cargo-worktree-builds - Shared Target Dir for Parallel Worktree Agents
When you fan out parallel agents into separate git worktrees of a Rust repo
(one per issue/feature), each worktree builds into its own target/ by
default. For a project with hundreds of dependency crates that means every
worktree pays the full cold dependency build (minutes each) and writes its own
multi-GB target/ — so N worktrees cost ≈ N× time and N× disk for dependency
artifacts that are byte-identical across them.
Point every worktree at one shared, pre-warmed CARGO_TARGET_DIR instead.
Dependencies compile once and are reused; cargo's build lock serializes the
concurrent builds (which also caps CPU/I/O thrash); disk stays ≈ 1× not N×.
When to Use This Skill
| Use this skill when... | Use X instead when... |
|---|---|
| Dispatching parallel agents into multiple git worktrees of one Rust repo | A single working tree — the default target/ is already optimal |
cargo/clippy/test is rebuilding the same deps in each worktree |
Caching deps in CI — use Swatinem/rust-cache@v2 (see cargo-llvm-cov) |
N worktrees are filling the disk with N copies of target/ |
Speeding up a single build — use a faster linker / cargo check |
| Coordinating a multi-worktree wave (see agent-patterns-plugin) | Cross-machine sharing — use sccache, not a shared dir |
Context
- Cargo.toml present: !
find . -maxdepth 1 -name 'Cargo.toml' - CARGO_TARGET_DIR currently set: !
echo "${CARGO_TARGET_DIR:-<unset — each worktree uses its own ./target>}" - Active git worktrees: !
git worktree list
The Pattern
Step 1: Choose one persistent shared target dir
Pick a path outside any worktree (so removing a worktree never deletes the cache) and on the same disk as the checkouts (so cargo can hardlink):
export SHARED_TARGET="$HOME/.cache/<repo>-target"
mkdir -p "$SHARED_TARGET"
Step 2: Pre-warm it ONCE before dispatching agents
A cold shared dir means the first agent to build compiles every dependency crate while the others block on cargo's build lock. Pre-warming from the orchestrator removes that serialized stall from the critical path:
CARGO_TARGET_DIR="$SHARED_TARGET" cargo fetch
CARGO_TARGET_DIR="$SHARED_TARGET" cargo build # compiles all deps once
Step 3: Every worktree command exports the same dir
Prefix every cargo/just invocation in every worktree agent with it:
CARGO_TARGET_DIR="$SHARED_TARGET" just check # fmt + clippy + test
CARGO_TARGET_DIR="$SHARED_TARGET" cargo test
Brief each agent to use this exact prefix. Dependency artifacts are now shared; only each worktree's own crate is recompiled per build.
Why It Works (and the one gotcha)
- Deps compile once. The external dependency graph is identical across worktrees, so the shared dir reuses it. This holds while the branches change only leaf crates; if one changes a crate others depend on, see When Not to Share.
- Cargo's build lock serializes concurrent builds. Two agents building at once won't corrupt the dir — cargo holds an exclusive lock on the target dir during a build, so the second waits. This also throttles total CPU/I/O, which is usually desirable when many agents run at once.
- Disk stays ≈ 1×. One
target/for all worktrees instead of N.
Gotcha: "method not found" / stale-rlib under contention
Because builds serialize on the shared lock, an agent can read a stale rlib
that a concurrent agent built from its own branch, surfacing as a compile error
like no method named X found or a file-lock message, even though this
worktree's code is correct.
When every branch changes only leaf crates, the error is transient. Force a rebuild and re-run:
touch src/lib.rs # or any source file in scope
CARGO_TARGET_DIR="$SHARED_TARGET" just check
When the branches change a non-leaf workspace crate (one that other crates depend on), it is not transient: the collision recurs each time a peer rebuilds that crate, so a re-run does not reliably clear it. The same swap can also go the other way, letting a gate compile and pass against a peer's version of the crate (a false green; inferred from the mechanism, not yet observed). Stop sharing for gate runs, per When Not to Share.
A dispatch brief that tells agents to share a target dir must carry the stale-rlib gotcha: an isolated "method not found" right after a peer build is the shared target, not a code bug.
When Not to Share
If the parallel branches modify any workspace crate that other crates depend
on, not just leaf crates, give each worktree its own CARGO_TARGET_DIR for gate
runs (clippy, tests, anything whose verdict you report). Keep dependency builds
shared through sccache (RUSTC_WRAPPER=sccache) instead of the target dir:
CARGO_TARGET_DIR="
Установить cargo-worktree-builds в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Bash(git worktree list *)Bash(find *)Bash(mkdir *)Bash(cargo fetch *)Bash(cargo build *)Bash(cargo test *)Bash(just check *)Bash(touch *)ReadFAQ
Что делает скилл cargo-worktree-builds?
Share one CARGO_TARGET_DIR across parallel git-worktree agents so Rust deps compile once. Use when worktrees run cargo concurrently, rebuild deps N times, or fill disk with N target/ copies.
Как установить скилл cargo-worktree-builds?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл cargo-worktree-builds запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic