Package CLI for npm/brew distribution
✓Works with OpenClaudeYou are a CLI packaging expert. The user wants to package a Node.js CLI application for distribution via npm and Homebrew.
What to check first
- Run
npm list -gto verify no conflicting global packages exist - Check that
package.jsonhas"bin"field defined with entry point - Confirm the CLI entry file has
#!/usr/bin/env nodeshebang at the top - Verify
package.jsonhas"preferGlobal": trueor"type": "module"set appropriately
Steps
- Add the
binfield topackage.jsonmapping command name to executable file:"bin": { "mycli": "./bin/cli.js" } - Make the CLI entry file executable with
chmod +x bin/cli.js - Test locally with
npm linkto simulate global installation, then run the command by name - Set
"files"array inpackage.jsonto include onlybin/,lib/, andREADME.mdto reduce package size - Create
.npmignoreto exclude test files,.git, and development dependencies from npm tarball - Run
npm packto generate a.tgzfile and verify contents withtar -tzf package-name.tgz - Publish to npm with
npm publish --access public(add--access restrictedfor scoped packages) - Create a Homebrew formula file at
Formula/mycli.rbwith SHA256 hash of the npm tarball URL - Test Homebrew installation locally with
brew install --build-from-source ./Formula/mycli.rb
Code
// package.json - minimal working configuration
{
"name": "mycli",
"version": "1.0.0",
"description": "A powerful CLI tool",
"main": "lib/index.js",
"bin": {
"mycli": "./bin/cli.js"
},
"preferGlobal": true,
"files": [
"bin",
"lib",
"README.md"
],
"engines": {
"node": ">=14.0.0"
},
"keywords": ["cli", "tool"],
"author": "Your Name",
"license": "MIT",
"dependencies": {
"yargs": "^17.0.0",
"chalk": "^4.1.0"
}
}
#!/usr/bin/env node
// bin/cli.js - entry point
const yargs = require('yargs');
const chalk = require('chalk');
const { version } = require('../package.json');
yargs
.scriptName('mycli')
.version('v' + version)
.command(
'greet <name>',
'Greet someone',
(yargs) => y
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related CLI Tools Skills
Other Claude Code skills in the same category — free to download.
CLI App Builder
Build CLI applications with Commander.js
Interactive CLI
Create interactive CLI prompts (Inquirer.js)
CLI Progress Bar
Add progress bars and spinners to CLI
CLI Config Manager
Build CLI configuration management
CLI Help Generator
Generate help text and man pages
CLI Testing
Test CLI applications
CLI Autocomplete
Add shell autocompletion to CLI tools
CLI Color Output
Add colored and formatted CLI output
Want a CLI Tools skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.