cli-design
Use this skill when building command-line interfaces, designing CLI argument parsers, writing help text, adding interactive prompts, managing config files, or distributing CLI tools. Triggers on argument parsing, subcommands, flags, positional arguments, stdin/stdout piping, shell completions, interactive menus, dotfile configuration, and packaging CLIs as npm/pip/cargo/go binaries.
engineering cliterminalargument-parsingconfigdistributionpromptsWhat is cli-design?
Use this skill when building command-line interfaces, designing CLI argument parsers, writing help text, adding interactive prompts, managing config files, or distributing CLI tools. Triggers on argument parsing, subcommands, flags, positional arguments, stdin/stdout piping, shell completions, interactive menus, dotfile configuration, and packaging CLIs as npm/pip/cargo/go binaries.
cli-design
cli-design is a production-ready AI agent skill for claude-code, gemini-cli, openai-codex. Building command-line interfaces, designing CLI argument parsers, writing help text, adding interactive prompts, managing config files, or distributing CLI tools.
Quick Facts
| Field | Value |
|---|---|
| Category | engineering |
| Version | 0.1.0 |
| Platforms | claude-code, gemini-cli, openai-codex |
| License | MIT |
How to Install
- Make sure you have Node.js installed on your machine.
- Run the following command in your terminal:
npx skills add AbsolutelySkilled/AbsolutelySkilled --skill cli-design- The cli-design skill is now available in your AI coding agent (Claude Code, Gemini CLI, OpenAI Codex, etc.).
Overview
CLI design is the practice of building command-line tools that are intuitive, composable, and self-documenting. A well-designed CLI follows the principle of least surprise - flags behave like users expect, help text answers questions before they are asked, and errors guide toward resolution rather than dead ends. This skill covers argument parsing, help text conventions, interactive prompts, configuration file hierarchies, and distribution strategies across Node.js, Python, Go, and Rust ecosystems.
Tags
cli terminal argument-parsing config distribution prompts
Platforms
- claude-code
- gemini-cli
- openai-codex
Related Skills
Pair cli-design with these complementary skills:
Frequently Asked Questions
What is cli-design?
Use this skill when building command-line interfaces, designing CLI argument parsers, writing help text, adding interactive prompts, managing config files, or distributing CLI tools. Triggers on argument parsing, subcommands, flags, positional arguments, stdin/stdout piping, shell completions, interactive menus, dotfile configuration, and packaging CLIs as npm/pip/cargo/go binaries.
How do I install cli-design?
Run npx skills add AbsolutelySkilled/AbsolutelySkilled --skill cli-design in your terminal. The skill will be immediately available in your AI coding agent.
What AI agents support cli-design?
This skill works with claude-code, gemini-cli, openai-codex. Install it once and use it across any supported AI coding agent.
Maintainers
Generated from AbsolutelySkilled
SKILL.md
CLI Design
CLI design is the practice of building command-line tools that are intuitive, composable, and self-documenting. A well-designed CLI follows the principle of least surprise - flags behave like users expect, help text answers questions before they are asked, and errors guide toward resolution rather than dead ends. This skill covers argument parsing, help text conventions, interactive prompts, configuration file hierarchies, and distribution strategies across Node.js, Python, Go, and Rust ecosystems.
When to use this skill
Trigger this skill when the user:
- Wants to build a new CLI tool or add subcommands to an existing one
- Needs to parse arguments, flags, options, or positional parameters
- Asks about help text formatting, usage strings, or man pages
- Wants to add interactive prompts, confirmations, or selection menus
- Needs to manage config files (dotfiles, rc files, XDG directories)
- Asks about distributing a CLI via npm, pip, cargo, brew, or standalone binary
- Wants to add shell completions (bash, zsh, fish)
- Needs to handle stdin/stdout piping and exit codes correctly
Do NOT trigger this skill for:
- GUI application design or web UI - use frontend or ultimate-ui skills
- Shell scripting syntax questions unrelated to building a distributable CLI tool
Key principles
Predictability over cleverness - Follow POSIX conventions: single-dash short flags (
-v), double-dash long flags (--verbose),--to end flag parsing. Users should never have to guess how your flags work.Self-documenting by default - Every command must have a
--helpthat shows usage, all flags with descriptions, and at least one example. If a user needs to read external docs to run a command, the help text has failed.Fail loudly, recover gracefully - Print errors to stderr, not stdout. Use non-zero exit codes for failures. Include the failed input and a suggested fix in every error message. Never fail silently.
Composability - Respect the Unix philosophy: accept stdin, produce clean stdout, use stderr for diagnostics. Support
--jsonor--output=jsonfor machine-readable output so other tools can pipe it.Progressive disclosure - Show the simplest usage first. Hide advanced flags behind
--helpsubgroups or separatehelp <topic>commands. New users see 5 flags; power users discover 30.
Core concepts
Argument taxonomy
CLI arguments fall into four categories that every parser must handle:
| Type | Example | Notes |
|---|---|---|
| Subcommand | git commit |
Verb that selects behavior |
| Positional | cp source dest |
Order-dependent, unnamed |
| Flag (boolean) | --verbose, -v |
Presence toggles a setting |
| Option (valued) | --output file.txt, -o file.txt |
Key-value pair |
Short flags can be combined: -abc equals -a -b -c. Options consume the
next token or use =: --out=file or --out file.
Config hierarchy
CLIs should load configuration from multiple sources, with later sources overriding earlier ones:
1. Built-in defaults (hardcoded)
2. System config (/etc/<tool>/config)
3. User config (~/.config/<tool>/config or ~/.<tool>rc)
4. Project config (./<tool>.config.json or ./<tool>rc)
5. Environment vars (TOOL_OPTION=value)
6. CLI flags (--option value)Exit codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Misuse of command (bad flags, missing args) |
| 126 | Command found but not executable |
| 127 | Command not found |
| 128+N | Killed by signal N (e.g. 130 = Ctrl+C / SIGINT) |
Common tasks
1. Parse arguments with Node.js (Commander.js)
Define commands declaratively and let Commander handle help generation.
import { Command } from 'commander';
const program = new Command();
program
.name('mytool')
.description('A CLI that does useful things')
.version('1.0.0');
program
.command('deploy')
.description('Deploy the application to a target environment')
.argument('<environment>', 'target environment (staging, production)')
.option('-d, --dry-run', 'show what would happen without deploying')
.option('-t, --tag <tag>', 'docker image tag to deploy', 'latest')
.option('--timeout <ms>', 'deploy timeout in milliseconds', '30000')
.action((environment, options) => {
if (options.dryRun) {
console.log(`Would deploy ${options.tag} to ${environment}`);
return;
}
deploy(environment, options.tag, parseInt(options.timeout, 10));
});
program.parse();2. Parse arguments with Python (click)
Click uses decorators for commands and handles type conversion, help generation, and shell completions out of the box.
import click
@click.group()
@click.version_option("1.0.0")
def cli():
"""A CLI that does useful things."""
pass
@cli.command()
@click.argument("environment", type=click.Choice(["staging", "production"]))
@click.option("--dry-run", "-d", is_flag=True, help="Show what would happen.")
@click.option("--tag", "-t", default="latest", help="Docker image tag.")
@click.option("--timeout", default=30000, type=int, help="Timeout in ms.")
def deploy(environment, dry_run, tag, timeout):
"""Deploy the application to a target environment."""
if dry_run:
click.echo(f"Would deploy {tag} to {environment}")
return
do_deploy(environment, tag, timeout)
if __name__ == "__main__":
cli()3. Add interactive prompts
Use prompts for destructive actions or first-time setup. Never force
interactivity - always allow --yes / -y to skip prompts for scripting.
import { confirm, select, input } from '@inquirer/prompts';
async function interactiveSetup() {
const name = await input({
message: 'Project name:',
default: 'my-project',
validate: (v) => v.length > 0 || 'Name is required',
});
const template = await select({
message: 'Choose a template:',
choices: [
{ name: 'Minimal', value: 'minimal' },
{ name: 'Full-stack', value: 'fullstack' },
{ name: 'API only', value: 'api' },
],
});
const proceed = await confirm({
message: `Create "${name}" with ${template} template?`,
default: true,
});
if (!proceed) {
console.log('Aborted.');
process.exit(0);
}
return { name, template };
}Always check
process.stdout.isTTYbefore showing prompts. If the output is piped or running in CI, fall back to defaults or error with a clear message about which flags to pass.
4. Manage configuration files
Use cosmiconfig (Node.js) or similar to support multiple config formats.
import { cosmiconfig } from 'cosmiconfig';
const explorer = cosmiconfig('mytool', {
searchPlaces: [
'package.json',
'.mytoolrc',
'.mytoolrc.json',
'.mytoolrc.yaml',
'mytool.config.js',
'mytool.config.ts',
],
});
async function loadConfig(flagOverrides: Record<string, unknown>) {
const result = await explorer.search();
const fileConfig = result?.config ?? {};
// Merge: defaults < file config < env vars < flags
return {
output: 'dist',
verbose: false,
...fileConfig,
...(process.env.MYTOOL_OUTPUT ? { output: process.env.MYTOOL_OUTPUT } : {}),
...flagOverrides,
};
}5. Write effective help text
Follow this template for every command's help output:
Usage: mytool deploy [options] <environment>
Deploy the application to a target environment.
Arguments:
environment target environment (staging, production)
Options:
-d, --dry-run show what would happen without deploying
-t, --tag <tag> docker image tag to deploy (default: "latest")
--timeout <ms> deploy timeout in milliseconds (default: "30000")
-h, --help display help for command
Examples:
$ mytool deploy staging
$ mytool deploy production --tag v2.1.0 --dry-runRules: show Usage: first with <required> and [optional] args. One-line
description. Group options logically with --help and --version last.
Always include 2-3 real examples at the bottom.
6. Handle stdin/stdout piping
Support stdin when no file argument is given. This makes the tool composable.
import { createReadStream } from 'fs';
import { stdin as processStdin } from 'process';
function getInputStream(filePath?: string): NodeJS.ReadableStream {
if (filePath) return createReadStream(filePath);
if (!process.stdin.isTTY) return processStdin;
console.error('Error: No input. Provide a file or pipe stdin.');
console.error(' mytool process <file>');
console.error(' cat file.txt | mytool process');
process.exit(2);
}
function output(data: unknown, json: boolean) {
if (json) {
process.stdout.write(JSON.stringify(data) + '\n');
} else {
console.log(formatHuman(data));
}
}7. Distribute the CLI
Node.js (npm) - set bin in package.json, ensure shebang #!/usr/bin/env node:
{
"name": "mytool",
"bin": { "mytool": "./dist/cli.js" },
"files": ["dist"],
"engines": { "node": ">=18" }
}Python (pip) - use pyproject.toml entry points:
[project.scripts]
mytool = "mytool.cli:cli"Go - go install github.com/org/mytool@latest. Cross-compile with
GOOS=linux GOARCH=amd64 go build.
Rust - cargo install mytool. Cross-compile with cross. Distribute
via crates.io or GitHub Releases.
8. Add shell completions
# Click: built-in completion support
# Users activate with:
# eval "$(_MYTOOL_COMPLETE=zsh_source mytool)"// Clap: generate completions via clap_complete
use clap_complete::{generate, shells::Zsh};
generate(Zsh, &mut cli, "mytool", &mut std::io::stdout());Anti-patterns / common mistakes
| Mistake | Why it is wrong | What to do instead |
|---|---|---|
| Printing errors to stdout | Breaks piping - error text contaminates data stream | Use console.error() or sys.stderr.write() |
| Exit code 0 on failure | Breaks && chaining and CI pipelines |
Always process.exit(1) or sys.exit(1) on error |
| Requiring interactivity | Breaks CI, cron jobs, and scripting | Accept all inputs as flags; prompt only when TTY + flag missing |
No --help on subcommands |
Users cannot discover options | Every command and subcommand gets --help |
| Inconsistent flag naming | --dry-run vs --dryRun vs --dry_run |
Pick kebab-case for flags, be consistent everywhere |
| Giant monolithic help text | Overwhelms users, hides important flags | Use subcommand groups; hide advanced flags in extended help |
| Non-standard flag syntax | /flag or +flag or flag:value |
Stick to POSIX: -f, --flag, --flag=value |
| Swallowing errors silently | User has no idea something failed | Print error to stderr with context and suggested fix |
No --version flag |
Users cannot report which version they run | Always add --version to the root command |
Gotchas
Interactive prompts in CI/scripts - A confirm prompt that blocks waiting for user input will hang a CI job indefinitely with no error message. Always check
process.stdin.isTTY(or equivalent) before prompting, and provide a--yes/-yflag that skips all confirmations.Exit code 0 on partial failure - A command that processes 10 files but fails on 2 and still exits 0 breaks
&&chaining and CI pipelines silently. Track failures explicitly and exit non-zero when any operation failed, even if some succeeded.Flag name inconsistency across subcommands - Having
--dry-runondeploybut--dryRunonmigratecreates a mental tax for users. Establish naming conventions (kebab-case) at project start and enforce them in every subcommand - inconsistency compounds with every new feature.Node.js shebang missing or wrong - Distributing a Node CLI without
#!/usr/bin/env nodeas the first line means users must runnode mytoolinstead ofmytool, and npm'sbinlinking won't work correctly. Always set the shebang and make the file executable (chmod +x).Swallowing parser errors - Argument parsers like Commander.js call
process.exit(1)on invalid args by default, but some configurations catch and suppress these errors. An invalid flag that silently falls back to defaults is extremely confusing. Ensure validation errors always produce a clear message to stderr and a non-zero exit code.
References
For detailed patterns on specific CLI sub-domains, read the relevant file
from the references/ folder:
references/argument-parsing-patterns.md- advanced parsing patterns including variadic args, mutually exclusive flags, coercion, and validation across Node.js, Python, Go, and Rustreferences/config-file-patterns.md- config file formats, XDG Base Directory spec, schema validation, migration strategies, and environment variable conventions
Only load a references file if the current task requires it - they are long and will consume context.
References
argument-parsing-patterns.md
Argument Parsing Patterns
Advanced patterns for argument parsing across Node.js, Python, Go, and Rust. Load this file only when the task requires patterns beyond basic flags and positional arguments.
Variadic arguments
Accept a variable number of positional arguments.
Node.js (Commander.js)
program
.command('concat')
.description('Concatenate multiple files')
.argument('<files...>', 'one or more file paths')
.action((files: string[]) => {
// files is an array: ['a.txt', 'b.txt', 'c.txt']
for (const file of files) {
process.stdout.write(readFileSync(file));
}
});Python (click)
@cli.command()
@click.argument("files", nargs=-1, required=True, type=click.Path(exists=True))
def concat(files):
"""Concatenate multiple files."""
for f in files:
click.echo(open(f).read(), nl=False)Go (cobra)
var concatCmd = &cobra.Command{
Use: "concat <file> [file...]",
Short: "Concatenate multiple files",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
for _, path := range args {
data, err := os.ReadFile(path)
if err != nil { return err }
cmd.OutOrStdout().Write(data)
}
return nil
},
}Rust (clap)
#[derive(Parser)]
struct Concat {
/// One or more file paths
#[arg(required = true, num_args = 1..)]
files: Vec<PathBuf>,
}Mutually exclusive flags
Prevent the user from passing conflicting options.
Node.js (Commander.js) - no built-in support, validate manually:
program
.command('output')
.option('--json', 'output as JSON')
.option('--csv', 'output as CSV')
.option('--table', 'output as table')
.action((options) => {
const formats = [options.json, options.csv, options.table].filter(Boolean);
if (formats.length > 1) {
console.error('Error: --json, --csv, and --table are mutually exclusive.');
process.exit(2);
}
const format = options.json ? 'json' : options.csv ? 'csv' : 'table';
render(format);
});Python (click) - use cls=MutuallyExclusiveOption or manual check:
@cli.command()
@click.option("--json", "fmt", flag_value="json", help="Output as JSON.")
@click.option("--csv", "fmt", flag_value="csv", help="Output as CSV.")
@click.option("--table", "fmt", flag_value="table", default=True, help="Output as table.")
def output(fmt):
"""Render output in the chosen format."""
render(fmt)Go (cobra) - use MarkFlagsMutuallyExclusive:
outputCmd.Flags().Bool("json", false, "output as JSON")
outputCmd.Flags().Bool("csv", false, "output as CSV")
outputCmd.MarkFlagsMutuallyExclusive("json", "csv")Rust (clap) - use conflicts_with:
#[derive(Parser)]
struct Output {
#[arg(long, conflicts_with = "csv")]
json: bool,
#[arg(long, conflicts_with = "json")]
csv: bool,
}Custom type coercion
Parse flag values into specific types with validation.
Node.js (Commander.js) - custom parsing function:
function parsePort(value: string): number {
const port = parseInt(value, 10);
if (isNaN(port) || port < 1 || port > 65535) {
throw new InvalidArgumentError('Port must be between 1 and 65535.');
}
return port;
}
program
.option('-p, --port <number>', 'server port', parsePort, 3000);Python (click) - use click.IntRange or custom ParamType:
@click.option("--port", type=click.IntRange(1, 65535), default=3000, help="Server port.")
def serve(port):
start_server(port)Go (cobra + pflag) - implement pflag.Value interface:
type portValue uint16
func (p *portValue) String() string { return fmt.Sprintf("%d", *p) }
func (p *portValue) Set(s string) error {
v, err := strconv.ParseUint(s, 10, 16)
if err != nil || v < 1 || v > 65535 {
return fmt.Errorf("port must be between 1 and 65535")
}
*p = portValue(v)
return nil
}
func (p *portValue) Type() string { return "port" }Rust (clap) - use value_parser:
#[arg(short, long, default_value_t = 3000, value_parser = clap::value_parser!(u16).range(1..=65535))]
port: u16,Required flags vs required positional args
Rule of thumb: if there is one primary input, make it positional. If there are multiple required inputs with no natural order, make them required options.
# Good: single primary input as positional
mytool compile <file>
# Good: multiple required inputs as named options
mytool deploy --env staging --tag v1.2.3
# Bad: multiple positionals with no obvious order
mytool deploy staging v1.2.3 # which is env, which is tag?Flag groups and conditional requirements
Go (cobra) - require flags together:
cmd.MarkFlagsRequiredTogether("username", "password")
cmd.MarkFlagRequired("config")Rust (clap) - require conditionally:
#[arg(long, requires = "password")]
username: Option<String>,
#[arg(long, requires = "username")]
password: Option<String>,Node.js / Python - validate manually in the action handler. Check for incomplete flag groups and print a clear error:
if (options.username && !options.password) {
console.error('Error: --username requires --password.');
process.exit(2);
}Negatable flags
Allow users to explicitly disable a default-on behavior.
Node.js (Commander.js):
program
.option('--color', 'enable colored output (default)')
.option('--no-color', 'disable colored output');
// options.color is true by default, false if --no-color is passedPython (click):
@click.option("--color/--no-color", default=True, help="Toggle colored output.")Rust (clap):
#[arg(long, default_value_t = true, action = clap::ArgAction::Set)]
color: bool,Environment variable fallback
Let environment variables serve as defaults for flags the user does not pass.
Node.js (Commander.js) - use envVar or manual fallback:
program
.option('--api-key <key>', 'API key')
.action((options) => {
const apiKey = options.apiKey ?? process.env.MYTOOL_API_KEY;
if (!apiKey) {
console.error('Error: --api-key or MYTOOL_API_KEY is required.');
process.exit(2);
}
});Python (click) - use envvar parameter:
@click.option("--api-key", envvar="MYTOOL_API_KEY", required=True, help="API key.")Go (cobra + viper) - bind flags to env vars via viper:
viper.SetEnvPrefix("MYTOOL")
viper.AutomaticEnv()
viper.BindPFlag("api-key", cmd.Flags().Lookup("api-key"))Rust (clap) - use env:
#[arg(long, env = "MYTOOL_API_KEY")]
api_key: String,Library comparison matrix
| Feature | Commander.js | click | cobra | clap |
|---|---|---|---|---|
| Language | Node.js | Python | Go | Rust |
| Subcommands | Yes | Yes | Yes | Yes |
| Auto help | Yes | Yes | Yes | Yes |
| Shell completions | Plugin | Built-in | Built-in | clap_complete |
| Mutually exclusive | Manual | Via flag_value | Built-in | Built-in |
| Env var fallback | Manual | Built-in | Via viper | Built-in |
| Type coercion | Custom fn | ParamType/Range | pflag.Value | value_parser |
| Negatable flags | --no-X | --flag/--no-flag | Manual | ArgAction |
| Variadic args | <args...> |
nargs=-1 |
Args validators |
num_args |
config-file-patterns.md
Config File Patterns
Patterns for managing CLI configuration files across multiple scopes and formats. Load this file only when the task involves config loading, dotfiles, XDG compliance, or config schema validation.
XDG Base Directory Specification
The XDG spec defines where config, data, cache, and state files live on Linux and macOS. Following it keeps user home directories clean.
| Variable | Default | Purpose |
|---|---|---|
XDG_CONFIG_HOME |
~/.config |
User config files |
XDG_DATA_HOME |
~/.local/share |
User data files |
XDG_STATE_HOME |
~/.local/state |
User state (logs, history) |
XDG_CACHE_HOME |
~/.cache |
Non-essential cached data |
Config path resolution:
import { join } from 'path';
import { homedir } from 'os';
function configDir(toolName: string): string {
return join(
process.env.XDG_CONFIG_HOME ?? join(homedir(), '.config'),
toolName
);
}
function dataDir(toolName: string): string {
return join(
process.env.XDG_DATA_HOME ?? join(homedir(), '.local', 'share'),
toolName
);
}
function cacheDir(toolName: string): string {
return join(
process.env.XDG_CACHE_HOME ?? join(homedir(), '.cache'),
toolName
);
}Python:
from pathlib import Path
import os
def config_dir(tool: str) -> Path:
base = Path(os.environ.get("XDG_CONFIG_HOME", Path.home() / ".config"))
return base / tool
def data_dir(tool: str) -> Path:
base = Path(os.environ.get("XDG_DATA_HOME", Path.home() / ".local" / "share"))
return base / toolConfig file formats
JSON
{
"output": "dist",
"verbose": false,
"plugins": ["@mytool/plugin-a"]
}Pros: universal parser support, strict syntax. Cons: no comments, no trailing commas.
YAML
output: dist
verbose: false
plugins:
- "@mytool/plugin-a"Pros: human-readable, supports comments.
Cons: indentation sensitivity, security risks with !! tags.
TOML
output = "dist"
verbose = false
plugins = ["@mytool/plugin-a"]Pros: clear section boundaries, typed values, comments. Cons: less familiar to web developers, verbose for nested structures.
JavaScript / TypeScript
// mytool.config.ts
import type { Config } from 'mytool';
export default {
output: 'dist',
verbose: false,
plugins: ['@mytool/plugin-a'],
} satisfies Config;Pros: type checking, dynamic values, IDE autocompletion. Cons: security risk (arbitrary code execution), harder to lint.
Recommendation
Offer JSON and YAML at minimum. Add TypeScript config support for
developer tools. Use cosmiconfig (Node.js) or dynaconf (Python) to
search multiple formats automatically.
Full config loading hierarchy
A production CLI should merge config from all sources in this order:
import { cosmiconfig } from 'cosmiconfig';
import { z } from 'zod';
// 1. Define schema
const ConfigSchema = z.object({
output: z.string().default('dist'),
verbose: z.boolean().default(false),
timeout: z.number().int().positive().default(30000),
plugins: z.array(z.string()).default([]),
});
type Config = z.infer<typeof ConfigSchema>;
// 2. Load and merge
async function resolveConfig(cliFlags: Partial<Config>): Promise<Config> {
const explorer = cosmiconfig('mytool');
const result = await explorer.search();
const merged = {
// Layer 1: hardcoded defaults (handled by zod .default())
// Layer 2: file config
...result?.config,
// Layer 3: environment variables
...(process.env.MYTOOL_OUTPUT ? { output: process.env.MYTOOL_OUTPUT } : {}),
...(process.env.MYTOOL_VERBOSE ? { verbose: process.env.MYTOOL_VERBOSE === 'true' } : {}),
...(process.env.MYTOOL_TIMEOUT ? { timeout: parseInt(process.env.MYTOOL_TIMEOUT, 10) } : {}),
// Layer 4: CLI flags (highest priority)
...Object.fromEntries(
Object.entries(cliFlags).filter(([, v]) => v !== undefined)
),
};
// 3. Validate
const parsed = ConfigSchema.safeParse(merged);
if (!parsed.success) {
console.error('Invalid configuration:');
for (const issue of parsed.error.issues) {
console.error(` ${issue.path.join('.')}: ${issue.message}`);
}
process.exit(2);
}
return parsed.data;
}Environment variable conventions
Follow these naming rules for environment variables:
| Rule | Example | Notes |
|---|---|---|
| Prefix with tool name | MYTOOL_OUTPUT |
Avoids collisions |
| Use SCREAMING_SNAKE_CASE | MYTOOL_API_KEY |
Standard convention |
| Map flag names directly | --output becomes MYTOOL_OUTPUT |
Predictable mapping |
| Boolean values | MYTOOL_VERBOSE=true |
Accept true/1/yes |
| List values | MYTOOL_PLUGINS=a,b,c |
Comma-separated |
Python (click) auto-mapping:
@click.option("--output", envvar="MYTOOL_OUTPUT", default="dist")
@click.option("--verbose", envvar="MYTOOL_VERBOSE", is_flag=True)Rust (clap) auto-mapping:
#[arg(long, env = "MYTOOL_OUTPUT", default_value = "dist")]
output: String,Schema validation
Always validate config files at load time. Report all errors at once rather than failing on the first one.
Node.js (zod):
const parsed = ConfigSchema.safeParse(rawConfig);
if (!parsed.success) {
console.error('Config validation failed:');
for (const issue of parsed.error.issues) {
console.error(` ${issue.path.join('.')}: ${issue.message}`);
}
process.exit(2);
}Python (pydantic):
from pydantic import BaseModel, ValidationError
class Config(BaseModel):
output: str = "dist"
verbose: bool = False
timeout: int = 30000
plugins: list[str] = []
try:
config = Config(**raw_config)
except ValidationError as e:
for err in e.errors():
click.echo(f" {'.'.join(str(l) for l in err['loc'])}: {err['msg']}", err=True)
raise SystemExit(2)Config migration
When the config schema changes between versions, provide an automatic migration path.
interface Migration {
from: string; // semver range
to: string;
migrate: (config: Record<string, unknown>) => Record<string, unknown>;
}
const migrations: Migration[] = [
{
from: '1.x',
to: '2.0.0',
migrate: (config) => {
// Renamed "outDir" to "output" in v2
if ('outDir' in config) {
config.output = config.outDir;
delete config.outDir;
}
return config;
},
},
];
function migrateConfig(
config: Record<string, unknown>,
fromVersion: string
): Record<string, unknown> {
let current = config;
for (const m of migrations) {
if (satisfies(fromVersion, m.from)) {
console.error(`Migrating config from ${m.from} to ${m.to}...`);
current = m.migrate(current);
}
}
return current;
}Config file creation / init command
Provide a init or config subcommand that creates a config file
interactively or with sensible defaults.
program
.command('init')
.description('Create a configuration file')
.option('--format <format>', 'config format (json, yaml, toml)', 'json')
.action(async (options) => {
const configPath = `.mytoolrc.${options.format}`;
if (existsSync(configPath)) {
console.error(`Error: ${configPath} already exists.`);
process.exit(1);
}
const defaults = {
output: 'dist',
verbose: false,
plugins: [],
};
const content = options.format === 'json'
? JSON.stringify(defaults, null, 2)
: options.format === 'yaml'
? dumpYaml(defaults)
: dumpToml(defaults);
writeFileSync(configPath, content + '\n');
console.log(`Created ${configPath}`);
});Platform-specific config paths
| Platform | Config location | Notes |
|---|---|---|
| Linux | ~/.config/mytool/config.json |
XDG_CONFIG_HOME |
| macOS | ~/Library/Application Support/mytool/config.json |
Or XDG if set |
| Windows | %APPDATA%\mytool\config.json |
APPDATA env var |
Use a library like env-paths (Node.js) or dirs (Rust) to resolve
platform-specific paths automatically:
import envPaths from 'env-paths';
const paths = envPaths('mytool', { suffix: '' });
// paths.config -> platform-appropriate config dir
// paths.data -> platform-appropriate data dir
// paths.cache -> platform-appropriate cache diruse dirs::config_dir;
let config = config_dir().unwrap().join("mytool").join("config.toml"); Frequently Asked Questions
What is cli-design?
Use this skill when building command-line interfaces, designing CLI argument parsers, writing help text, adding interactive prompts, managing config files, or distributing CLI tools. Triggers on argument parsing, subcommands, flags, positional arguments, stdin/stdout piping, shell completions, interactive menus, dotfile configuration, and packaging CLIs as npm/pip/cargo/go binaries.
How do I install cli-design?
Run npx skills add AbsolutelySkilled/AbsolutelySkilled --skill cli-design in your terminal. The skill will be immediately available in your AI coding agent.
What AI agents support cli-design?
cli-design works with claude-code, gemini-cli, openai-codex. Install it once and use it across any supported AI coding agent.