Commander vs yargs
Commander vs yargs compared for 2026: Commander 15.1 (ESM only, zero dependencies, strict by default) vs yargs 18.2 (ESM-first, built-in completion and locales, lenient unless you add .strict()). Includes start-up times, typo and bad-input handling, TypeScript inference and install size we measured on the same CLI, plus the Node.js version and ESM changes that affect upgrades.
Quick Answer
Commander and yargs are the two most-downloaded argument parsers for Node.js CLIs, and both handle subcommands, options, defaults, choices, help and version flags. They differ in defaults and weight. Commander 15.1.0 (7 November 2026) has no dependencies, rejects unknown options and extra arguments out of the box, and suggests the right spelling. yargs 18.2.0 (20 September 2026) installs 13 packages, ships 29 locales and generates shell completion scripts, but accepts unknown flags and unknown commands unless you call .strict(). In our runs on 2 December 2026, the same two-command CLI started in a median 40-41 ms with Commander and 105-106 ms with yargs, against 21-22 ms for bare Node.js, and a 50-command CLI kept the same gap. A mistyped command (deploi prod) made Commander print an error with a suggestion; our non-strict yargs program printed nothing and exited 0. Both returned NaN for --port abc until we added validation. Both now need modern Node.js: Commander 15 is ESM only and requires 22.12, yargs 18 requires 20.19 or 22.12 and its 19 alpha drops Node 20. Pick Commander for most CLIs; pick yargs when you want completion, localised messages or config and environment loading built in.
Last updated December 2, 2026. Covers Commander 15.1.0 (7 November 2026) and yargs 18.2.0 (20 September 2026, with 19.0.0-alpha.0 on 28 November); npm registry metadata and download counts, GitHub repositories and release notes, Commander README and release policy, yargs README read on 2 December 2026, plus start-up, install, input-handling, TypeScript, completion and locale runs we did that day.
| Feature | Commander | yargs |
|---|---|---|
| Licence & Repository | MIT; tj/commander.js, ~28.5k stars, 7 open issues | MIT; yargs/yargs, ~11.5k stars, 201 open issues |
| Latest Release | 15.1.0 on 7 Nov 2026 | 18.2.0 on 20 Sep 2026 (19.0.0-alpha.0 on 28 Nov) |
| npm Weekly Downloads (24-30 Nov 2026) | 722,814,469 | 368,073,222 |
| Our Run: Install (packages / size) | 1 package, 252 KB | 13 packages, 1.0 MB |
| Node.js Requirement & Module Format | Node.js >=22.12.0; ESM only (require(esm) from CommonJS) | Node.js ^20.19.0, ^22.12.0 or >=23; ESM-first (import-only exports) |
| Our Run: 2-Command CLI Start-up (median) | 40-41 ms (help 37-42 ms) | 105-106 ms (help 90-96 ms) |
| Our Run: 50-Command CLI Start-up (median) | 43 ms | 101-109 ms |
| Our Run: Import Time / RSS | 13.6-15.8 ms; 43 MB RSS | 58.6-73.1 ms; 53 MB RSS |
| Unknown Option (--prot) | Error with suggestion (Did you mean --port?), exit 1 | Accepted silently; with .strict(): Unknown argument: prot |
| Unknown Command (deploi) | Error with suggestion (Did you mean deploy?), exit 1 | No output, exit 0 (non-strict); with .strict() + recommendCommands(): Did you mean deploy? |
| Extra Positional Arguments | Error: too many arguments, exit 1 | Kept in argv._; with .strict(): Unknown argument |
| Our Run: --port abc | NaN with a Number parser; InvalidArgumentError gives a clean error | NaN with type: number; .check() gives a clean error |
| --dry-run=false | Rejected (use --no-dry-run style options) | Accepted (dryRun: false) |
| Environment Variables | Per option: new Option(...).env('REGION'), shown in help | .env('TOOL') maps TOOL_REGION to --region |
| Shell Completion | Not built in | Bash and Zsh via .completion(); Fish since 18.2.0 |
| Localised Messages | English only | 29 locales via y18n |
| Our Run: TypeScript Inference | Bundled types; extra-typings caught 3 of 3 planted mistakes, plain Command 0 | @types/yargs 17.0.35 caught 2 of 3 (misspelled key allowed) |
| Testing / Exit Control | .exitOverride() throws CommanderError (code, exitCode); configureOutput() | .fail() handler, parseAsync, exitProcess(false) |
| Stand-alone Executable Subcommands | Yes, git-style (tool-deploy) | No; commandDir loads command modules |
| Release Activity & Support Policy | 14.0.3, 15.0.0, 15.1.0 in 2026; v14 security fixes until 29 May 2027 | 16.2.2, 17.7.3, 18.1.0, 18.2.0, 19.0.0-alpha.0 in 2026 |
Commander
Commander.js is the long-standing, minimal CLI framework for Node.js, used by a large share of the npm ecosystem. You build a program with a fluent API: new Command(), .command(), .argument(), .option() and .action(), with Option objects for choices, defaults, environment variables, conflicts and implied values, and hooks such as preAction. By default it is strict: unknown options and excess arguments are errors, with Did you mean suggestions, unless you call .allowUnknownOption() or .allowExcessArguments(). It can also dispatch subcommands to stand-alone executables, git-style. Commander 15.0.0 (29 May 2026) converted the code base to ESM and requires Node.js 22.12 or later, so that CommonJS callers can load it through require(esm); it also changed how a lone --no-* option sets defaults. 15.1.0 (7 November 2026) is a fix release that also deprecates storeOptionsAsProperties() and combineFlagAndOptionalValue(). The release policy keeps Commander 14 on security updates until 29 May 2027. Types ship with the package, and the optional @commander-js/extra-typings package infers option and argument types from your definitions.
Pros
- Zero dependencies: one package and 252 KB in node_modules, against 13 packages and 1.0 MB for yargs
- Fast start-up: a median 40-41 ms for our two-command CLI against 105-106 ms for yargs (bare Node.js 21-22 ms)
- Strict by default: unknown options, unknown commands and extra arguments are errors, with spelling suggestions
- With @commander-js/extra-typings, TypeScript inferred port as number and flagged a misspelled option name
- Clear support policy: majors about every six months, previous major on security fixes for 12 months
- Clean result objects: options only, camelCased, no alias duplicates
Cons
- No shell completion generator and no built-in message translation (errors printed in English with LC_ALL=de_DE.UTF-8)
- Commander 15 needs Node.js 22.12 or later; tools that cannot load ESM from CommonJS have to stay on 14
- Plain .opts() is typed as a loose record; real type inference needs the separate extra-typings package
- Rejects --flag=false for boolean flags (error: unknown option '--dry-run=false'); you define a --no-flag instead
- No built-in config-file loading; you read and merge files yourself
Best For
Most Node.js CLIs, especially small tools and npx-style commands where start-up time, dependency count and strict input checking matter.
yargs
yargs is a full-featured argument parser built on yargs-parser. You describe commands with .command(name, description, builder, handler), options with typed objects (type, alias, choices, default, demandOption), and add behaviour through middleware, .check(), .coerce(), .config() for JSON config files and .env(prefix) for environment variables. It generates help with types and defaults, translates its own messages through y18n (29 locale files ship with 18.2.0), and produces Bash and Zsh completion scripts through .completion(), with Fish support added in 18.2.0. By default it is permissive: unknown options are passed through on argv, and .strict(), .strictCommands() and .recommendCommands() turn on checking and suggestions. yargs 18.0.0 (May 2025) made the package ESM-first, removed the yargs.argv singleton and requires Node.js 20.19, 22.12 or newer. 18.1.0 (July 2026) fixed a local prototype pollution issue in apply-extends, 18.2.0 added Fish completion, and maintenance releases 17.7.3 and 16.2.2 followed in June 2026. 19.0.0-alpha.0 (28 November 2026) drops Node.js 20 and makes the factory read process arguments by default.
Pros
- Shell completion built in: .completion() emitted a 30-line Bash script and a #compdef Zsh script for our CLI
- Localised output: with LC_ALL=de_DE.UTF-8 the missing-command error came out in German
- Config files and prefixed environment variables in one call each (.config(), .env('TOOL'))
- Accepts --dry-run=false and other key=value boolean forms
- Rich validation and middleware hooks (.check, .coerce, middleware) for larger CLIs
- Still maintains older majors: 17.7.3 and 16.2.2 shipped in June 2026
Cons
- Lenient by default: --prot 80 was accepted as a new key and a mistyped command printed nothing and exited 0 in our non-strict program
- Slower start-up: a median 105-106 ms for our two-command CLI, about 65 ms more than Commander
- 13 packages in node_modules (cliui, string-width, y18n and others) against Commander's single package
- Types come from @types/yargs 17.0.35, which did not flag a misspelled option name on argv
- argv carries every alias and both kebab and camel spellings (p, port, dry-run, dryRun), which clutters spreading it into config
Best For
Larger, user-facing CLIs that want shell completion, translated messages, config files and environment loading without extra libraries, and teams willing to turn on .strict().
Same job, opposite defaults
Both libraries turn process.argv into commands, options and positional arguments, generate --help and --version, and support defaults, choices, required options, variadic values and async handlers through parseAsync. The real difference is what happens when the user gets it wrong. Commander treats the CLI definition as a contract. In our two-command test program, --prot 80 produced error: unknown option '--prot' (Did you mean --port?), deploi prod produced error: unknown command 'deploi' (Did you mean deploy?), and an extra positional argument produced too many arguments for 'deploy', each with exit code 1. yargs treats argv as open-ended. The same program without .strict() accepted --prot as a new key next to port's default of 3000, kept the extra argument in argv._, and, for deploi prod, printed nothing at all and exited 0, because .demandCommand(1) only counts that a command-like word was given. Adding .strict() and .recommendCommands() brought yargs to parity: Unknown argument: prot, Unknown argument: extra, and Did you mean deploy? with exit 1. Commander can be loosened the other way with .allowUnknownOption() and .allowExcessArguments(). The defaults matter because they are what ships when nobody remembers to change them.
What we measured: start-up, install and memory
On 2 December 2026 we built the same CLI with Commander 15.1.0 and yargs 18.2.0 on Node.js 22.23.5 in a 2-vCPU sandbox: a deploy <env> command with --port (number, default 3000), --dry-run, repeatable --tag, --region with choices and --no-color, plus a logs command. Each command was run 15 times pinned to one core, two rounds. Bare node -e 0 took a median 21-22 ms. Running deploy prod -p 8080 -t a b took 40-41 ms with Commander and 105-106 ms with yargs; --help took 37-42 ms against 90-96 ms. A generated 50-command CLI took 43 ms with Commander and 101-109 ms with yargs, so the cost is mostly loading the library, not registering commands. Importing the module alone took 13.6-15.8 ms with 43 MB resident memory for Commander, against 58.6-73.1 ms and 53 MB for yargs. Installing into an empty project gave one package and 252 KB for Commander and 13 packages and 1.0 MB for yargs: cliui, string-width, strip-ansi, wrap-ansi, y18n, yargs-parser, escalade, get-caller-file and their helpers. Sixty-odd milliseconds will not matter for a long-running dev server, but it is visible in a git hook, a shell prompt helper or anything run many times in a script.
Input handling: numbers, booleans and environment variables
Neither library validates numbers for you by default. With Commander's option('-p, --port <n>', 'port', v => Number(v), 3000) and yargs' type: 'number', --port abc reached the handler as NaN in both. --port 08 became 8 and --port -5 became -5 in both, and repeated -t a -t b collected an array in both. The clean fixes differ: in Commander, throw InvalidArgumentError from the parser and the user sees option '--port <n>' argument 'abc' is invalid. Not a number.; in yargs, add .check() and the fail handler gets port must be a number. Choices are validated by both: --region asia was rejected with the allowed values listed. Booleans diverge: yargs accepted --dry-run=false as dryRun: false, while Commander rejected it as an unknown option, because its booleans are presence flags and negation is a separate --no-dry-run option. --no-color worked in both. Environment variables are per option in Commander, new Option('--region <r>').env('REGION'), and the variable appears in help; yargs maps a prefix for all options at once with .env('TOOL'), so TOOL_REGION=us set region. That convenience has the same NaN gap: TOOL_PORT=abc gave NaN without a check. Finally, yargs puts every alias and both spellings on argv (p, port, dry-run, dryRun); Commander's opts() contains each option once, camelCased.
TypeScript, testing and module format
Commander ships its own typings, but plain .opts() is a loose record, so assigning the port option to a string compiled without complaint in our tsc 6.0.3 strict test. Importing Command from @commander-js/extra-typings 15.1.0 instead inferred { port: number; dryRun?: true } and caught all three planted mistakes, including reading a misspelled o.prot. yargs 18 does not ship types for its main entry point, only browser.d.ts, so TypeScript uses @types/yargs 17.0.35. It inferred port as number and dryRun as boolean | undefined, catching two mistakes, but argv.prot compiled because argv allows any string key. For tests, Commander's .exitOverride() makes parse errors throw a CommanderError (we got code commander.unknownOption, exitCode 1) and configureOutput() captures output; yargs uses a .fail() callback and parseAsync. Async handler rejections surfaced through parseAsync in both. Module format is the upgrade trap. Commander 15 is ESM only and requires Node.js 22.12 for require(esm); yargs 18 exports only an import entry point. On Node.js 22.23.5, require('commander') and require('yargs') both worked from a CommonJS file, but bundlers, test runners or older runtimes that cannot load ESM from CommonJS will fail. Commander's 15.0.0 notes suggest staying on 14 if that bites.
Limits and alternatives
Commander's minimalism has costs. There is no completion generator, so tab completion means a third-party package or a hand-written script, and messages are English only: with LC_ALL=de_DE.UTF-8 Commander still printed error: missing required argument 'env' while yargs printed Nicht genügend Argumente ohne Optionen. There is no config-file loader. yargs covers those, plus middleware and commandDir for loading command modules, but you carry 13 packages and a slower start, and its permissive defaults need switching off. Both are evolving: yargs 19.0.0-alpha.0 drops Node.js 20 and changes the factory to read process arguments by default, which will make hideBin(process.argv) unnecessary but is a breaking change; Commander deprecated storeOptionsAsProperties() in 15.1.0. Our timings come from one sandbox and a small synthetic CLI; real CLIs that import heavy dependencies will be dominated by those. If you need neither subcommand help nor validation, Node.js's built-in util.parseArgs (present in the Node.js 22.23.5 we tested) covers simple flag parsing with no dependency at all. For Python CLIs the same trade-off appears in Click vs Typer; for running TypeScript CLIs during development, see tsx vs ts-node, and for runtime choice, Bun vs Node.js.
Verdict
Pick Commander for most Node.js CLIs. It installs one package, started our CLI in well under half yargs' time, and its strict defaults caught every typo and extra argument we tried, with suggestions, without any configuration. Add @commander-js/extra-typings if you write TypeScript, and validate numbers with InvalidArgumentError, since a bare Number parser lets NaN through. Pick yargs when the CLI is large and user-facing and you want shell completion, translated messages, config files or prefixed environment variables without writing them yourself, and when key=value booleans must work. If you choose yargs, call .strict() (and .recommendCommands()) from day one: in our test a mistyped command did nothing and exited 0 without it. Check your Node.js floor before upgrading either one. Commander 15 needs 22.12 and is ESM only, so stay on Commander 14 (security fixes until 29 May 2027) if your runtime or test tooling cannot load ESM from CommonJS; yargs 18 still supports Node.js 20.19, but its 19 alpha drops 20.

