Skip to content
Software Engineering / CLI Design

Design CLIs for agents and humans

  • BP-0001
  • v1.0.0
  • draft
  • guideline
  • role: implementer
  • stage: build
  • updated 2026-11-24
  • reviewed 2026-11-24
  • next review 2027-05-24
  1. MUST provide --json with a stable, documented schema on every command that outputs data.
  2. MUST write data to stdout and diagnostics, progress and prompts to stderr.
  3. MUST never block on a prompt when stdin is not a TTY; fail with a clear message and a non-zero exit code instead.
  4. MUST accept every input as a flag or argument; interactive prompts are a convenience, not the only path.
  5. SHOULD return distinct, documented exit codes (0 success, 1 failure, 2 usage error; others listed in --help).
  6. SHOULD offer --dry-run on every command that changes state, and --yes to skip confirmation explicitly.
  7. SHOULD make --help complete and example-led, and keep it in step with behaviour.
  8. SHOULD make output deterministic: stable ordering, no colour or spinners when not a TTY, honour NO_COLOR.
  9. MAY offer an interactive or TUI mode behind an explicit flag.

Any CLI an agent may call: your own tools, wrappers around APIs, build and ops scripts. Not needed for one-off throwaway scripts that will never be invoked by another program.

  1. List the commands and, for each, what it reads and what it changes.
  2. Define the --json shape per command before writing human output.
  3. Define the exit-code table.
  4. Implement; human output is a rendering of the same data.
  5. Test with stdin closed (</dev/null) and stdout piped to confirm nothing blocks or leaks ANSI codes.

Good:

Terminal window
$ parts list --json
[{"id":"R-10K","qty":120}]
$ echo $?
0

Bad:

Terminal window
$ parts list
✨ Found 1 part! ✨
R-10K .... 120 left
Continue? [y/N]

The bad version mixes decoration with data, has no machine format, and blocks an unattended caller.

  • Parsing your own human-readable output in tests or other tools instead of using --json.
  • Exit code 0 on partial failure.
  • Changing JSON field names in a minor release.
  • Every data command has --json
  • Runs unattended with stdin closed
  • Exit codes listed in --help
  • State-changing commands support --dry-run