agentleFS
Sequela02Sequela02/canasta/skills/workflow/cli-design/SKILL.md

cli-design

Skill0 starsChanged yesterdayMITView on GitHub

Design or review a command-line interface that people, scripts and coding agents run (commands, flags, output, --json, exit codes, help, errors, prompts, signals). Use before adding or changing a command or flag, and when reviewing one. Not for the library a command wraps (api-design).

18 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use writing and review.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • alxyrginSkill

    writing

    Создание контента для личного бренда — статьи, посты, туториалы. Use when user asks to "напиши статью", "создай пост", "подготовь контент", "write article", "create content", or when task requires content creation for blogging, LinkedIn, Medium, or other publishing platforms.

    Also in 3 projects that use this

  • SentrySkill

    review

    Fixture review skill.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

10 rules. 0 are common, 6 are distinctive, and 4 are very specific to this project.

  • 0

    Common

    Most of the 15 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When the CLI wraps a library, design the library first with api-design: the command line maps arguments onto it and prints its result.

    line 16
  2. Very specific:

    Use the platform's parser in strict mode (util.parseArgs with strict: true, clap, argparse).

    line 52
  3. Very specific:

    Prefer flags to positionals.

    line 55
  4. Distinctive:

    When a value can contain commas, as an expression can, repeat the flag instead of splitting on commas.

    line 59
  5. Distinctive:

    No catch-all command and no prefix matching of command names.

    line 61
  6. Distinctive:

    Keep the JSON deterministic: the same input gives the same bytes.

    line 74
  7. Distinctive:

    Keep codes clear of the shell (126 to 165, 255), the runtime (Node uses 1 and 3 to 14) and any tool you wrap.

    line 86
  8. Distinctive:

    Every error says what went wrong, where, and the exact next command to run.

    line 93
  9. Very specific:

    Never require a prompt. Without a TTY on stdin, or with --no-input, fail fast and name the flag to pass.

    line 101
  10. Distinctive:

    Run the checklist in contract tests.

    line 116

“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

CLI design

A command line is an API whose callers are people, scripts and agents. An agent reads the exit code first, then stdout, and never answers a prompt. Design for that reader and for a person at a terminal at once.

When the CLI wraps a library, design the library first with api-design: the command line maps arguments onto it and prints its result. Document the CLI with technical-writing.

Design a command line

Each step ends when its output exists. Stop when a step shows that no consumer needs the feature.

  1. Consumers. List the real callers (a person at a terminal, an agent's tool call, a CI job), each with the exact command line it will run.
  2. Result. Fix the result type first. --json prints exactly that result. The CLI adds fields only for failures that happen before the library is called.
  3. Grammar. A synopsis per command: at most one positional (usually the input file), long names for every flag, value names, which flags repeat, defaults, and mutual exclusions. Reuse the standard names below and the wrapped tool's names.
  4. Outcomes. One row per outcome: exit code, stream, human summary line, JSON status. Include usage error, crash, interrupt and timeout.
  5. Errors. For each failure a user can cause: the message and the next command or flag to try.
  6. Terminal behaviour. Colour, progress and prompts, split by TTY and non-TTY.
  7. Help. --help per command, leading with examples, plus the short help printed when required input is missing.
  8. Contract tests, written before the implementation: see contract tests.

For a change to an existing CLI, run steps 2 to 5 and 8 against the diff and mark every removed or renamed flag, exit code or JSON field as breaking.

Rules

Parsing

  • Use the platform's parser in strict mode (util.parseArgs with strict: true, clap, argparse). An unknown flag, a missing value, a bad value or an extra positional is a usage error.
  • Prefer flags to positionals. Every flag has a long name. Reserve -h/--help and --version. Standard names: --json, -n/--dry-run, --no-input, -o/--output, -q/--quiet, -f/--force. -- ends options; - means stdin or stdout where a file is taken.
  • When a value can contain commas, as an expression can, repeat the flag instead of splitting on commas.
  • No catch-all command and no prefix matching of command names.

Output

  • The result goes to stdout. Progress, logs, warnings, hints and errors go to stderr.
  • Human-readable output by default. --json prints one JSON document on stdout, with the same exit code as human mode. Add another format only for a consumer that needs it. Use JSON Lines only for long runs that emit events.
  • Once parsing succeeded, failures in --json mode use the result's error shape on stdout. Usage errors stay text on stderr with the usage code, since no result exists yet.
  • Keep the JSON deterministic: the same input gives the same bytes. Put timestamps and durations in a separate field, or leave them out.
  • --json fields, exit codes, flag names and environment variable names are a versioned interface. Human text may change.

Exit codes

  • 0 only when the command did what was asked. A check that examined nothing is not a success.
  • Usage error is 2. Uncaught crash is 1.
  • Give distinct codes only to outcomes a caller branches on, and publish them as a table.
  • Keep codes clear of the shell (126 to 165, 255), the runtime (Node uses 1 and 3 to 14) and any tool you wrap. A range such as 20 to 29 is clear of all three for a Node CLI.
  • Interrupt exits 130 (SIGINT) or 143 (SIGTERM), after a bounded cleanup.

Errors and help

  • Every error says what went wrong, where, and the exact next command to run. Put the key line last. No stack trace for an expected error.
  • --help goes to stdout with exit 0, shows defaults, and leads with real examples. Missing required input prints short help to stderr with the usage code.

Terminal and environment

  • Never require a prompt. Without a TTY on stdin, or with --no-input, fail fast and name the flag to pass. Read stdin only when it is not a TTY or when - is given.
  • Colour and animation only when that stream is a TTY. Respect NO_COLOR, TERM=dumb and --no-color. On a non-TTY, print progress as plain lines.
  • Print something within about 100 ms for anything slow.
  • Bound every wait with a timeout that has a default. A timeout is its own outcome, never success.
  • Configuration precedence: flags, then environment, then project file, then user file. Read secrets from a file or stdin, never from a flag.
  • Make state-changing commands safe to rerun. Destructive ones get --dry-run and an explicit --yes or --force.

Review an existing CLI

Run the checklist in contract tests. Report each failure with the command line that shows it, its exit code and output, and the rule it breaks.

Done when

  • the synopsis, the outcome table and the error messages exist;
  • the contract tests run the built binary, and pass;
  • the stable surface (flags, exit codes, JSON fields) is listed in the docs.

Sources lists the evidence behind these rules and where sources disagree.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.