cargo-machete
Skill2 starsChanged 8 months agoMITView on GitHub
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.
- Installs packages
In this repository12 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- axumSkill
- cargo-fuzzSkill
- event-sourcing-architectSkill
- protobufSkill
- rust-async-patternsSkill
- rust-best-practicesSkill
- tokio-concurrencySkill
- tokio-patternsSkill
- checkSkill
- release-checkSkill
- life-lagoSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 41
Check if cargo-machete is installed (see Context above).
- Distinctive: line 49
Run cargo-machete with metadata for detailed output:
- Distinctive: line 93
After removing dependencies, confirm everything still compiles:
- Distinctive: line 118
Use cargo-machete for fast CI checks.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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: !
test -f Cargo.toml && echo "EXISTS" || echo "MISSING" - Workspace: !
grep -q '\[workspace\]' Cargo.toml 2>/dev/null && echo "YES" || echo "NO" - cargo-machete installed: !
cargo machete --version 2>/dev/null || echo "NOT INSTALLED" - Machete config: !
test -f .cargo-machete.toml && echo "EXISTS" || echo "MISSING" - Workspace members: !
grep -A 20 '^\[workspace\]' Cargo.toml 2>/dev/null | grep -o '"[^"]*"' 2>/dev/null
Execution
Execute this unused dependency analysis:
Step 1: Verify installation
Check if cargo-machete is installed (see Context above). If not installed, install it:
cargo install cargo-macheteStep 2: Run dependency analysis
Run cargo-machete with metadata for detailed output:
# Single crate
cargo machete --with-metadata
# Workspace (if Context shows workspace)
cargo machete --workspace --with-metadataStep 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:
cargo machete --fixFor false positives, add ignore annotations in Cargo.toml:
serde = "1.0" # machete:ignore - used via derive macroOr create .cargo-machete.toml for project-wide ignores:
[ignore]
dependencies = ["serde", "log"]Step 5: Verify build
After removing dependencies, confirm everything still compiles:
cargo check --all-targets
cargo test --no-runFalse 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:
cargo +nightly udeps --workspace --all-featuresAgentic 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.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

