Overview
Incur uses Zod schemas to validate inputs and outputs. Schemas enable:- Automatic validation — inputs are parsed before
run()executes - Type inference — TypeScript infers types from schemas with zero manual annotations
- Error reporting — validation errors include field-level details
- Schema composition — reuse schemas across commands
Importing Zod
Incur re-exports Zod, so you can importz directly from incur:
Arguments Schema
Theargs schema defines positional arguments. Keys define the order arguments are parsed from the command line.
Optional Arguments
Use.optional() to make an argument optional:
Default Values
Use.default() to provide a fallback value:
Options Schema
Theoptions schema defines named flags. Options are parsed from --name value or --name (for booleans).
Boolean Options
Boolean options are flags that don’t require a value:--no- prefix to negate:
String Options
String options require a value:Number Options
Number options are automatically coerced:Enum Options
Usez.enum() for a fixed set of values:
Array Options
Usez.array() to collect multiple values:
Kebab-Case to camelCase
Incur automatically maps kebab-case flags to camelCase schema keys:Environment Variables Schema
Theenv schema validates environment variables. Keys are the variable names (e.g. NPM_TOKEN).
DEPLOY_TOKEN is not set, incur raises a validation error before run() executes.
Output Schema
Theoutput schema validates the return value from run(). This ensures the command always returns data in the expected shape.
Type Inference
Incur infers types from schemas automatically. No manual type annotations are required.Schema Composition
Reuse schemas across commands:Schema Extensions
Extend schemas with.merge() or .extend():
Validation Errors
When validation fails, incur provides detailed field-level errors:Descriptions
Use.describe() to add human-readable descriptions shown in help output:
Deprecated Options
Mark options as deprecated with.meta({ deprecated: true }):
[deprecated] in --help and emit a warning when used:
Next Steps
Output
Learn about output formats and CTAs
Zod Documentation
Explore Zod’s full schema API

