/major-ai-skills:rust-clifrom major-ai-skills
Build production Rust CLIs with clap derive, anyhow/thiserror boundaries, script-friendly stdout/stderr, ExitCode mapping, assert_cmd tests, and release Cargo workspaces.
Ships in major-ai-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Rust CLIs are Cargo binary crates (often workspace members) that parse argv with clap, report failures with anyhow at the binary edge and structured thiserror in libraries when callers must match variants, and exit with meaningful codes. Agents keep I/O fallible, avoid unwrap/expect on user-facing paths, put data on stdout / diagnostics on stderr, and prove behavior with assert_cmd integration tests.
┌─────────────────────────────────────────────────────────────┐
│ Rust CLI execution path │
│ │
│ cargo run / installed binary │
│ ├── clap::Parser / Subcommand (+ env defaults) │
│ ├── library crate (thiserror / Result) │
│ └── bin edge: anyhow context → ExitCode + stderr │
│ │
│ I/O contract │
│ ├── stdout: machine-consumable result (text/json) │
│ └── stderr: progress, warnings, errors │
│ │
│ Quality │
│ └── unit + assert_cmd / trycmd + clippy -D warnings │
└─────────────────────────────────────────────────────────────┘
Use when
--format json for automation.lib + bin crates and release/--target distribution.Do not use when
@go-services or @nodejs / @express.@python-packaging.clap::Parser / Subcommand; every flag gets a help string; document env vars in help/README.anyhow::Result in main with .with_context(|| …) on I/O; use thiserror in libraries when callers match error kinds.$?.? over unwrap on user input paths; reserve expect for invariants that are programmer bugs.cargo fmt, cargo clippy -- -D warnings, cargo test, and assert_cmd smoke tests.Cargo.toml when supporting older toolchains; use workspaces when lib reuse or compile times matter.Cargo.toml (excerpt):
[package]
name = "inventory"
version = "0.1.0"
edition = "2021"
rust-version = "1.74"
[dependencies]
anyhow = "1"
clap = { version = "4", features = ["derive", "env"] }
[dev-dependencies]
assert_cmd = "2"
predicates = "3"
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use std::process::ExitCode;
#[derive(Parser)]
#[command(name = "inventory", version, about = "Inventory helper CLI")]
struct Cli {
/// Emit machine-readable JSON on stdout
#[arg(long, global = true, env = "INVENTORY_FORMAT")]
format: Option<String>,
#[command(subcommand)]
cmd: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Count lines in a file (stdout = count only)
Count {
path: PathBuf,
},
}
fn run() -> Result<()> {
let cli = Cli::parse();
match cli.cmd {
Commands::Count { path } => {
let data = std::fs::read_to_string(&path)
.with_context(|| format!("read {}", path.display()))?;
let n = data.lines().count();
if cli.format.as_deref() == Some("json") {
println!("{{\"lines\":{n}}}");
} else {
println!("{n}");
}
}
}
Ok(())
}
fn main() -> ExitCode {
match run() {
Ok(()) => ExitCode::SUCCESS,
Err(err) => {
eprintln!("error: {err:#}");
ExitCode::from(1)
}
}
}
Integration test (tests/cli.rs):
use assert_cmd::Command;
use predicates::prelude::*;
#[test]
fn count_missing_file_fails() {
Command::cargo_bin("inventory")
.unwrap()
.args(["count", "does-not-exist.txt"])
.assert()
.failure()
.code(1)
.stdout(predicate::str::is_empty())
.stderr(predicate::str::contains("read"));
}
Commands:
cargo new inventory --bin
cargo add clap --features derive,env
cargo add anyhow
cargo add --dev assert_cmd predicates
cargo run -- count ./README.md
cargo clippy -- -D warnings
cargo test
cargo build --release
Distribute via release binary or @docker when the org ships tools as images.
| Signature | Likely cause | Fix path |
|---|---|---|
| Pipe consumer parses log noise | Progress/logs on stdout | Move to stderr; keep stdout pure |
| CI passes on failure | Exit 0 despite validation error | Return non-zero ExitCode; assert in assert_cmd |
| Clap usage printed oddly | Error before format flag parsed | Recover format from raw argv for usage errors if needed |
unwrap panic (exit 101) | Panic on bad user input | ? + context; never panic for expected I/O errors |
Slow cargo build | Monolith crate / many proc-macros | Workspace libs; feature-gate heavy deps |
| Cross-compile linker errors | Missing target / linker | rustup target add; zig/cross or CI matrix |
| Color codes break logs | Always-on ANSI | clap/anstream auto vs --color never |
--format json (or --output) when output grows beyond one scalar.--help and README; prefer env = "…" on clap args.assert_cmd (and trycmd for help snapshots when stable).tracing to stderr with levels; default quiet for scripts.cargo build --release for distribution; strip/LTO only when measured and MSRV-safe.@go-services — Go alternative for simple static service binaries@docker — ship CLIs in images when host installs are hard@python-packaging — Python CLI packaging alternative@nodejs — Node-based CLIs when the org standard is JS/TS@typescript — typed config/schemas consumed by the CLIMANDATORY: Clap-derived help for every flag. Data on stdout, errors on stderr. Non-zero exit codes for failures. Prefer
anyhowat the edge and structured errors in libraries when matching matters. Prove withcargo test+assert_cmd. Never embed secrets in binaries.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub alivirgo/major-ai-skills --plugin major-ai-skills412 skills in this plugin
/3d-slicerAutomate 3D Slicer research workflows with MRML, VTK/ITK, DICOM data, and Segment Editor. Use for software workflows, not clinical interpretation./abbreviated-git-statusInspect Git branch, staging, and working-tree changes with short or porcelain status output when a compact repository check is needed./ableton-liveAutomate Ableton Live sessions with Python MIDI Remote Scripts, Max for Live, AbletonOSC, and Link synchronization./act-as-a-personal-tutorExplain a subject step by step, assess prior knowledge, and use short exercises to check understanding before advancing.Other plugins' skills for the same job