This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
All commit messages and PR titles MUST follow conventional commit format:
Format: <type>(<scope>): <description>
Types:
feat:- New featuresfix:- Bug fixes that affect the CLI behavior (not CI, docs, or infrastructure)refactor:- Code refactoringdocs:- Documentation changesstyle:- Code style/formatting (no logic changes)perf:- Performance improvementstest:- Testing changeschore:- Maintenance tasks, releases, dependency updates, CI/infrastructure changessecurity:- Security-related changes
Scopes:
- For shell-specific changes:
bash,zsh,fish,powershell - For subsystem changes:
spec,parse,complete,docs,manpage,lib,cli,deps
Description Style:
- Use lowercase after the colon
- Use imperative mood ("add feature" not "added feature")
- Keep it concise but descriptive
Examples:
fix(zsh): handle spaces in completion valuesfeat(powershell): add completion supportfeat(spec): add mount node for nested specsdocs: update KDL spec format exampleschore: release 2.0.0
Usage is a spec and CLI for defining CLI tools using KDL format. It generates shell completions, markdown docs, and man pages from a single spec file. Think OpenAPI/Swagger for CLIs.
# Build all packages
cargo build --all
# Run all tests
cargo test --all --all-features
# Run a single test
cargo test -p usage-lib test_name
cargo test -p usage-cli test_name
# Update snapshots (uses cargo-insta)
cargo insta test --accept
# Lint and format
cargo clippy --all --all-features -- -D warnings
cargo fmt --all
prettier -w .
# Full CI check
mise run ci
# Render completions, docs, and assets
mise run renderThree crates in a Cargo workspace:
- lib (
usage-lib): Core library containing spec parsing, CLI argument parsing, shell completion generation, and documentation generation - cli (
usage-cli): Command-line tool that wraps the library - clap_usage: Generates usage specs from clap Command definitions
The spec model represents a CLI definition parsed from KDL:
Spec- Root struct containing name, version, commands, global completersSpecCommand- A command/subcommand with args, flags, and nested subcommandsSpecFlag- A flag definition (-v,--verbose,--config <path>)SpecArg- A positional argument (<input>,[optional],<files>...)SpecComplete- Custom completion definitions (shell commands to run)SpecMount- Mount another spec at a subcommand path
Specs can be:
- Parsed from
.usage.kdlfiles - Extracted from embedded
# USAGE:comments in scripts - Generated from clap Command definitions
Each shell has its own module generating completion scripts:
bash.rs- Usescompletebuiltinzsh.rs- Usescompdeffish.rs- Usescompletecommandpowershell.rs- UsesRegister-ArgumentCompleter
Completions call back to usage complete-word at runtime for dynamic completions.
The parse() function parses command-line arguments against a spec, returning:
- Matched command path
- Parsed args and flags with values
- Env var and default fallbacks applied
Generates from specs:
- Markdown documentation (
markdown/) - Man pages (
manpage/) - CLI help text (
cli/)
Uses Tera templates for markdown rendering.
Specs use KDL syntax. Key nodes:
name "mycli"
bin "mycli"
flag "-v --verbose" help="Enable verbose output"
arg "<input>" help="Input file"
cmd "subcommand" {
flag "--force"
arg "[optional]"
}
complete "input" run="find . -name '*.txt'"- Snapshot tests use
cargo-instawith auto-review enabled - Shell integration tests require bash, zsh, fish, and pwsh installed
- Run
cargo insta test --acceptto update snapshots
kdl: KDL parser for spec filesclap: CLI parsing for the usage tool itselfmiette: Error reporting with diagnosticstera: Template engine for markdown docsinsta: Snapshot testing
When posting comments on GitHub PRs or discussions, always include a note that the comment was AI-generated (e.g., "This comment was generated by Claude Code.").