Skip to content
Skills Library
Programming · Review & audit

cargo-machete

/cargo-machete

cargo-machete: detect unused Rust dependencies. Use when auditing Cargo.toml, optimizing build times, or cleaning up dependency bloat.

Licence
MIT
Last repository change
24.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
2
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 24.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

cargo-machete: detect unused Rust dependencies. Use when auditing Cargo.toml, optimizing build times, or cleaning up dependency bloat.

Original author description

cargo-machete: detect unused Rust dependencies. Use when auditing Cargo.toml, optimizing build times, or cleaning up dependency bloat.

How it works

  1. When to Use This Skill
  2. Context
  3. Execution
  4. False Positive Handling
  5. Comparison with cargo-udeps
  6. Agentic Optimizations
  7. Quick Reference
  8. Troubleshooting
Original SKILL.md headings · 143 lines, 620 words
SKILL.md preview
---
created: 2025-12-16
modified: 2026-06-18
reviewed: 2025-12-16
name: cargo-machete
description: "cargo-machete: detect unused Rust dependencies. Use when auditing Cargo.toml, optimizing build times, or cleaning up dependency bloat."
user-invocable: false
allowed-tools: Bash, Read, Grep, Glob
---

# cargo-machete - Unused Dependency Detection

Detect and remove unused dependencies in Rust projects using cargo-machete.

## When to Use This Skill

| Use this skill when... | Use X instead when... |
|------------------------|----------------------|
| Auditing for unused dependencies | Checking for outdated deps -- use `cargo outdated` |
| Cleaning up Cargo.toml | Auditing security vulnerabilities -- use `cargo audit` |
| Optimizing build times by removing bloat | Checking license compliance -- use `cargo deny` |
| Verifying deps in CI | Need nightly-accurate analysis -- use `cargo +nightly udeps` |

## Context

- Cargo.toml: !`find . -maxdepth 1 -name \'Cargo.toml\'`
- Workspace: !`find . -maxdepth 1 -name 'Cargo.toml' -exec grep -q '\[workspace\]' {} +`
- cargo-machete installed: !`cargo machete --version`
- Machete config: !`find . -maxdepth 1 -name \'.cargo-machete.toml\'`
- Workspace members: !`find . -maxdepth 1 -name 'Cargo.toml' -exec grep -A 20 '^\[workspace\]' {} +`

## Execution

Execute this unused dependency analysis:

### Step 1: Verify installation

Check if cargo-machete is installed (see [Context](#context)). If not installed, install it:

```bash
cargo install cargo-machete
```

### Step 2: Run dependency analysis

Run cargo-machete with metadata for detailed output:

```bash
# Single crate
cargo machete --with-metadata

# Workspace (if Context shows workspace)
cargo machete --workspace --with-metadata
```

### Step 3: Evaluate results

Review the output and classify each finding:

| Finding | Action |
|---------|--------|
| Genuinely unused dependency | Remove with `--fix` or manually |
| Proc-macro dependency (e.g., serde derive) | Add `machete:ignore` comment |
| Build.rs-only dependency | Move to `[build-dependencies]` |
| Re-exported dependency | Add `machete:ignore` comment with explanation |

### Step 4: Apply fixes

For confirmed unused dependencies, auto-remove them:

```bash
cargo machete --fix
```

For false positives, add ignore annotations in `Cargo.toml`:

```toml
serde = "1.0"  # machete:ignore - used via derive macro
```

Or create `.cargo-machete.toml` for project-wide ignores:

```toml
[ignore]
dependencies = ["serde", "log"]
```

### Step 5: Verify build

After removing dependencies, confirm everything still compiles:

```bash
cargo check --all-targets
cargo test --no-run
```

## False Positive Handling

| Scenario | Solution |
|----------|----------|
| Proc-macro deps (e.g., serde derive) | `machete:ignore` comment |
| Build.rs-only deps | Move to `[build-dependencies]` |
| Re-exported deps | `machete:ignore` comment with explanation |
| Example/bench-only deps | Verify in `[dev-dependencies]` |

## Comparison with cargo-udeps

| Feature | cargo-machete | cargo-udeps |
|---------|---------------|-------------|
| Accuracy | Good | Excellent |
| Speed | Very fast | Slower |
| Rust version | Stable | Requires nightly |
| False positives | Some | Fewer |

Use cargo-machete for fast CI checks. Use cargo-udeps for thorough audits:

```bash
cargo +nightly udeps --workspace --all-features
```

## Agentic Optimizations

| Context | Command |
|---------|---------|
| Quick check | `cargo machete` |
| Detailed check | `cargo machete --with-metadata` |
| Workspace check | `cargo machete --workspace --with-metadata` |
| Auto-fix | `cargo machete --fix` |
| Verify after fix | `cargo check --all-targets` |
| Accurate check (nightly) | `cargo +nightly udeps --workspace` |

## Quick Reference

| Flag | Description |
|------|-------------|
| `--with-metadata` | Show detailed output with versions and locations |
| `--fix` | Auto-remove unused dependencies from Cargo.toml |
| `--workspace` | Check all workspace members |
| `-p <crate>` | Check specific workspace member |
| `--exclude <crate>` | Exclude specific workspace member |

## Troubleshooting

| Problem | Solution |
|---------|----------|
| Proc macro flagged as unused | Add `machete:ignore` comment in Cargo.toml |
| Build.rs dep flagged | Move to `[build-dependencies]` |
| Re-exported dep flagged | Add `machete:ignore` with explanation |
| Need more accuracy | Use `cargo +nightly udeps` |

For CI integration patterns, configuration file examples, pre-commit setup, and Makefile integration, see [REFERENCE.md](REFERENCE.md).
Files in this package (2)
  • REFERENCE.md 5 KB
  • SKILL.md 4 KB

Versions

The database has no other skills named cargo-machete.

Database snapshot: 13.11.2026 · package version 5a55f7f42096 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100claude-skill-rust
    Guide for Rust development including code style, testing, building, and quality checks using cargo tools. Apply when working with Rust code, Cargo.toml, or running cargo commands.
  • 90cargo-workflows
    Use when managing Cargo workspaces, feature flags, build scripts, CI caching, dependency auditing, or Cargo.lock with Rust.
  • 90cargo-workflows
    Use when managing Cargo workspaces, feature flags, build scripts, CI caching, dependency auditing, or Cargo.lock with Rust.
  • 100cargo-workflows
    Cargo workflow skill for Rust projects. Use when managing workspaces, feature flags, build scripts, cargo cache, incremental builds, dependency auditing, or CI configuration with Cargo. Activates on queries about cargo workspaces, Cargo.toml features, build.rs, cargo nextest,…
  • 100rust-supply-chain
    Rust supply-chain & quality toolchain — cargo-deny (license + advisory + bans), cargo-audit (RustSec advisory DB), cargo-nextest (faster test runner with retry/parallel), cargo-tarpaulin / llvm-cov (code coverage), cargo-machete (unused deps), cargo-outdated (version gap…
  • 100managing-cargo-dependencies
    Cargo.toml dependency management patterns for HASH workspace. Use when adding, updating, or removing dependencies, organizing Cargo.toml sections, configuring version pinning and default features, or managing public dependencies.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.