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

Swift
61%
GPL 3.0

cmux

AI Development · Developer Tools

28,379

A native, Ghostty-based macOS terminal with vertical tabs, agent-aware notifications, and a scriptable browser built for running many parallel AI coding agent sessions instead of juggling tmux panes.

View details
85
Repo Health
81
Technical
68
Dependency
Built with
Swift 61%
Rust 11%
Updated 6 days ago
Go
33%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

13,023

Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.

View details
84
Repo Health
88
Technical
63
Dependency
Built with
Go 33%
Rust 26%
C 22%
Updated 1 weeks ago
Go
33%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

13,023

Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.

View details
84
Repo Health
88
Technical
63
Dependency
Built with
Go 33%
Rust 26%
C 22%
Updated 1 weeks ago
TypeScript
74%
Apache 2.0

Fern

Developer Tools

3,822

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript 74%
Updated 6 days ago
TypeScript
74%
Apache 2.0

Fern

Developer Tools

3,822

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript 74%
Updated 6 days ago
TypeScript
74%
Apache 2.0

Fern

Developer Tools

3,822

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
66
Dependency
Built with
TypeScript 74%
Updated 6 days ago
Rust
99%
Other

Fluree DB

Databases

475

A temporal, verifiable graph database with git-like branching, integrated vector/text/geo search, and RDF/SPARQL/JSON-LD/openCypher support — benchmarked at 10.4x faster than the next database on the full Wikidata dump.

View details
87
Repo Health
74
Technical
65
Dependency
Built with
Rust 99%
Updated 6 days ago
Rust
99%
Other

Fluree DB

Databases

475

A temporal, verifiable graph database with git-like branching, integrated vector/text/geo search, and RDF/SPARQL/JSON-LD/openCypher support — benchmarked at 10.4x faster than the next database on the full Wikidata dump.

View details
87
Repo Health
74
Technical
65
Dependency
Built with
Rust 99%
Updated 6 days ago
Rust
87%
GPL 2.0

Fresh

Code Editors · Developer Tools

9,291

A zero-configuration terminal text editor with familiar keybindings, full mouse support, LSP-powered IDE features, and a built-in orchestrator for running multiple coding agents in parallel worktrees.

View details
85
Repo Health
88
Technical
71
Dependency
Built with
Rust 87%
Updated 1 weeks 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