Clap
The most widely used command-line argument parser for Rust, with both derive and builder APIs.
Repository Health
Technical Analysis
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/-hand--version/-Vgeneration 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-styletool 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 49 apps in this directory
Arroyo
Data Engineering · Analytics
A distributed stream processing engine written in Rust that lets you write SQL to run stateful, real-time computations over data streams with subsecond results.
BrowserOS
Browser · AI Assistants
The open-source agentic Chromium browser with native AI agents, MCP server, and visual workflow automation — your data never leaves your machine.
Cameleer
AI Agents
A local-first desktop workspace for managing AI agents in an enterprise-style workflow — agent directory, Kanban task tracking, workspace chat, and a full runtime/audit log of agent actions and tool approvals.
Cap
Team Chat · Video Conferencing
Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.
claw-code
AI Agents · AI Code Assistants
A Rust-built CLI agent harness for Claude AI with persistent sessions, MCP tool integration, plugin hooks, and multi-provider support — designed to run autonomous coding workflows without human babysitting.
ClickHouse
Databases · Analytics · Data Engineering
Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.
cmux
Developer Tools · AI Development
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.
CubeSandbox
Developer Tools · Security · AI Agents
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.
Fern
Developer Tools
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.