cargo-machete
cargo-machete: detect unused Rust dependencies. Use when auditing Cargo.toml, optimizing build times, or cleaning up dependency bloat.
- License 许可
- MIT
- 最近更新
- 2026-11-12
- Stars
- ★ 59
- Forks
- 6
01 前言 Front Matter
- name
- cargo-machete
- created
- 1765843200000
- modified
- 1793750400000
- reviewed
- 1765843200000
- description
- cargo-machete: detect unused Rust dependencies. Use when auditing Cargo.toml, optimizing build times, or cleaning up dependency bloat.
- allowed-tools
- Bash, Read, Grep, Glob
- user-invocable
- false
02 资源文件 1
- 参考文档REFERENCE.md4.6 KB
03 SKILL.md 正文
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). If not installed, install it:
cargo install cargo-machete
Step 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-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:
cargo machete --fix
For false positives, add ignore annotations in Cargo.toml:
serde = "1.0" # machete:ignore - used via derive macro
Or 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-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:
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.
04 同仓库更多 Skills
kitty-show-image
Show the user an image with a note on what to judge, via a file send or a labelled kitty tab. Use when the user must see an image, or icat fails with no /dev/tty.
kitty-session-persistence
Snapshot and restore kitty terminal sessions on macOS. Use when surviving WindowServer hangs without losing tabs, configuring snapshots, or restoring after a force-reboot.
kitty-remote-control
Safe kitty remote control from an agent — read panes with kitty @ ls/get-text, notify, and never mutate the live terminal unasked. Use when running inside kitty.
docs-reference-check
Dangling doc-reference gate: flag markdown naming repo paths or relative links that no longer exist. Use when docs cite moved/deleted files, or wiring a doc-drift lint.
youtube-upload
Upload a video to YouTube via the Data API v3 and edit its title, description, tags or thumbnail afterwards. Use when publishing or retitling a YouTube video.
youtube-studio-share
Share a private YouTube video with a whole Google Workspace organization by scripting YouTube Studio in the browser. Use when a video must be org-only.