Skip to main content

Overview

This tutorial walks you through creating a simple CLI that greets users. You’ll learn:
  • How to create a CLI with Cli.create()
  • How to define arguments and options with Zod schemas
  • How to add multiple commands
  • How to enable agent discovery
  • How to test your CLI with an agent
1

Create a simple CLI

Create a new file greet.ts with a basic single-command CLI:
greet.ts
Key points: Cli.create() takes a name and configuration. The args field defines positional arguments with Zod schemas. The run() function receives typed context with c.args.name, and the return value is automatically wrapped and formatted.
2

Run your CLI

Execute your CLI:
You’ll see:
This is TOON format (Token-Optimized Object Notation) - more readable than JSON and uses 60% fewer tokens.
Try adding --json to see JSON output: npx tsx greet.ts world --json
Check the built-in help:
Output:
3

Add options

Extend your CLI with options for more control:
greet.ts
Try it:
Output:
4

Add multiple commands

Convert your CLI to support multiple commands:
greet.ts
Now you can:
The export default cli is important for agent discovery and type generation.
5

Enable agent discovery

Make your CLI discoverable by AI agents using Skills:
This generates skill files and installs them globally so agents can discover your CLI automatically.Output:
Skills are lightweight Markdown files that describe your CLI’s commands, arguments, and options. They’re automatically kept in sync with your code.
Alternatively, register as an MCP server:
This adds your CLI to your agent’s MCP configuration.
6

Test with an agent

Now your agent can discover and use your CLI. Try asking:
The agent will automatically:
  1. Discover your CLI via Skills or MCP
  2. Read the available commands and their schemas
  3. Execute greet hello alice
  4. Parse the TOON output
You can also test the machine-readable manifest:
This outputs Markdown documentation that agents can read:

What You’ve Learned

CLI Creation

How to create CLIs with Cli.create() and add commands with .command()

Type Safety

Using Zod schemas for arguments and options with automatic type inference

Output Formats

TOON as the default token-efficient format, with JSON, YAML, and more available

Agent Discovery

Enabling automatic discovery via skills add and mcp add

Next Steps

Commands & Arguments

Deep dive into command patterns, schemas, and validation

Output & Formats

Learn about output envelopes, CTAs, and format options

Agent Integration

Configure Skills, MCP, and customize agent behavior

Complete Example

Here’s the final CLI from this tutorial:
greet.ts
Want to see a more complete example? Check out the npm CLI example in the incur repository.