huacnlee/cargo is a fork of Cargo, the Rust build tool. Install it and it replaces your cargo, with nothing to configure. Git worktrees and projects share build output that stays under a size limit on its own, so you can run as many AI agents as you like, stop deleting target, and stop rebuilding from scratch.
$ curl -fsSL https://huacnlee.github.io/cargo/install.sh | sh
Installs over ~/.cargo/bin/cargo and keeps the rustup proxy as cargo.rustup. cargo +nightly and rust-toolchain.toml keep working. Run the script with --uninstall to put the proxy back.
Install once, stay current. At most once a day, after a command, cargo checks for a new release in the background and installs it: checksum verified, renamed into place, nothing printed. The last result is in ~/.cargo/.fork-update.log. Set CARGO_FORK_AUTO_UPDATE=0 to turn it off; it never runs in CI.
Why I built this
Rust is one of the most valuable languages of the AI era, but target became my biggest headache: a 2 TB drive was not enough. The tools I tried did not solve it, so I changed Cargo itself. Read the background.
Day five, nothing deleted
It now runs on four of my computers: two Linux, one macOS and one Windows, which has seen less use. On Linux and macOS it has run for five days straight, full of worktrees doing automated AI development. I have not cleaned a target directory once, and the disk has not filled up again.
My home directory on Omarchy, November 4, 2026, in Disktree. All Rust build output is 41.7 GB. All my checkouts and worktrees, in work, are 9.9 GB. 711.9 GB of the disk is free.
Worktrees stop adding up. In a 525-crate workspace, each new worktree adds about 0.4 GB instead of 6.7 GB.
The disk looks after itself. Each project keeps to twice its largest build of the last day. There is no cron job and no cargo clean to remember.
Nothing builds from scratch. Since the build directory stays, a new worktree of the same commit builds in 5 s instead of 106 s, and the machine stays usable while agents work.
Rust still compiles slower than languages like Go. That is a trade I accept: we wait a little, and users get the faster app.
5 git worktrees of a 525-crate Rust workspace, each built once. Measured.
Disk used
5.1 GBvs 33.6 GB with Cargo, 6.6× less
Cargo
33.6 GB
Fork
5.1 GB
Build time
1.6 minvs 8.5 min with Cargo, 5.3× faster
Cargo
8.5 min
Fork
1.6 min
nsh, a 525-crate workspace, dev build of one binary per worktree on an 8-core Apple Silicon Mac, Rust 1.99 stable. Five worktrees of the same commit in one run; edits are the median of three runs. Compiler caches such as sccache off.
Cargo
This fork
Total disk 33.6 GB → 5.1 GB
12345
Total build time 8.5 min → 1.6 min
12345
Each worktree is a fresh checkout building one binary. Cargo gives every worktree its own target directory and compiles all dependencies again. The fork compiles them once and reuses them, so later worktrees only build the workspace crates.
One worktree, first build
Empty build directory. Most of the difference is debug info that dependencies no longer carry.
Cargo
111.4 s
Fork
77.2 s
Rebuild after editing a core crate
Edit nsh-core, which most of the workspace depends on, in the second of two worktrees. About as fast as Cargo, the first edit in a new worktree included; Cranelift on nightly.
Cargo
9.1 s
Fork
9.7 s
Fork, nightly
9.2 s
Undo the edit
The files match a build made before, so the fork reuses it; Cargo compiles the crates again.
Cargo
8.8 s
Fork
3.4 s
Fork, nightly
3.2 s
Projects share dependencies too
Release builds of Cargo 1.99.0 and this fork, run one after another on the same machine: nsh, then mado (a 330-crate app in its own repository), then mado again from an empty build directory, as a new worktree or after cargo clean would start. One run each.
nsh, first build
Empty build directories. The same speed; dependencies now land in the shared directory.
Cargo
207.9 s
Fork
206.7 s
mado, first build after nsh
mado builds its dependencies at opt-level 3 and nsh at 0, so the two share almost nothing (1 of 330 crates). The fork is faster because dependencies carry no debug info.
Cargo
513.8 s
Fork
379.2 s
mado again, empty build directory
Cargo compiles all 330 crates again, as in its first build. The fork finds the dependencies in the shared directory and compiles 2 crates.
Cargo
513.8 s
Fork
16.2 s
Disk after nsh and mado
Cargo: both target directories. Fork: both project directories (2.3 GB and 0.4 GB) and the shared dependencies (2.2 GB).
Cargo
10.3 GB
Fork
4.9 GB
What a cleanup looks like
After a build, at most once an hour, Cargo removes what no build has used for a day, then the least recently used units until the project fits. It prints one line when it frees something.
$ cargo buildFinished `dev` profile [unoptimized + debuginfo] target(s) in 1.89s
Cleaned 680 stale build units, 10.1GiB freed (build.gc)
What changes
Your projects, Cargo.toml and .cargo/config.toml stay as they are.
One build directory per project. Intermediate files go to ~/.cargo/targets/<name>-<hash>/, where the hash comes from the repository's .git directory. Every worktree lands there wherever it is created, reuses compiled dependencies, and only builds its own crates. Binaries still appear in ./target.
Fixed directories../target and ~/.cargo/targets cannot be moved: --target-dir, CARGO_TARGET_DIR, build.target-dir and build.build-dir are ignored with a warning, so no flag, env var or tool can scatter build output elsewhere.
Dependencies shared by every project. Registry and git dependencies build once in ~/.cargo/targets/shared-deps/ and are reused by any project that needs the same version, features and profile, like Go's build cache. cargo check, clippy, rust-analyzer and cargo doc use the same builds, so a check after a build only looks at your own crates.
Your own crates shared by worktrees too. A workspace crate is keyed by the content of its files instead of the checkout it is in, so a new worktree of the same commit reuses every crate another worktree built, and switching back to a branch reuses what it built before. Editing a test or a binary rebuilds only that target. Crates with a build script, and crates that read their own path (env!("CARGO_MANIFEST_DIR")), still build per worktree. Worktrees also share rustc's incremental caches, so the first edit in a new worktree is incremental too. For this rustc records . as the compile directory (-Zremap-cwd-prefix=.; on stable through RUSTC_BOOTSTRAP=1 with no #![feature] allowed), so start a debugger from the workspace root.
A size limit. Each project keeps to twice its largest build of the last day, and its units unused for a day are removed. Shared dependencies are kept for 7 days and keep to 50 GiB. A project not built for a day loses its incremental caches, one not built for 7 days is removed whole, and all projects together keep to 50 GiB, sparing those built in the last 6 hours unless the disk is nearly full. The units an edit replaces are removed right away, unless another worktree uses them. Older builds of a shared dependency that was rebuilt for new dependencies go after a day, and so do stale test directories in CARGO_TARGET_TMPDIR and binaries in ./target whose build unit is gone; what the stock Cargo left in ./target goes after an hour. Nothing a running build has locked is removed.
No duplicate object files on macOS. Debuggers and backtraces read the objects inside each rlib, so the loose copies beside it are removed.
Worktrees build at the same time. Fine-grained locking is on, so parallel agents do not queue on one lock. When two builds need the same dependency at once, one compiles it and the other reuses the result.
Less debug info in dev builds. Line tables for your crates, none for dependencies. Backtraces keep file and line. A debug setting in your profile still wins.
Metadata stored once on nightly. An rlib no longer carries a second copy of its .rmeta on a nightly rustc, about 30% off the shared dependencies.
Updates itself. Once a day at most, a background check installs the latest release, so you never rerun the installer. CARGO_FORK_AUTO_UPDATE=0 turns it off.
Cranelift on nightly.cargo build compiles your crates with Cranelift and runs the compiler front end on up to 8 threads. Tests and release builds keep LLVM. The installer adds the Cranelift component when you have a nightly toolchain.
Change a default
# ~/.cargo/config.toml[build.gc]
max-size = "auto" # or "15 GiB", "none"
shared-max-size = "50 GiB"
projects-max-size = "50 GiB" # all other projects
max-unused = "1 day"
shared-max-unused = "7 days"
frequency = "1 hour" # or "always", "never"
enabled = true
Set CARGO_SHARED_DEPS=0 to keep dependencies in the project's build directory, CARGO_CHECK_SHARED_DEPS=0 to only check them in cargo check, CARGO_SHARE_WORKSPACE_UNITS=0 to build your crates per worktree, CARGO_DEV_CRANELIFT=0 to keep LLVM on nightly, and CARGO_RUSTC_THREADS=1 for a single-threaded front end.