CommandDefinition
Defines a command’s schema, behavior, and documentation. Commands are registered withcli.command().
Type Signature
Properties
Zod schema for positional arguments. Arguments are parsed in the order they are defined in the schema.
A short description of what the command does. Shown in help text, agent discovery, and skill manifests.
Zod schema for command-specific environment variables. Merged with CLI-level env schema. Keys are the variable names (e.g.
DEPLOY_TOKEN).Zod schema for named options/flags. Options are passed as
--key value or --flag for booleans.Zod schema for the return value. Used for output validation and type inference in the command registry.
Map of option names to single-char aliases.
Usage examples for this command. Shown in help output with
--help.Default output format for this command. Overrides CLI-level format. Can still be overridden by
--format or --json flags.Controls when output data is displayed:
'all'— displays to both humans and agents'agent-only'— suppresses data output in human/TTY mode while still returning it to agents
Alternative usage patterns shown in help output. Useful for documenting multiple invocation styles.
Command-specific middleware that runs only for this command. Runs after CLI-level and group-level middleware.
The command handler function. Receives a context object with parsed arguments, options, environment variables, and utility functions.Can return:
- A plain value (synchronous)
- A Promise (asynchronous)
- An AsyncGenerator (streaming)
Context Type
The context object passed to therun handler. Contains parsed inputs, CLI metadata, and control flow functions.
Properties
Whether the consumer is an agent (stdout is not a TTY). Use this to customize output for different audiences.
Positional arguments parsed according to the args schema. Fully typed based on the Zod schema.
The CLI name (not the command name).
Parsed environment variables according to the env schema. Includes both CLI-level and command-level env vars.
Named options/flags parsed according to the options schema. Fully typed based on the Zod schema.
Variables set by middleware. Typed according to the CLI’s vars schema.
Return a success result with optional metadata. Calling this function short-circuits execution and immediately returns.
Return an error result with optional CTAs. Calling this function short-circuits execution, exits with code 1, and displays the error.
The CLI version string, if provided.

