Comprehensive guidelines for building command-line tools that follow UNIX conventions, designed for AI agents and LLMs. Contains 44 rules across 8 categories, prioritized by impact from critical (argument handling, exit codes, output streams) to incremental (configuration and environment).
When to Apply
Reference these guidelines when:
Writing new CLI tools in any language
Parsing command-line arguments and flags
Deciding what goes to stdout vs stderr
Choosing appropriate exit codes
Handling signals like SIGINT and SIGTERM
Rule Categories by Priority
Priority
Category
Impact
Prefix
1
Argument & Flag Design
CRITICAL
args-
2
Exit Codes
CRITICAL
exit-
3
Output Streams
CRITICAL
output-
4
Error Handling
HIGH
error-
5
I/O & Composition
HIGH
io-
6
Help & Documentation
MEDIUM-HIGH
help-
7
Signals & Robustness
MEDIUM
signal-
8
Configuration & Environment
MEDIUM
config-
Quick Reference
1. Argument & Flag Design (CRITICAL)
args-use-getopt - Use standard argument parsing libraries
args-provide-long-options - Provide long options for all short options
args-support-double-dash - Support double-dash to terminate options
args-require-help-version - Implement --help and --version options
args-prefer-flags-over-positional - Prefer flags over positional arguments
args-use-standard-flag-names - Use standard flag names
args-never-read-secrets-from-flags - Never read secrets from command-line flags
args-support-option-bundling - Support option bundling
2. Exit Codes (CRITICAL)
exit-zero-for-success - Return zero for success only
exit-use-standard-codes - Use standard exit codes
exit-signal-codes - Use 128+N for signal termination
help-show-usage-on-error - Show brief usage on argument errors
help-structure-help-output - Structure help output consistently
help-show-defaults - Show default values in help
help-include-examples - Include practical examples in help
help-version-format - Format version output correctly
7. Signals & Robustness (MEDIUM)
signal-handle-sigint - Handle SIGINT gracefully
signal-handle-sigterm - Handle SIGTERM for clean shutdown
signal-handle-sigpipe - Handle SIGPIPE for broken pipes
signal-cleanup-on-second-interrupt - Skip cleanup on second interrupt
8. Configuration & Environment (MEDIUM)
config-follow-xdg - Follow XDG Base Directory Specification
config-precedence-order - Apply configuration in correct precedence order
config-env-naming - Use consistent environment variable naming
config-never-store-secrets - Never store secrets in config files or environment
config-respect-standard-vars - Respect standard environment variables
How to Use
Read individual reference files for detailed explanations and code examples:
Section definitions - Category structure and impact levels
Rule template - Template for adding new rules
Reference Files
File
Description
references/_sections.md
Category definitions and ordering
assets/templates/_template.md
Template for new rules
metadata.json
Version and reference information
1---2name: unix-cli3description: UNIX/POSIX Standards CLI Best Practices4---5# UNIX/POSIX Standards CLI Best Practices67Comprehensive guidelines for building command-line tools that follow UNIX conventions, designed for AI agents and LLMs. Contains 44 rules across 8 categories, prioritized by impact from critical (argument handling, exit codes, output streams) to incremental (configuration and environment).89## When to Apply1011Reference these guidelines when:12- Writing new CLI tools in any language13- Parsing command-line arguments and flags14- Deciding what goes to stdout vs stderr15- Choosing appropriate exit codes16- Handling signals like SIGINT and SIGTERM1718## Rule Categories by Priority1920| Priority | Category | Impact | Prefix |21|----------|----------|--------|--------|22| 1 | Argument & Flag Design | CRITICAL | `args-` |23| 2 | Exit Codes | CRITICAL | `exit-` |24| 3 | Output Streams | CRITICAL | `output-` |25| 4 | Error Handling | HIGH | `error-` |26| 5 | I/O & Composition | HIGH | `io-` |27| 6 | Help & Documentation | MEDIUM-HIGH | `help-` |28| 7 | Signals & Robustness | MEDIUM | `signal-` |29| 8 | Configuration & Environment | MEDIUM | `config-` |3031## Quick Reference3233### 1. Argument & Flag Design (CRITICAL)3435- [`args-use-getopt`](references/args-use-getopt.md) - Use standard argument parsing libraries36- [`args-provide-long-options`](references/args-provide-long-options.md) - Provide long options for all short options37- [`args-support-double-dash`](references/args-support-double-dash.md) - Support double-dash to terminate options38- [`args-require-help-version`](references/args-require-help-version.md) - Implement --help and --version options39- [`args-prefer-flags-over-positional`](references/args-prefer-flags-over-positional.md) - Prefer flags over positional arguments40- [`args-use-standard-flag-names`](references/args-use-standard-flag-names.md) - Use standard flag names41- [`args-never-read-secrets-from-flags`](references/args-never-read-secrets-from-flags.md) - Never read secrets from command-line flags42- [`args-support-option-bundling`](references/args-support-option-bundling.md) - Support option bundling4344### 2. Exit Codes (CRITICAL)4546- [`exit-zero-for-success`](references/exit-zero-for-success.md) - Return zero for success only47- [`exit-use-standard-codes`](references/exit-use-standard-codes.md) - Use standard exit codes48- [`exit-signal-codes`](references/exit-signal-codes.md) - Use 128+N for signal termination49- [`exit-partial-success`](references/exit-partial-success.md) - Handle partial success consistently50- [`exit-distinguish-error-types`](references/exit-distinguish-error-types.md) - Distinguish error types with different exit codes5152### 3. Output Streams (CRITICAL)5354- [`output-stdout-for-data`](references/output-stdout-for-data.md) - Write data to stdout only55- [`output-stderr-for-errors`](references/output-stderr-for-errors.md) - Write errors and diagnostics to stderr56- [`output-detect-tty`](references/output-detect-tty.md) - Detect TTY for human-oriented output57- [`output-provide-machine-format`](references/output-provide-machine-format.md) - Provide machine-readable output format58- [`output-line-based-text`](references/output-line-based-text.md) - Use line-based output for text streams59- [`output-respect-no-color`](references/output-respect-no-color.md) - Respect NO_COLOR environment variable6061### 4. Error Handling (HIGH)6263- [`error-include-program-name`](references/error-include-program-name.md) - Include program name in error messages64- [`error-actionable-messages`](references/error-actionable-messages.md) - Make error messages actionable65- [`error-use-strerror`](references/error-use-strerror.md) - Use strerror for system errors66- [`error-avoid-stack-traces`](references/error-avoid-stack-traces.md) - Avoid stack traces in user-facing errors67- [`error-validate-early`](references/error-validate-early.md) - Validate input early and fail fast6869### 5. I/O & Composition (HIGH)7071- [`io-support-stdin`](references/io-support-stdin.md) - Support reading from stdin72- [`io-write-to-stdout`](references/io-write-to-stdout.md) - Write output to stdout by default73- [`io-be-stateless`](references/io-be-stateless.md) - Design stateless operations74- [`io-handle-binary-safely`](references/io-handle-binary-safely.md) - Handle binary data safely75- [`io-atomic-writes`](references/io-atomic-writes.md) - Use atomic file writes76- [`io-handle-multiple-files`](references/io-handle-multiple-files.md) - Handle multiple input files consistently7778### 6. Help & Documentation (MEDIUM-HIGH)7980- [`help-show-usage-on-error`](references/help-show-usage-on-error.md) - Show brief usage on argument errors81- [`help-structure-help-output`](references/help-structure-help-output.md) - Structure help output consistently82- [`help-show-defaults`](references/help-show-defaults.md) - Show default values in help83- [`help-include-examples`](references/help-include-examples.md) - Include practical examples in help84- [`help-version-format`](references/help-version-format.md) - Format version output correctly8586### 7. Signals & Robustness (MEDIUM)8788- [`signal-handle-sigint`](references/signal-handle-sigint.md) - Handle SIGINT gracefully89- [`signal-handle-sigterm`](references/signal-handle-sigterm.md) - Handle SIGTERM for clean shutdown90- [`signal-handle-sigpipe`](references/signal-handle-sigpipe.md) - Handle SIGPIPE for broken pipes91- [`signal-cleanup-on-second-interrupt`](references/signal-cleanup-on-second-interrupt.md) - Skip cleanup on second interrupt9293### 8. Configuration & Environment (MEDIUM)9495- [`config-follow-xdg`](references/config-follow-xdg.md) - Follow XDG Base Directory Specification96- [`config-precedence-order`](references/config-precedence-order.md) - Apply configuration in correct precedence order97- [`config-env-naming`](references/config-env-naming.md) - Use consistent environment variable naming98- [`config-never-store-secrets`](references/config-never-store-secrets.md) - Never store secrets in config files or environment99- [`config-respect-standard-vars`](references/config-respect-standard-vars.md) - Respect standard environment variables100101## How to Use102103Read individual reference files for detailed explanations and code examples:104105- [Section definitions](references/_sections.md) - Category structure and impact levels106- [Rule template](assets/templates/_template.md) - Template for adding new rules107108## Reference Files109110| File | Description |111|------|-------------|112| [references/_sections.md](references/_sections.md) | Category definitions and ordering |113| [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules |114| [metadata.json](metadata.json) | Version and reference information |
Run npx skillmds@latest add comeonoliver/unix-cli in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
UNIX/POSIX Standards CLI Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.