# yargs-parser — card for AI agents

Powerful command-line argument parser for Node.js CLIs.

Category: Dev workflow and config · npm package `yargs-parser` · latest version 22.0.0 (checked 2026-11-01)
Install: `npm install yargs-parser`
License: ISC (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: 48.4 (#2165 of all tools, 160 of 299 in its category)
- Used in 3 public projects set up for AI coding agents (0.0%)
- Downloads last week: 394,038,993 (as of 2026-11-24), +42.6% over 4 weeks
- GitHub stars: 520 (as of 2026-11-24)
- Last push: 2026-11-17

## Often used with
tsx 66.7%, Prettier 66.7%, Vitest 66.7%, js-yaml 50.0%, yaml 50.0%, yargs 50.0%

## Checked alternatives (same job)
- Commander: https://agentgid.com/tools/commander/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/yargs-parser/
- Homepage: https://github.com/yargs/yargs-parser#readme
- Repository: https://github.com/yargs/yargs-parser


## yargs-parser: turn typed command options into values

yargs-parser is a small free JavaScript library that reads options typed after a command, like "--width 1200 --dry-run", and gives your code ready values. Numbers become numbers, on-off switches become true or false, and other words are kept in a list. It is the part of the yargs toolkit that only reads options; it does not print help or check for mistakes.

### Where to use it
- Options for your own script: You have a small Node.js script that resizes photos or cleans a folder. It reads "-w 1200 --dry-run" without you splitting the text by hand.
- Commands typed in a chat box: A team chat bot or a web console gets "/deploy --env staging --force" as one line of text and needs the parts as values.
- A command box in a web page: A tutorial site or an in-browser playground lets visitors type options, and the page reads them without a server.
- Quiet, normal or chatty output: Your tool prints more detail with -v and even more with -vvv; the library counts the letters for you.
- Pass extra words to another program: A wrapper script keeps everything after "--" untouched and hands it to the program it starts, like a test runner.

### How to start
- Add the package to your project.

```
npm i yargs-parser --save
```

- Pass it the words after your command, or one string, and read the result.

```
const argv = require('yargs-parser')(process.argv.slice(2))
console.log(argv)
```

- Tell it which options are numbers, switches, lists or text, and give defaults.

```
import parser from 'yargs-parser'

const argv = parser('--foo=99 --bar=9987930', {
  string: ['bar']
})
```


### License
Free to use for any purpose, also in paid products, under the ISC license. Keep the short copyright and permission notice with copies of its code.

### Good to know
- It only reads options. Help text, required options and error messages for typos are in the full yargs package.
- An option you did not list is still accepted. In our run a misspelled "--output-dir" became a new value instead of an error.
- Version 22 needs Node.js 20.19 or 22.12 and newer; projects on older Node.js stay on version 21.
- The last release, 22.0.0, came out in May 2025; the project is still in use and its code is still being updated.
- In a web page it cannot load settings from files; that part works only in Node.js.

Checked 2026-11-10 against: https://github.com/yargs/yargs-parser/blob/main/README.md, https://github.com/yargs/yargs-parser/blob/main/CHANGELOG.md, https://github.com/yargs/yargs-parser/blob/main/LICENSE.txt, https://github.com/yargs/yargs-parser/blob/main/package.json, https://github.com/yargs/yargs-parser/blob/main/browser.js, https://registry.npmjs.org/yargs-parser, https://registry.npmjs.org/yargs-parser/22.0.0

### Mistakes to avoid
- Don't: require('yargs-parser') with yargs-parser 22 on Node.js 18 or 20.0-20.18 → Do: Upgrade to Node.js 20.19+ or 22.12+, or pin yargs-parser@21.1.1 on older Node.js (Version 22 is published as an ES module only and lists those Node.js versions as its minimum.)
- Don't: array: ['format'] and then shrink --format webp avif photo.jpg → Do: Put files first, or set configuration: { 'greedy-arrays': false } so a list takes one word per flag (A list option keeps taking the following words; in our run photo.jpg ended up inside format.)
- Don't: Counting on it to reject unknown or misspelled options → Do: Check argv against your own list of allowed keys, or use yargs' strict mode for real validation (Unknown options are accepted as new keys; in our run --output-dir became outputDir with no error.)
- Don't: parse(['-f', 11, '--zoom', 55]) with numbers in the list → Do: parse(['-f', 11, '--zoom', 55].map(String)), or join the list into one string (The README asks for strings; convert mixed values before you pass them.)
- Don't: Reading parser(...) result only and missing that an option needed more words → Do: Use parser.detailed(args, opts) and check its error field (The plain call returns values only; detailed() also returns the error, as in our run with narg.)

### Questions
- Does it print a --help screen? No. It only turns the typed words into values; yargs, which is built on it, adds help and usage text.
- Can I give it one string instead of a list of words? Yes. It takes a string or a list of strings.
- Does --no-color work? Yes. By default an option that starts with --no- is read as that option set to false.
- Does it work in the browser? Yes, through its browser entry, since version 19. Loading settings from files is not supported there.
- Can I use it in a paid product? Yes. The ISC license allows any use with or without a fee; keep the notice in copies.

---
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.
