Clap

The most widely used command-line argument parser for Rust, with both derive and builder APIs.

Library
Cargo
v4.6.7
16,795 stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
88 /100 Excellent
Development Activity 88
Maintenance 96
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
90 /100 Excellent
Architecture 90
Code Quality 88
Innovation 93
Learning Curve 95

Clap (Command Line Argument Parser) is the de facto standard library for parsing command-line arguments in Rust, used across hundreds of millions of downloads by projects ranging from small utilities to widely used tools like ripgrep, fd, and bat. It gives developers two equally supported ways to define a CLI: a declarative #[derive(Parser)] macro that turns a plain struct into a full parser, and an imperative builder API (Command/Arg) for CLIs that need to be constructed dynamically at runtime.

Beyond parsing, clap automatically generates colored, terminal-width-aware --help and usage text, produces structured errors with typo-correcting suggestions, and — via the companion clap_complete, clap_complete_nushell, and clap_mangen crates — generates shell completions and man pages straight from the same argument definitions, so documentation and behavior never drift apart.

What You Get

  • A declarative derive macro (Parser, Args, Subcommand, ValueEnum) that turns a plain Rust struct into a fully working CLI parser.
  • A lower-level builder API (Command, Arg, ArgGroup) for constructing CLIs dynamically at runtime.
  • Automatic --help/-h and --version/-V generation with colored, terminal-width-aware formatting.
  • Structured, typo-correcting error messages (e.g. suggesting the right subcommand when one is misspelled).
  • Companion crates for shell completions (clap_complete, clap_complete_nushell) and man-page generation (clap_mangen).

Common Use Cases

  • Parsing flags, options, and positional arguments for a Rust CLI binary.
  • Building multi-level subcommand trees (e.g. git-style tool remote add).
  • Validating and converting argument values (paths, enums, numbers) via typed value parsers.
  • Generating shell completion scripts and man pages as part of a release pipeline.

Under The Hood

Architecture: The public clap crate (src/lib.rs, 110 lines) is a thin facade that re-exports everything from clap_builder and, behind the derive feature flag, re-exports the Parser/Args/Subcommand/ValueEnum proc-macros from clap_derive. The real engine lives in clap_builder/src, organized into four layers: builder/ (Command, Arg, ArgGroup, ArgAction, ValueParser — the user-facing construction API, with command.rs and arg.rs each around 5,300 lines), parser/ (parser.rs at 1,685 lines plus validator.rs and matches/ — walks argv against the built Command tree and produces ArgMatches), output/ (help.rs, help_template.rs, usage.rs — renders --help/usage strings from the same Command definition), and error/ (kind.rs, context.rs, format.rs — structured, typed errors with contextual suggestions). Two supporting workspace members, clap_lex (a low-level argv tokenizer) and clap_derive (the proc-macro crate), sit alongside clap_complete/clap_complete_nushell (shell-completion generators) and clap_mangen (man-page generation), all consuming the same Command metadata so completions and docs never drift from the parser itself.

Tech Stack: Pure Rust, workspace-based ([workspace] members in Cargo.toml), MSRV 1.85 on the 2024 edition. The core dependency chain is clap -> clap_builder (default-features = false, version-pinned with =) -> optionally clap_derive behind the derive feature; clap_derive in turn depends on proc-macro2, syn, and quote for macro expansion. Dev-dependencies favor snapshot/golden testing (trycmd, snapbox with the term-svg feature) plus trybuild for compile-fail tests and automod for auto-registering test modules. The workspace Cargo.toml also carries an unusually large, individually-toggled [workspace.lints.clippy] block.

Code Quality: 135 Rust files under tests/ cover both the builder and derive APIs, backed by trycmd/snapbox snapshot tests that assert exact --help and error output byte-for-byte. clap_builder/src/builder/debug_asserts.rs runs invariant checks (e.g. conflicting arg definitions) in debug builds only, surfacing misconfigured CLIs immediately without adding runtime cost in release builds. The crate is #![forbid(unsafe_code)] and #![warn(missing_docs)]; roughly 183 .unwrap() calls remain in non-test builder source, which is reasonable given most guard internal invariants already covered by debug_asserts, but worth flagging for anyone auditing panic surface in a public library.

API Design: clap ships two parallel, equally-supported entry points — a #[derive(Parser)] macro for the common case (a plain struct becomes a full CLI with zero manual wiring) and a Command/Arg builder for dynamic/runtime-constructed CLIs — both funnelling into the same engine so behavior never diverges between them. Documentation is unusually thorough for a Rust crate: src/lib.rs embeds a live, always-current example via include_str!("../examples/demo.rs"), and dedicated _tutorial, _derive::_tutorial, _cookbook, _concepts, and _faq doc modules (gated behind an unstable-doc feature) ship a full manual alongside the API reference on docs.rs.

Used by 70 apps in this directory

Rust
60%
Apache 2.0

Magnitude

AI Development · Developer Tools

7,313

An open source inference engine that profiles your hardware, recommends the best local models, and tunes them for the coding agent you already use.

View details
79
Repo Health
83
Technical
71
Dependency
Built with
Rust 60%
TypeScript 25%
Updated 6 days ago
Rust
48%
MIT

Meetily

AI Assistants · Productivity

32,103

Privacy-first AI meeting assistant that transcribes and summarizes your meetings entirely on your local machine — no cloud, no data leakage.

View details
87
Repo Health
72
Technical
67
Dependency
Built with
Rust 48%
TypeScript 29%
Updated 1 weeks ago
Rust
100%
Other

Meilisearch

Search

59,644

Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.

View details
90
Repo Health
88
Technical
67
Dependency
Built with
Rust 100%
Updated 1 weeks ago
TypeScript
95%
MIT

melty

AI Code Assistants · Code Editors · Developer Tools

5,462

The AI code editor where every chat message is a git commit you can revert, branch, or squash

View details
35
Repo Health
75
Technical
67
Dependency
Built with
TypeScript 95%
Updated 1 years ago
TypeScript
95%
MIT

melty

AI Code Assistants · Code Editors · Developer Tools

5,462

The AI code editor where every chat message is a git commit you can revert, branch, or squash

View details
35
Repo Health
75
Technical
67
Dependency
Built with
TypeScript 95%
Updated 1 years ago
Rust
86%
Apache 2.0

mesh-llm

AI Agents · AI Development

3,551

Mesh LLM pools GPUs and memory across every machine you own into one OpenAI-compatible API, so agents tap distributed compute instead of a single GPU box or a metered cloud bill.

View details
85
Repo Health
91
Technical
69
Dependency
Built with
Rust 86%
TypeScript 10%
Updated 6 days ago
Rust
43%
BSD 3

MicroBin

File Storage

4,622

A self-contained, encrypted paste bin and file-sharing app in Rust with animal-name URLs, burn-after-read, and one-command Docker deployment.

View details
53
Repo Health
67
Technical
71
Dependency
Built with
Rust 43%
HTML 28%
JavaScript 20%
Updated 1 months ago
Rust
93%
Apache 2.0

Murr

Databases

117

A RocksDB-based NVMe/S3 cache purpose-built for AI inference workloads — a faster Redis replacement optimized for batch, low-latency, zero-copy reads and writes between data pipelines and inference apps.

View details
73
Repo Health
72
Technical
75
Dependency
Built with
Rust 93%
Updated 1 weeks ago
C++
43%
MIT

openduck

Data Engineering · Databases

576

OpenDuck brings MotherDuck-style cloud capabilities to self-hosted DuckDB — attach remote databases, run hybrid queries across local and remote nodes, and own your data with an open gRPC and Arrow IPC protocol.

View details
26
Repo Health
76
Technical
76
Dependency
Built with
C++ 43%
Rust 38%
HTML 13%
Updated 5 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers