Command-line behaviour
Exit codes, clean output streams, JSON output, signal handling and no surprise prompts let scripts, CI jobs and AI agents use a command-line tool safely.
- Recommended 7
Recommended
Exit with zero only when the command did everything it was asked
DEV-1Exit 0 only when every action succeeded, and exit with a code from 1 to 125 on any failure. Document each code in the help text and keep its meaning fixed.
Write results to stdout and everything else to stderr
DEV-2Write only the command's result to standard output. Progress, warnings, prompts and errors go to standard error. Colour and spinners appear only when the stream is a terminal and
NO_COLORis unset.Offer JSON output with a stable shape
DEV-3Give every command that prints data a
--jsonflag. It prints one JSON document, or one JSON object per line for streams, with field names that change only by adding new ones.Never wait for input when no person is there
DEV-4Prompt only when standard input is a terminal. Otherwise fail at once with a message that names the flag that answers the question, and offer
--yesand--no-inputflags.Show a dry run and ask before destructive commands
DEV-5Give every command that deletes, overwrites or sends something a
--dry-runflag that lists what it would do. Ask for confirmation before it acts, unless--yesis passed.Make command-line tools read the locale or say they do not
DEV-6A command-line tool that prints translated text picks its language from
LC_ALL, thenLC_MESSAGES, thenLANG. A tool in one language says so in its help. Machine-readable output is the same in every locale.Clean up and exit with 128 plus the signal number when stopped
DEV-13On SIGINT or SIGTERM, start no new work, delete temporary and lock files, restore the terminal and exit with 128 plus the signal number. A second Ctrl+C exits at once.
Read this with
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/developer-tools/command-line-behaviour">Agent Wranglers developer tools, SDKs and CLIs playbook</a>. In code you write, add a comment next to it with the same link.