cli-tool-design-pitfalls
Step 6 of the pipeline (WORKFLOW.md), for the interface of a command-line program, whatever language it is
written in. The premise: a command-line tool has two kinds of caller, a person at a terminal and a script with
no terminal, and most defects are one caller's convenience breaking the other: a progress message on standard
output that corrupts a pipe, a success code after a failure, a prompt that hangs a pipeline, a token in an
argument that every user of the machine can read. Writing the shell scripts that call tools is in
shell-scripting-conventions and bash-pitfalls-and-bats; a tool exposed to an agent is in mcp-server-design-pitfalls.
When
- A new command, subcommand or flag is added, renamed or removed.
- A tool prints, prompts, reads configuration or exits.
- A tool is called from CI, a hook or another program.
- A command can delete, overwrite, send or spend something.
Skip when the program is an internal build or maintenance script that only the repository's own pipeline and its maintainers call, with no published interface: read §1.1, §1.2 and §2.1.8 and say "not applicable: reason" for completions, configuration precedence, deprecation periods and the rest rather than invent a finding.
Steps
Read only the section the task meets. They are independent.
| § |
Covers |
Read it when |
File |
| 1 |
Output streams, exit codes, machine-readable output, colour and progress, interactive versus non-interactive, signals |
a command prints, prompts or exits |
01-streams-exit-codes-and-scripting.md |
| 2 |
Command and flag naming, configuration precedence, secrets, destructive actions, help and errors, completions, compatibility |
a command surface, option or message is designed or changed |
02-surface-config-and-safety.md |
Output / checkpoint
Each section ends with its own checks. For a change touching this block: results go to standard output and
everything else to standard error, failure exits non-zero with a message that says what to do, the command runs
with no terminal and no prompt, no secret is accepted as an argument value, and a destructive command on data the user owns has a
dry-run and a non-interactive confirmation flag (a directory the tool itself regenerates is exempt, §2.4.6).
Guardrails
- Write only the result to standard output; send messages, progress and warnings to standard error (§1.1). Never mix them.
- Exit zero only on success and name each failure class with its own non-zero code (§1.2). Never exit zero after an error, and never turn an error in the tool's own environment into "nothing to do" (§1.2.6).
- Detect a missing terminal and never wait for input there (§1.4). Never block a pipeline on a prompt.
- Take secrets from a file, an environment variable or standard input, not from an argument (§2.3).
- Give every destructive command on user data a preview and an explicit flag to skip confirmation (§2.4).
- Once a flag, output format or exit code is published, change it only with a deprecation period (§2.6).
- Conventions below are general practice from our own knowledge; only the colour variable and the base-directory defaults were checked against their specifications (🟡, nothing here was run).
Origin
Own guidance, from the craft of writing command-line tools, plus two convention pages read for facts (no-colour, freedesktop base directories). The published command-line guide is CC BY-SA 4.0 (licence file read) and was not opened. See
references/origin.md.
1---2name: cli-tool-design-pitfalls3description: "Use when designing or reviewing a command-line tool that people or scripts will call: command and flag naming, standard output versus standard error, exit codes, machine-readable output, prompts and non-interactive use, configuration precedence, secrets on the command line, destructive actions, help and error messages, and shell completions."4metadata:5 source: https://skillmd.com/skills/techmefr/cli-tool-design-pitfalls6---78# cli-tool-design-pitfalls910Step 6 of the pipeline (`WORKFLOW.md`), for the interface of a command-line program, whatever language it is11written in. The premise: **a command-line tool has two kinds of caller, a person at a terminal and a script with12no terminal, and most defects are one caller's convenience breaking the other**: a progress message on standard13output that corrupts a pipe, a success code after a failure, a prompt that hangs a pipeline, a token in an14argument that every user of the machine can read. Writing the shell scripts that call tools is in15`shell-scripting-conventions` and `bash-pitfalls-and-bats`; a tool exposed to an agent is in `mcp-server-design-pitfalls`.1617## When18- A new command, subcommand or flag is added, renamed or removed.19- A tool prints, prompts, reads configuration or exits.20- A tool is called from CI, a hook or another program.21- A command can delete, overwrite, send or spend something.2223**Skip when** the program is an internal build or maintenance script that only the repository's own pipeline and its maintainers call, with no published interface: read §1.1, §1.2 and §2.1.8 and say "not applicable: reason" for completions, configuration precedence, deprecation periods and the rest rather than invent a finding.2425## Steps2627**Read only the section the task meets.** They are independent.2829| § | Covers | Read it when | File |30|---|---|---|---|31| 1 | Output streams, exit codes, machine-readable output, colour and progress, interactive versus non-interactive, signals | a command prints, prompts or exits | [`01-streams-exit-codes-and-scripting.md`](./references/01-streams-exit-codes-and-scripting.md) |32| 2 | Command and flag naming, configuration precedence, secrets, destructive actions, help and errors, completions, compatibility | a command surface, option or message is designed or changed | [`02-surface-config-and-safety.md`](./references/02-surface-config-and-safety.md) |3334## Output / checkpoint35Each section ends with its own checks. For a change touching this block: results go to standard output and36everything else to standard error, failure exits non-zero with a message that says what to do, the command runs37with no terminal and no prompt, no secret is accepted as an argument value, and a destructive command on data the user owns has a38dry-run and a non-interactive confirmation flag (a directory the tool itself regenerates is exempt, §2.4.6).3940## Guardrails41- Write only the result to standard output; send messages, progress and warnings to standard error (§1.1). Never mix them.42- Exit zero only on success and name each failure class with its own non-zero code (§1.2). Never exit zero after an error, and never turn an error in the tool's own environment into "nothing to do" (§1.2.6).43- Detect a missing terminal and never wait for input there (§1.4). Never block a pipeline on a prompt.44- Take secrets from a file, an environment variable or standard input, not from an argument (§2.3).45- Give every destructive command on user data a preview and an explicit flag to skip confirmation (§2.4).46- Once a flag, output format or exit code is published, change it only with a deprecation period (§2.6).47- Conventions below are general practice from our own knowledge; only the colour variable and the base-directory defaults were checked against their specifications (🟡, nothing here was run).4849## Origin50Own guidance, from the craft of writing command-line tools, plus two convention pages read for facts (no-colour, freedesktop base directories). The published command-line guide is CC BY-SA 4.0 (licence file read) and was not opened. See51[`references/origin.md`](./references/origin.md).