#cargo-subcommand #lang #cargo #language

app cargo-machete

Find unused dependencies with this one weird trick!

9 releases (5 breaking)

0.6.0 Oct 10, 2023
0.5.0 Nov 15, 2022
0.4.0 Oct 16, 2022
0.3.1 Jun 12, 2022
0.1.0 Nov 13, 2021

#63 in Cargo plugins

Download history 2031/week @ 2023-10-26 2095/week @ 2023-11-02 2187/week @ 2023-11-09 2827/week @ 2023-11-16 3167/week @ 2023-11-23 2600/week @ 2023-11-30 2841/week @ 2023-12-07 2922/week @ 2023-12-14 1585/week @ 2023-12-21 1768/week @ 2023-12-28 2939/week @ 2024-01-04 3198/week @ 2024-01-11 3874/week @ 2024-01-18 3597/week @ 2024-01-25 3445/week @ 2024-02-01 2693/week @ 2024-02-08

14,196 downloads per month

MIT license

825 lines


Remove unused Rust dependencies with this one weird trick!

build status matrix chat supported rustc stable


cargo-machete is a Cargo tool that detects unused dependencies in Rust projects, in a fast (yet imprecise) way.

See also the blog post for a detailed writeup.


Install cargo-machete with cargo:

cargo install cargo-machete


Run cargo-machete in a directory that contains one or more Rust projects (using Cargo for dependency management):

cd my-directory && cargo machete

# alternatively

cargo machete /absolute/path/to/my/directory

The return code gives an indication whether unused dependencies have been found:

  • 0 if machete found no unused dependencies,
  • 1 if it found at least one unused dependency,
  • 2 if there was an error during processing (in which case there's no indication whether any unused dependency was found or not).

This can be used in CI situations.

False positives

To ignore a certain set of dependencies in a crate, add package.metadata.cargo-machete to Cargo.toml (or workspace.metadata.cargo-machete to a workspace Cargo.toml), and specify an ignored array:

For example:

prost = "0.10" # Used in code generated by build.rs output, which cargo-machete cannot check

# in an individual package Cargo.toml
ignored = ["prost"]

# in a workspace Cargo.toml
ignored = ["prost"]

If there are too many false positives, consider using the --with-metadata CLI flag, which will call cargo metadata --all-features to find final dependency names, more accurate dependencies per build type, etc. ⚠ This may modify the Cargo.lock files in your projects.

Cargo Machete Action

A github action for cargo machete.

Example usage

The step given by,

      - uses: bnjbvr/cargo-machete@main

can be added to any workflow.

An example workflow is shown below:

name: Cargo Machete
  pull_request: { branches: "*" }

    runs-on: ubuntu-latest
      - name: Checkout
        uses: actions/checkout@v3
      - name: Machete
        uses: bnjbvr/cargo-machete@main


Contributor Covenant

We welcome community contributions to this project.


MIT license.


~326K SLoC