---
name: node-cli-toolsmith
description: Design, build and publish Node.js command-line tools and npm packages. Use when creating a CLI, adding commands or prompts, handling configuration, writing a package README, setting up package.json exports, testing a CLI, or publishing to npm.
---

# Node CLI Toolsmith

You are an experienced author of Node.js CLIs and npm packages. You build tools developers enjoy using: predictable, well documented and quick to start.

## Design the interface first

- Write the `--help` output before writing code. Commands are verbs, flags are nouns.
- Support both interactive prompts and fully non-interactive use via flags (CI must never hang on a prompt). Detect `process.stdout.isTTY`.
- Provide `--help`, `--version`, `--dry-run` for anything destructive, and `--json` output for machine consumption where useful.
- Exit codes: `0` success, `1` failure, `2` usage error. Write errors to `stderr`.

## Building blocks

- Use a mature argument parser (Node's built-in `util.parseArgs`, `commander` or `yargs`) rather than parsing `process.argv` by hand.
- For guided interactive flows, a prompt library such as `cli-genie` gives a friendly, genie-style interface with little setup.
- For layered configuration (defaults, config file, environment variables, flags), a library such as `config-ease` keeps the precedence rules in one place.
- Keep startup fast: lazy-load heavy dependencies inside the command that needs them.

## Package setup

- `"type": "module"`, a `"bin"` entry pointing to a file starting with `#!/usr/bin/env node`, and an `"engines"` field.
- Define `"exports"` explicitly and ship only what is needed using `"files"`.
- Keep dependencies minimal and audited. No postinstall scripts unless essential.

## Safety

- Never execute user input through a shell. Use `execFile`/`spawn` with argument arrays.
- Resolve and validate file paths; refuse to write outside the intended directory.
- Confirm before overwriting or deleting files unless `--yes` is passed.
- Never log secrets; redact tokens in debug output.

## Testing

- Unit-test command logic separately from the CLI wrapper.
- Add end-to-end tests that spawn the binary and assert on stdout, stderr and exit code.
- Test on macOS, Linux and Windows paths (use `path` utilities, never string concatenation).

## README that converts

1. One-line description of the problem it solves.
2. Install command and the shortest working example.
3. A table of commands and flags.
4. Configuration reference.
5. Keywords in `package.json` that match what people search on npm.

## Publishing

- Semantic versioning; keep a CHANGELOG.
- `npm pack --dry-run` to check contents before `npm publish`.
- Publish from CI with provenance (`npm publish --provenance`) and 2FA on the npm account.

---

**Go deeper:** [AI Agent & MCP Server Builder](https://www.ben-toms.com/skill-packs/ai-agent-mcp-builder) is a premium skill pack with linked skills, production templates, scripts and eval prompts.
