Home › Rust › Rust CLI CLAUDE.md
Rust CLI CLAUDE.md
CLAUDE.md for Rust command-line tools built with clap, anyhow and thiserror.
Claude Code (CLAUDE.md)Rust
How to use
Save this as CLAUDE.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.
CLAUDE.mdDownload # CLAUDE.md — Rust CLI
## Commands
- `cargo build` · `cargo test` · `cargo clippy --all-targets -- -D warnings` · `cargo fmt`
## Conventions
- CLI args with `clap` derive. Binary in `src/main.rs` stays tiny; logic in `src/lib.rs` modules so it's testable.
- Errors: `thiserror` for library error enums, `anyhow` with `.context("...")` in the binary.
- No `unwrap()`/`expect()` outside tests and truly impossible cases (comment why).
- Prefer borrowing (`&str`, `&[T]`) in function params; clone only when ownership is needed.
- Output for humans on stdout, diagnostics on stderr; support `--json` for machine output.
- Integration tests in `tests/` using `assert_cmd`.
## Before finishing
- fmt + clippy clean with zero warnings, tests green.