Command Palette

Search for a command to run...

YepAPI
Free · All Tools

CLI Tools Agent Skill

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

clicommandertoolsnpm

The Skill

Full content, every format. Copy it, download it, or install with one command.

SKILL.md
---
description: Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.
homepage: https://yepapi.com/skills/cli-tools
metadata:
  tags: [cli, commander, tools, npm]
---

# CLI Tools

## Rules

- Commander.js for argument parsing — `.command()`, `.option()`, `.argument()` with descriptions
- Interactive prompts: `@clack/prompts` (modern, beautiful) or `inquirer` — for user input when args aren't provided
- Spinners: `ora` for long-running operations — start, update message, succeed/fail
- Colors: `chalk` for styled output — use sparingly: red for errors, green for success, yellow for warnings, dim for secondary info
- Config files: `cosmiconfig` — searches `.toolrc`, `.toolrc.json`, `tool.config.js`, `package.json` key automatically
- Exit codes: `0` for success, `1` for general error, `2` for usage error — always `process.exit(code)`
- `--help` and `--version` flags: Commander adds these automatically — write clear descriptions for every option
- Error handling: catch errors at the top level, print user-friendly message to stderr, exit with code 1
- Publish: `bin` field in `package.json`, `#!/usr/bin/env node` shebang, `"type": "module"` for ESM

## Patterns

\`\`\`ts
#!/usr/bin/env node
import { Command } from "commander";
import * as p from "@clack/prompts";
import ora from "ora";
import chalk from "chalk";

const program = new Command()
  .name("my-tool")
  .description("A CLI that does useful things")
  .version("1.0.0");

program
  .command("init")
  .description("Initialize a new project")
  .option("-t, --template <name>", "template to use", "default")
  .action(async (options) => {
    p.intro(chalk.bold("Project Setup"));

    const name = await p.text({ message: "Project name?", placeholder: "my-app" });
    if (p.isCancel(name)) { p.cancel("Cancelled."); process.exit(0); }

    const spinner = ora("Creating project...").start();
    await createProject(name, options.template);
    spinner.succeed(chalk.green("Project created!"));

    p.outro(`Run ${chalk.cyan(`cd ${name} && npm install`)}`);
  });

program.parse();

// package.json: { "bin": { "my-tool": "./dist/index.js" } }
\`\`\`

## Avoid

- Printing errors to stdout — use `console.error()` or `process.stderr.write()` for errors
- Exiting without a code on failure — always `process.exit(1)` so scripts and CI detect the failure
- Walls of unformatted text — use chalk colors, sections, and whitespace for readability
- Requiring interactive input with no flag alternative — always support `--flag` overrides for CI/scripting
- Forgetting the shebang `#!/usr/bin/env node` — without it, `npx` and global installs won't work

Install

Why Use the CLI Tools Skill?

Without this skill, your AI guesses at cli tools patterns. It might hallucinate deprecated APIs, use outdated conventions, or miss best practices entirely. With it, your AI follows a proven ruleset — every suggestion aligns with current standards.

Drop this skill into your project and your AI instantly knows the rules. Better code suggestions, fewer errors, faster shipping.

Try These Prompts

These prompts work better with the CLI Tools skill installed. Your AI knows the context and writes code that fits.

"Build a CLI tool with Commander.js, interactive prompts, and a spinner for long operations"

"Create a CLI with cosmiconfig for reading config from .rc files, .json, or package.json"

"Set up an npm-publishable CLI with proper bin field, shebang, and exit codes"

CLI Tools skill — FAQ

It provides rules for Commander.js argument parsing, interactive prompts with @clack/prompts, ora spinners, chalk colors, cosmiconfig for config files, proper exit codes, and npm publishing with bin field and shebang.

Run `npx skills add YepAPI/skills --skill cli-tools` in your project root. This copies the skill file into your repo where your AI coding tool can read it automatically.

@clack/prompts provides a modern, beautiful interface with spinner, select, multiselect, and text prompts. It's the recommended choice over inquirer for new projects due to its better DX and visual design.

Want more skills?

Browse all 110 free skills for builders.

See All Skills