Skip to main content

Overview

Incur normalizes all command output into a structured envelope with consistent shape. The envelope includes:
  • Data — the command’s return value
  • Metadata — command name, duration, and CTAs
  • Error details — when the command fails
By default, incur uses TOON format for output, which is up to 60% more token-efficient than JSON for agents.

Output Envelope Structure

Every command produces an output envelope with a consistent structure.

Success Envelope

Error Envelope

Return Values

By default, commands return data directly:
Use --verbose to see the full envelope:

Using c.ok() and c.error()

Use c.ok() and c.error() to attach CTAs or signal structured errors.

c.ok()

Return success with optional metadata:

c.error()

Return a structured error:

Call-to-Actions (CTAs)

CTAs tell users (human or agent) what commands to run next. They appear after successful or failed commands.

String CTAs

Simplest form — just the command name:

Object CTAs

Provide structured arguments and options with descriptions:

Type-Safe CTAs

CTAs are fully type-inferred. If your CLI has registered commands, the command field is typed as a union of command names:

Output Formats

Incur supports multiple output formats. Use --format <fmt> or --json to override the default.

TOON (default)

TOON is a token-efficient format designed for agents. It strips braces, quotes, and redundant keys.

JSON

Standard JSON with indentation:

YAML

YAML format:

Markdown

Tables for flat objects and arrays:

JSONL

Newline-delimited JSON, useful for streaming:

Format Priority

Formats are resolved in this order:
  1. Explicit --format or --json flag
  2. Command-level format option
  3. CLI-level format option
  4. Default (toon)

Output Policy

Control when output data is displayed with outputPolicy.

'all' (default)

Displays to both humans and agents:

'agent-only'

Suppresses data in TTY mode, but still returns it to agents:
Inheritance:
  • CLI-level outputPolicy applies to all commands
  • Group-level outputPolicy overrides CLI-level
  • Command-level outputPolicy overrides group-level

Streaming Output

Use async *run to stream chunks incrementally:
With default TOON format, each chunk is printed as a line:
With --format jsonl, each chunk becomes a structured event:

Error Handling

Errors are automatically captured and normalized:

Thrown Errors

Structured Errors

Use c.error() for custom error codes:

Validation Errors

Validation errors include field-level details:
With --verbose:

Next Steps

CLI Creation

Learn how to create and configure CLIs

Middleware

Explore middleware for composable hooks