clap-patterns

clap-patterns is a skill for Claude Code from geoffjay/claude-plugins. It costs 31 tokens per session (1,268 once invoked), scanned A, original, MIT.

A reference for common ways to use Clap 4, a Rust library that reads command-line arguments and turns them into typed program options.

In plain words
What is it for?
Use it when adding options, subcommands, validation rules, global flags, mutually exclusive choices, help text, or other argument-parsing behavior with Clap 4.
Why use it?
It helps you choose suitable argument patterns and avoid inconsistent or weak command-line interfaces. It also explains when to define the interface in code structures or build it dynamically at runtime.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the rust-cli-developer plugin — 4 skills shipped together

Good fit Use it when adding options, subcommands, validation rules, global flags, mutually exclusive choices, help text, or other argument-parsing behavior with Clap 4.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/geoffjay/claude-plugins/clap-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add geoffjay/claude-plugins --skill clap-patterns
Clone the repo
git clone --depth 1 https://github.com/geoffjay/claude-plugins

Made for: Claude Code.

Or install rust-cli-developer, the plugin that ships this one along with the rest of its 4 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for clap-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/geoffjay/claude-plugins/clap-patterns/github.svg)](https://agentmods.dev/skills/geoffjay/claude-plugins/clap-patterns)
Your own site
<a href="https://agentmods.dev/skills/geoffjay/claude-plugins/clap-patterns"><img src="https://agentmods.dev/badge/skills/geoffjay/claude-plugins/clap-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for clap-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/geoffjay/claude-plugins/clap-patterns"><img src="https://agentmods.dev/badge/skills/geoffjay/claude-plugins/clap-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 31 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,268 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00031 $0.01268
Opus 5.5 $0.00012 $0.00507
Sonnet 5.5 $0.00006 $0.00254
Haiku 4.5 $0.00003 $0.00127

Measured 3mo ago against content hash 288c65f5cced, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

clap-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/rust-cli-developer/skills/clap-patterns/SKILL.md · 249 lines

How it starts

The opening of the file, as written. The whole thing — 249 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Clap Patterns Skill

Common patterns and idioms for using Clap v4+ effectively in Rust CLI applications.

Derive API vs Builder API

When to Use Derive API

  • CLI structure known at compile time
  • Want type safety and compile-time validation
  • Prefer declarative style
  • Standard CLI patterns are sufficient
#[derive(Parser)]
#[command(version, about)]
struct Cli {
    #[arg(short, long)]
    input: PathBuf,
}

When to Use Builder API

  • CLI needs to be built dynamically at runtime
  • Building plugin systems
  • Arguments depend on configuration
  • Need maximum flexibility
fn build_cli() -> Command {
    Command::new("app")
        .arg(Arg::new("input").short('i'))
}

Common Patterns

Global Options with Subcommands

#[derive(Parser)]
struct Cli {
    #[arg(short, long, global = true, action = ArgAction::Count)]
    verbose: u8,

    #[command(subcommand)]
    command: Commands,
}

Argument Groups for Mutual Exclusivity

#[derive(Parser)]
#[command(group(
    ArgGroup::new("format")
        .required(true)
        .args(&["json", "yaml", "toml"])
))]
struct Cli {
    #[arg(long)]
    json: bool,
    #[arg(long)]
    yaml: bool,
    #[arg(long)]
    toml: bool,
}

Custom Value Parsers

fn parse_port(s: &str) -> Result<u16, String> {
    let port: u16 = s.parse()
        .map_err(|_| format!("`{s}` isn't a valid port"))?;
    if (1024..=65535).contains(&port) {
        Ok(port)
    } else {
        Err(format!("port not in range 1024-65535"))
    }
}

#[derive(Parser)]
struct Cli {
    #[arg(long, value_parser = parse_port)]
    port: u16,
}

Environment Variable Fallbacks

#[derive(Parser)]
struct Cli {
    #[arg(long, env = "API_TOKEN")]
    token: String,

    #[arg(long, env = "API_ENDPOINT", default_value = "https://api.example.com")]
    endpoint: String,
}

Flattening Shared Options

#[derive(Args)]
struct CommonOpts {
    #[arg(short, long)]
    verbose: bool,

    #[arg(short, long)]
    config: Option<PathBuf>,
}

#[derive(Parser)]
struct Cli {
    #[command(flatten)]
    common: CommonOpts,

    #[command(subcommand)]
    command: Commands,
}

Read the full file on GitHub · 249 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3mo ago First seen · 249 lines · 31 tokens per session scan A 288c65f5cced

Subscribe to this mod's changes

clap-patterns is a skill published in the GitHub repository geoffjay/claude-plugins (8 stars, last pushed 1y ago), licensed MIT. It adds 31 tokens to every session and 1,268 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

clap-patterns compared with skills from other repositories

clap-patterns next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
clap-patternsgeoffjay/claude-pluginsSkill81y agoMITA31Claude Code
rust-patternsaffaan-m/ECCSkill314kyesterdayMITA28Claude Code, Kiro
update-v8-versionopeninterpreter/openinterpreterSkill69k2d agoApache-2.0A86Codex
omh-rustrlaope/oh-my-hermesSkill6.2ktodayMITA19Claude Code
dd-code-generationDataDog/pupSkill1.0ktodayApache-2.0A16Claude Code
swiftidebosun-ai/swiftideSkill807todayMITA43Claude Code, Codex
azure-keyvault-secrets-rustbenjaminasterA/antigravity-awesome-skillsSkill522todayMITA0Claude Code, Codex