Skip to main content

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 import z directly from incur:

Arguments Schema

The args 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

The options 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:
Use --no- prefix to negate:

String Options

String options require a value:

Number Options

Number options are automatically coerced:

Enum Options

Use z.enum() for a fixed set of values:

Array Options

Use z.array() to collect multiple values:

Kebab-Case to camelCase

Incur automatically maps kebab-case flags to camelCase schema keys:

Environment Variables Schema

The env schema validates environment variables. Keys are the variable names (e.g. NPM_TOKEN).
If DEPLOY_TOKEN is not set, incur raises a validation error before run() executes.

Output Schema

The output schema validates the return value from run(). This ensures the command always returns data in the expected shape.
If the return value doesn’t match, incur raises a validation error.

Type Inference

Incur infers types from schemas automatically. No manual type annotations are required.
Type errors are caught at compile time:

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:
In non-TTY mode (agents), errors include machine-readable field details:

Descriptions

Use .describe() to add human-readable descriptions shown in help output:

Deprecated Options

Mark options as deprecated with .meta({ deprecated: true }):
Deprecated flags show [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