cli-design

Design Unix-composable command-line interfaces with stream separation, format flags, and exit codes.

Updated May 30, 2026
One-click install
npx skills add https://github.com/chloebrett/snitchos --skill cli-design-chloebrett
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cli-design
Source: https://github.com/chloebrett/snitchos/tree/main/.claude/skills/cli-design
Command: npx skills add https://github.com/chloebrett/snitchos --skill cli-design-chloebrett

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? CLI tools often break downstream pipelines by mixing diagnostics into stdout, using inconsistent exit codes, or lacking machine-readable output. This Skill provides language-agnostic design rules and implementation patterns for building CLIs that compose cleanly in Unix pipelines and scripts. ## Core Features & Use Cases - Stream and Format Contracts: Enforces stdout-for-data and stderr-for-diagnostics separation, with a three-tier format hierarchy (human-readable, --plain, --json) plus NDJSON streaming. - Exit Codes, TTY Detection, and Error Design: Defines semantic exit codes (0, 1, 2, 75, 78, 130, 143), an 8-level TTY/color detection priority, and structured error envelopes with machine-readable codes and fix suggestions. - Implementation Resources: Provides TypeScript patterns for Result types, entry point wiring, formatters, signal handling, crash-only design, pager integration, and Vitest-based CLI contract testing. - Use Case: When building a new CLI tool, apply the verification checklist to guarantee piped output contains zero ANSI codes, every prompt has a --yes bypass, and JSON schemas remain stable across versions. ## Quick Start Use the cli-design skill to review my CLI tool's output layer and fix any stdout/stderr separation or exit code issues.

Frequently Asked Questions about cli-design

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I separate stdout and stderr in a CLI tool?

Route only data and results to stdout, and send all progress, spinners, warnings, and errors to stderr. stdout is block-buffered when piped for throughput, while stderr is unbuffered so diagnostics appear immediately even when stdout is piped to another program.

What exit codes should a CLI tool use?

Use 0 for success, 1 for domain failures, 2 for invalid usage, 75 for temporary failures that retry logic can act on, and 78 for configuration errors. Codes 130 and 143 represent SIGINT and SIGTERM; never use codes above 125 for application errors since they are reserved for signals.

How do I make CLI output machine-readable with JSON?

Add a --json flag that emits only valid JSON on stdout using a consistent envelope with ok, data, and error fields. Errors must be structured JSON too, including a machine-readable code, message, fix suggestion, and a transient boolean for retry logic.

Does NO_COLOR and TTY detection affect CLI output?

Yes, check flags first, then NO_COLOR, FORCE_COLOR, TERM=dumb, CI, and finally isatty on each stream independently. When stdout is piped but stderr is a TTY, you can still show spinners on stderr while keeping piped stdout free of ANSI escape codes.

Why does my CLI break when piped to head or jq?

Piping breaks when diagnostics or ANSI codes leak onto stdout, or when SIGPIPE is unhandled. In Node.js, SIGPIPE is ignored by default and surfaces as an EPIPE error, so you must catch it and exit silently with code 141.

How do I test CLI stream separation and exit codes?

Spawn the CLI as a subprocess with a test runner helper that captures stdout, stderr, and exit code independently. Assert that --json output parses as valid JSON, non-zero exits always include a stderr explanation, and piped output contains no ANSI codes or spinner characters.