Skip to main content
prompt GP ChatGPT

Rust CLI taste — Claude and Claude.ai prompt: rules for Rust CLIs

A prompt that tells the model how to write a Rust command-line tool: argument parsing, error handling, output streams, tests.

Open on GitHub

What Rust CLI taste does

This prompt is a list of nineteen rules for building a Rust CLI. Arguments get parsed with clap and the derive API, and doc comments become the help text. main returns anyhow::Result, and every fallible step carries .context(). Library error types use thiserror; anyhow stays in the binary.

The crate splits into a thin main.rs and a lib.rs that holds the real logic, so the logic can be tested. Normal output goes to stdout, while logs, progress and errors go to stderr. A --json flag gives machine-readable output through serde, tracing runs with an env filter driven by -v flags and a RUST_LOG override, and colors are dropped when stdout is not a terminal or NO_COLOR is set. Progress bars via indicatif are reserved for operations longer than about a second. Exit codes are distinct and documented instead of always 1.

Config is read in order: flags, then environment variables, then a TOML file, with paths found through the directories crate. End-to-end tests use assert_cmd, snapshots use insta. The prompt advises against async and tokio unless the tool really does concurrent network work. The build side covers clap_complete and clap_mangen for completions and a man page, cargo-dist for prebuilt Linux, macOS and Windows binaries from GitHub Actions, clippy with warnings denied and cargo fmt --check in CI. One rule handles Ctrl+C through the ctrlc crate so no half-written files are left behind.

What it helps with

  • parse CLI arguments and pull help text from doc comments
  • attach context to every fallible step instead of a bare ?
  • split the crate into a thin main.rs and a testable lib.rs
  • emit machine-readable output behind a --json flag
  • return distinct exit codes instead of always 1

Example prompts for the agent

  • Write a Rust CLI following Rust CLI taste: clap with derive, anyhow in main, thiserror in the library.
  • Parse the arguments with clap and add .context() to every step that can fail.
  • Add a --json flag with serde and disable colors when stdout is not a terminal.

How to install Rust CLI taste

How to use

Paste the text at the start of a chat or into project instructions

Questions about Rust CLI taste

How do I install Rust CLI taste in Claude?

There is no install command: paste the prompt into the chat as a message or save it in your custom instructions.

What does Rust CLI taste do?

It sets the rules the model follows when writing a Rust command-line tool: clap, anyhow and thiserror, output split across streams, tests with assert_cmd and insta.

Do I need tokio for a tool built with this prompt?

The prompt advises skipping async and tokio unless the tool really does concurrent network work.

Source text

prompts.csv · CC0-1.0
# Rust CLI taste
- Parse arguments with clap using the derive API and doc comments as help text. Confidence: 0.95
- Return anyhow::Result from main and add context to every fallible step with .context(). Confidence: 0.90
- Define library error types with thiserror and keep anyhow in the binary only. Confidence: 0.85
- Split the crate into a thin main.rs and a lib.rs that holds the real logic for testing. Confidence: 0.85
- Write normal output to stdout and logs, progress and errors to stderr. Confidence: 0.95
- Offer a --json flag for machine-readable output and serialize it with serde. Confidence: 0.85
- Use tracing with an env filter controlled by -v flags and a RUST_LOG override. Confidence: 0.80
- Respect NO_COLOR and disable colors automatically when stdout is not a terminal. Confidence: 0.90
- Show progress bars with indicatif only for operations longer than about a second. Confidence: 0.75
- Exit with distinct, documented exit codes instead of always returning 1. Confidence: 0.80
- Read configuration in the order flags, then environment variables, then a TOML config file. Confidence: 0.80
- Find config and cache paths with the directories crate rather than hardcoding home paths. Confidence: 0.80
- Test the binary end to end with assert_cmd and snapshot output with insta. Confidence: 0.85
- Avoid async and tokio unless the tool really does concurrent network work. Confidence: 0.75
- Generate shell completions and a man page with clap_complete and clap_mangen at build time. Confidence: 0.75
- Ship prebuilt binaries for Linux, macOS and Windows with cargo-dist from GitHub Actions. Confidence: 0.80
- Run cargo clippy with warnings denied and cargo fmt --check in CI. Confidence: 0.90
- Set opt-level, lto and strip in the release profile to keep binaries small. Confidence: 0.70
- Handle Ctrl+C cleanly with the ctrlc crate and leave no half-written files behind. Confidence: 0.80

© f · CC0-1.0 · f/prompts.chat

Similar prompts

All prompts for Programming languages →

From the same set77

The whole set →
Error Handling taste A prompt that gives an AI assistant the error-handling taste of a TypeScript backend engineer: validate input, split expected errors from bugs, log once, answer with problem+json. GP ChatGPT ★ 174,597repo stars Kubernetes taste A prompt that hands your AI assistant a platform team's Kubernetes rules: GitOps, probes, resources, pod security. Useful when you ask a model to write or review manifests. GP ChatGPT ★ 174,597repo stars Git Workflow taste A prompt that gives an AI assistant trunk-based habits: short-lived branches, Conventional Commits, squash-merge and a protected main. GP ChatGPT ★ 174,597repo stars Monorepo taste A prompt that hands the agent a fixed set of monorepo conventions: pnpm workspaces, Turborepo, package boundaries and shared configs. Useful when repo structure keeps drifting. GP ChatGPT ★ 174,597repo stars React State Management taste A ruleset for picking React state tools: when to use useState, Zustand, Context and TanStack Query. Helps avoid overbuilt global stores and duplicated state. GP ChatGPT ★ 174,597repo stars Observability taste A prompt that tells an AI assistant how to wire traces, metrics and logs into a service. Handy when you ask a model to write instrumented code. GP ChatGPT ★ 174,597repo stars Python Packaging taste A prompt that hands the model a fixed set of Python packaging rules: pyproject.toml, src/, uv, Ruff. Useful when a new package needs one consistent style. GP ChatGPT ★ 174,597repo stars Open Source Release Checklist Builder (YAML) This prompt turns an upcoming open-source release into a YAML checklist for versions, tests, artifacts, security notes, rollback, and announcements. GP ChatGPT ★ 174,597repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor