/library / template-cli-tool-typescript
templateTooling

TypeScript CLI tool (zero-build, ESM, single file)

A small TypeScript CLI you can run with `npx your-tool` or install globally. tsx for zero-build dev, commander for arg parsing, kleur for color, ora for spinners. Publishes to npm in two commands.

use whenInternal devtool, project scaffolder, one-off automation, or a public CLI you want to ship without fighting with bundlers.

April 28, 20261,980 bytesclitypescriptnpmtsx

[Tool Name]

A small TypeScript CLI. Installs from npm, runs anywhere Node 22+ runs.

Source of truth

GitHub. Published to npm under your scope (@yourname/your-tool). Every release is a git tag plus an npm publish.

Tech stack

Node 22 + TypeScript + tsx (for dev; ships compiled to ESM in dist/). commander for arg parsing. kleur for colors (small, no deps). ora for spinners. prompts for interactive input. execa for spawning subprocesses. Tests via Vitest.

Deploy

  • Local dev: npm run dev -- your-args (tsx watches and re-runs)
  • Build: npm run build (tsc -> dist/)
  • Release: npm version patch && npm publish && git push --follow-tags

File map

  • src/cli.ts shebang line, commander setup, command routing
  • src/commands/ one file per subcommand
  • src/lib/ shared helpers (config loader, fs ops)
  • package.json "bin" field pointing at dist/cli.js
  • tsconfig.json ESM + NodeNext + strict
  • vitest.config.ts

.env keys

None at runtime. CLI reads config from ~/.config/yourtool/config.json (xdg-compliant) and CLI flags.

Hard rules

  • Shebang line on src/cli.ts is #!/usr/bin/env node (NOT node22 or any version). Lets users with any modern Node run it.
  • package.json "bin" points at the BUILT file in dist/, not src/.
  • "type": "module" and ESM only. Don't dual-publish CJS in 2026.
  • Every command has a --help example in the description. Test it.
  • Exit codes: 0 on success, 1 on user error, 2 on internal error. Catch unhandled rejections and exit cleanly.
  • No process.cwd() for finding the package root. Use import.meta.url resolution.

Recent significant changes

  • 2026-04-28: Scaffolded. Locked: tsx for dev, plain tsc for build, commander for parsing (yargs is overkill).

Next session: start here

  1. Set name in package.json (scoped is safest: @yourname/tool).
  2. npm init -w for the bin entry, set "bin" mapping.
  3. Implement first command under src/commands/.
  4. npm link locally to test the binary as if installed.
  5. npm publish --access public when ready.

Get the next CLAUDE.md in your inbox.

One new template every week, plus occasional case studies.