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
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:--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, thecommand 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:- Explicit
--formator--jsonflag - Command-level
formatoption - CLI-level
formatoption - Default (
toon)
Output Policy
Control when output data is displayed withoutputPolicy.
'all' (default)
Displays to both humans and agents:
'agent-only'
Suppresses data in TTY mode, but still returns it to agents:
- CLI-level
outputPolicyapplies to all commands - Group-level
outputPolicyoverrides CLI-level - Command-level
outputPolicyoverrides group-level
Streaming Output
Useasync *run to stream chunks incrementally:
--format jsonl, each chunk becomes a structured event:
Error Handling
Errors are automatically captured and normalized:Thrown Errors
Structured Errors
Usec.error() for custom error codes:
Validation Errors
Validation errors include field-level details:--verbose:
Next Steps
CLI Creation
Learn how to create and configure CLIs
Middleware
Explore middleware for composable hooks

