Back to Skills

cargo-machete

verified

Detect unused dependencies in Rust projects for cleaner Cargo.toml files and faster builds. Use when auditing dependencies, optimizing build times, cleaning up Cargo.toml, or detecting bloat. Trigger terms: unused dependencies, cargo-machete, dependency audit, dependency cleanup, bloat detection, cargo-udeps.

View on GitHub

Marketplace

laurigates-plugins

laurigates/claude-plugins

Plugin

rust-plugin

language

Repository

laurigates/claude-plugins
3stars

rust-plugin/skills/cargo-machete/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/laurigates/claude-plugins/blob/main/rust-plugin/skills/cargo-machete/SKILL.md -a claude-code --skill cargo-machete

Installation paths:

Claude
.claude/skills/cargo-machete/
Powered by add-skill CLI

Instructions

# cargo-machete - Unused Dependency Detection

cargo-machete is a fast tool for detecting unused dependencies in Rust projects. It analyzes your codebase to find dependencies listed in Cargo.toml but not actually used in your code.

## Installation

```bash
# Install cargo-machete
cargo install cargo-machete

# Verify installation
cargo machete --version
```

## Basic Usage

```bash
# Check for unused dependencies in current directory
cargo machete

# Check specific directory
cargo machete /path/to/project

# Check with detailed output
cargo machete --with-metadata

# Fix unused dependencies automatically (removes from Cargo.toml)
cargo machete --fix

# Check workspace
cargo machete --workspace
```

## Output Examples

### Basic Output

```bash
$ cargo machete
Found unused dependencies in Cargo.toml:
  serde_json (unused)
  log (unused in lib, used in build.rs)
  tokio (unused features: macros)
```

### With Metadata

```bash
$ cargo machete --with-metadata
Project: my_app (bin)
  Unused dependencies:
    - serde_json (0.1.0)
      Declared in: Cargo.toml [dependencies]
      Not used in: src/main.rs

  Partially used:
    - tokio (1.35.0)
      Unused features: macros, fs
      Used features: runtime, net
```

## False Positive Handling

### Common False Positives

1. **Dependencies used only in build.rs**:
   ```toml
   [build-dependencies]
   bindgen = "0.69"  # Correctly placed, machete won't flag
   ```

2. **Dependencies used only in examples**:
   ```toml
   [dev-dependencies]
   criterion = "0.5"  # For examples/benchmarks
   ```

3. **Dependencies used via re-exports**:
   ```rust
   // lib.rs
   pub use external_crate::SomeType;  # Machete may not detect
   ```

4. **Proc-macro dependencies**:
   ```toml
   [dependencies]
   serde = { version = "1.0", features = ["derive"] }
   # Machete may flag serde as unused if only using derive macro
   ```

### Ignoring False Positives

Create `.cargo-machete.toml` or add to `Cargo.toml`:

```toml
# .cargo-machete.to

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
8052 chars