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
59%
GPL 3.0

openfootmanager

Game Development

1,161

A free and open source football management simulation game built with Rust and Tauri, inspired by Football Manager.

View details
94
Repo Health
79
Technical
73
Dependency
Built with
Rust 59%
TypeScript 40%
Updated 1 weeks ago
TypeScript
39%
AGPL 3.0

OpenObserve

Analytics · Devops · Monitoring

22,475

Open source observability platform for logs, metrics, traces, and real user monitoring — delivering 140x lower storage costs than Elasticsearch with a single binary you can run in under 2 minutes.

View details
90
Repo Health
9
Technical
68
Dependency
Built with
TypeScript 39%
Rust 30%
Vue 17%
Updated 6 days ago
Python
73%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

40,705

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 73%
TypeScript 12%
Rust 11%
Updated 6 days ago
Rust
85%
AGPL 3.0

ParadeDB

Analytics · Databases · Search

9,436

Born out of Y Combinator's S2023 batch, ParadeDB is a Postgres extension that delivers Elasticsearch-quality BM25 search and real-time analytics without a separate search cluster to manage.

View details
89
Repo Health
87
Technical
68
Dependency
Built with
Rust 85%
PLpgSQL 15%
Updated 6 days ago
Go
82%
AGPL 3.0

PeerDB

Data Engineering · Databases

3,309

Postgres-native ETL that streams change data capture in real time to Snowflake, BigQuery, ClickHouse, S3, and Kafka — up to 10x faster than general-purpose pipelines, managed through a familiar Postgres SQL interface.

View details
89
Repo Health
76
Technical
66
Dependency
Built with
Go 82%
TypeScript 12%
Updated 6 days ago
Rust
63%
MIT

PostgresML

AI Development · Databases

6,823

Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.

View details
51
Repo Health
76
Technical
64
Dependency
Built with
Rust 63%
JavaScript 11%
Updated 1 years ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 6 days ago
Java
93%
Apache 2.0

QuestDB

Analytics · Databases

17,466

A high-performance, open-source time-series database built for financial market data, IoT telemetry, and real-time analytics, combining a zero-GC Java/C++ core with SIMD-accelerated SQL and a WAL-to-Parquet storage engine.

View details
91
Repo Health
86
Technical
67
Dependency
Built with
Java 93%
Updated 6 days ago
Rust
63%
MIT

Readur

Bookmarks Archiving · File Storage · Knowledge Management

804

A self-hosted document management system that OCRs, indexes, and makes every PDF, scan, and Office file instantly searchable.

View details
83
Repo Health
78
Technical
67
Dependency
Built with
Rust 63%
TypeScript 32%
Updated 6 days 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