# Commander — card for AI agents

Complete Node.js solution for building command-line interfaces with minimal boilerplate.

Category: Dev workflow and config · npm package `commander` · latest version 15.0.0 (checked 2026-11-01)
Install: `npm install commander`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Numbers (AgentGid data)
- Gid Score: 81.6 (#76 of all tools, 6 of 299 in its category)
- Used in 174 public projects set up for AI coding agents (2.8%)
- Downloads last week: 788,288,057 (as of 2026-11-24), +43.7% over 4 weeks
- GitHub stars: 28,466 (as of 2026-11-24)
- Last push: 2026-11-19

## Often used with
chalk 67.2%, tsx 61.5%, Vitest 63.8%, Express 47.1%, Zod 67.8%, dotenv 52.3%

## Links
- AgentGid page: https://agentgid.com/tools/commander/
- Homepage: https://github.com/tj/commander.js#readme
- Repository: https://github.com/tj/commander.js


## Commander: options and help for Node.js command-line tools

Commander is a free JavaScript package for building command-line tools in Node.js. You describe the options your tool takes, and it reads what the person typed, shows a help screen and prints a clear error for wrong input. Your assistant writes less code to turn a script into a proper tool.

### Where to use it
- Turn a script into a tool with help: Your image script gets named options with defaults, and typing --help shows what each one does, without extra code.
- Clear errors for wrong values: When someone types a value your tool does not accept, it stops with a message that lists the allowed values.
- One tool with several commands: Like git, your tool has separate commands such as deploy and logs, each with its own options and help page.
- Read a setting from the environment: A required port or token can come from a flag or, when the flag is missing, from an environment variable; help names that variable.
- Commands that wait for the network: When a command downloads or uploads something, its code can wait for the result before the tool exits.
- Test your tool without quitting: Your tests run the tool with sample input many times in one process and check the errors instead of the test run ending.

### How to start
- Install Commander in a project that runs Node.js 22.12 or newer.

```
npm install commander
```

- Describe the options, call parse(), then read the values with opts().

```
import { program } from 'commander';

program
  .option('--first')
  .option('-s, --separator <char>')
  .argument('<string>');

program.parse();

const options = program.opts();
const limit = options.first ? 1 : undefined;
console.log(program.args[0].split(options.separator, limit));
```

- For anything bigger than a quick script, or for tests, create your own Command object instead of the shared one.

```
import { Command } from 'commander';
const program = new Command();
```


### License
Free for any use, also in paid and closed-source products, under the MIT license. No visible credit is needed; keep the license notice if you ship Commander's own files.

### Good to know
- Version 15 needs Node.js 22.12 or newer and loads only as a modern module. Version 14 still gets security fixes until May 2027.
- It is strict. An unknown option or an extra word the person types stops the tool with an error, unless you allow it.
- After an error, the help or the version, it ends the whole program. In tests or long-running apps, switch that off with exitOverride().
- A new major version comes about every six months, and older ones get only security fixes for 12 months.

Checked 2026-11-10 against: https://github.com/tj/commander.js/blob/master/Readme.md, https://github.com/tj/commander.js/blob/master/LICENSE, https://github.com/tj/commander.js/blob/master/CHANGELOG.md, https://github.com/tj/commander.js/blob/master/docs/release-policy.md, https://github.com/tj/commander.js/releases/tag/v15.0.0, https://github.com/tj/commander.js/releases/tag/v15.1.0, https://registry.npmjs.org/commander

### Mistakes to avoid
- Don't: const program = require('commander'); program.option(...) → Do: const { program } = require('commander'), or better import { Command } from 'commander' and new Command() (The default export of a global Command was removed from CommonJS in Commander 12.)
- Don't: import { Command } from 'commander/esm.mjs' → Do: import { Command } from 'commander' (Commander 15 removed the old esm.mjs entry.)
- Don't: program.parse() when an action is an async function → Do: await program.parseAsync(process.argv) (parse() does not wait for async actions, so errors and the end of the work can be lost.)
- Don't: program.parse(['--port', '80']) in a test → Do: program.parse(['--port', '80'], { from: 'user' }) (Without from user, the first two items are treated as the node program and the script name and skipped.)
- Don't: Upgrading an old tool and passing extra words it never declared → Do: Declare every argument, or call .allowExcessArguments() if extra words are expected (Since Commander 13 extra command-arguments are an error by default.)

### Questions
- Can I use it with require() in a CommonJS project? Commander 15 is ESM only, but Node.js 22.12+ can load it from CommonJS. If your test runner or bundler cannot, stay on Commander 14 for now.
- Does it make the --help screen for me? Yes. Help is built from the descriptions you give each option and argument; you can also add your own text.
- How long are old versions supported? Older major versions get security updates for 12 months. Version 14 is supported until 2027-05-29.
- Can options and arguments be checked automatically? Yes. Unknown options, missing arguments and extra arguments are reported as errors when the command runs.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
