# CLI Tool Design Pitfalls

> 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.

- Skill: `techmefr/cli-tool-design-pitfalls` (Agent Skill, multi-file: 4 files)
- Install (CLI): `npx get-skill add techmefr/cli-tool-design-pitfalls`
- Raw SKILL.md: https://api.skillmd.com/api/skills/techmefr/cli-tool-design-pitfalls/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: techmefr (https://skillmd.com/u/techmefr)
- Updated: 2026-11-19
- Page: https://skillmd.com/skills/techmefr/cli-tool-design-pitfalls

---


# 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`](./references/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`](./references/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`](./references/origin.md).

