# Is it safe to delete a Rust project’s target folder?

Is it safe to delete? · Project folders · Updated 21 November 2026. By Mohit Nippanikar, who makes SiftMac.

## The short answer

- **Yes.** `target` is everything Cargo compiled for the project, and none of it is source. `cargo clean` deletes it the official way.
- **What it costs you:** the next build compiles the project and every dependency from scratch, a full build rather than a quick incremental one.
- **Does it come back?** Yes, with the next `cargo build`, `cargo test` or editor check.
- SiftMac’s verdict: Rebuilds

## 1. What’s in target

Cargo writes all build output for a workspace into one `target` folder at the workspace root: compiled dependencies, your binaries and libraries, test executables, documentation, and incremental data that makes small rebuilds quick.

- `target/debug`: the default `dev` profile, used by `cargo build`, `cargo run` and `cargo test`.
- `target/release`: builds made with `--release`.
- `target/<triple>/…`: builds for other targets, made with `--target`, kept apart from the rest.
- `target/doc`: output of `cargo doc`.

Each profile and each target gets its own build of every dependency, which is why `target` grows well past the size of the code.

## 2. Where it is

```
~/Projects/my-crate/target
```

Next to the workspace’s top `Cargo.toml`, unless `CARGO_TARGET_DIR` or the `build.target-dir` setting points somewhere else. To list the ones under your code folder with their sizes:

```
find ~/Projects -name Cargo.toml -execdir sh -c 'test -d target && du -sh "$PWD/target"' \; 2>/dev/null
```

## 3. How big it gets

It depends on the dependency tree, which profiles and targets you’ve built, and how long since anything cleared it. Cargo’s automatic cleanup covers its download cache in `~/.cargo`, not `target`, so a project you keep building only gains. To measure, and to preview a clean:

```
du -sh target target/*
cargo clean --dry-run
```

`cargo clean --dry-run` prints a summary of what would be deleted without deleting it; add `--verbose` to list the files.

## 4. How to delete it

From the project folder, with no build running:

```
cargo clean
```

With no options, that deletes the whole target directory. Narrower options:

- `cargo clean --release` removes only the `release` builds.
- `cargo clean --doc` removes only the generated docs.
- `cargo clean -p <crate>` cleans only that package.

Deleting the folder in Finder does the same. First copy out any program you use straight from `target/release`, or install it with `cargo install --path .` so it lives in `~/.cargo/bin` instead.

## 5. What happens afterwards

- The next build compiles every dependency again. It needs no downloads if Cargo’s registry cache still has the crates.
- Your editor’s rust-analyzer may start a check straight away and fill part of `target` again.
- Tests, benchmarks and docs rebuild the next time you run them; `Cargo.lock` and your sources aren’t touched.

## 6. Keep it while you’re working

In a project you build every day, `target` is what keeps each build quick, so clearing it buys space at the price of one full build. Finished projects are the ones worth clearing. The crates themselves are stored once for all projects in [Cargo’s registry](https://siftmac.com/safe-to-delete/cargo-registry).

## Questions

### Does cargo clean delete Cargo.lock or my code?

No. It only removes the target directory, or the parts of it you choose. `Cargo.lock`, `Cargo.toml` and `src` stay.

### Why is my target folder so much bigger than my code?

It holds compiled copies of every dependency for each profile and target you’ve built, plus incremental data kept to speed up rebuilds.

### Can several projects share one target folder?

Yes, by pointing `CARGO_TARGET_DIR` or `build.target-dir` at one folder. Then there’s a single place to clear, but cleaning it costs every project that uses it a full build.

## How SiftMac handles it

Its Developer files category lists `target` folders that sit next to a `Cargo.toml`, in projects whose own files haven’t changed for 1, 3 or 6 months, as Rust build output. None is ticked until you tick it, and cleared ones are deleted rather than shelved, since the next build makes them again.

Download: https://siftmac.com/SiftMac.dmg (scanning is free, and so is the first 2 GB of cleaning).

## Sources

- [The Cargo Book: cargo clean](https://doc.rust-lang.org/cargo/commands/cargo-clean.html)
- [The Cargo Book: Build cache](https://doc.rust-lang.org/cargo/reference/build-cache.html)

## Related

- [Is it safe to delete ~/.cargo/registry and ~/.cargo/git?](https://siftmac.com/safe-to-delete/cargo-registry)
- [Is it safe to delete node_modules?](https://siftmac.com/safe-to-delete/node-modules)
- [Xcode DerivedData, node_modules and Docker: what’s safe to delete on a developer’s Mac](https://siftmac.com/guides/developer-files-on-mac)
- [Developer files: what SiftMac clears, and how it knows it comes back](https://siftmac.com/features/developer-files)

Canonical: https://siftmac.com/safe-to-delete/rust-target-folder
