# yargs — card for AI agents

Command-line argument parsing for Node.js with automatic help and usage generation.

Category: Dev workflow and config · npm package `yargs` · latest version 18.2.0 (checked 2026-11-01)
Install: `npm install yargs`
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: 71.4 (#329 of all tools, 27 of 299 in its category)
- Used in 32 public projects set up for AI coding agents (0.5%)
- Downloads last week: 393,206,605 (as of 2026-11-24), +42.6% over 4 weeks
- GitHub stars: 11,508 (as of 2026-11-24)
- Last push: 2026-11-17

## Often used with
tsx 50.0%, chalk 31.2%, TypeScript 81.2%, ESLint 62.5%, dotenv 40.6%, Vitest 46.9%

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

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


## yargs: options, help and errors for command-line tools

yargs is a free JavaScript package for Node.js that reads the words typed after a command, such as --port 8080. You list your options once; yargs turns what the person typed into named values, prints a help screen and reports typos. It can also read chat-bot commands, not only terminal input.

### Where to use it
- Flags for your project scripts: The build, import or seed script your AI assistant writes gets --port, --open or --dry-run flags with defaults, so you change behaviour without editing code.
- Slash commands in a chat bot: Your Slack or Discord bot reads messages like "resize cat.jpg -w 640" and answers with the help text or a clear error when the message is wrong.
- Catch typos in options: A mistyped option such as --widht stops the tool with a clear message instead of being quietly ignored.
- Check values before the work starts: Stop the tool early when a value makes no sense, such as a port that is not a number, with your own message.
- Settings from environment variables: On a server, the same options can come from settings such as MY_PROGRAM_FRUIT_THING instead of typed flags.
- Tab completion in the terminal: People who use your tool press Tab to finish command and option names in bash, zsh or fish.

### How to start
- Add yargs to your Node.js project (Node.js 20.19+, 22.12+ or 23+ for version 18).

```
npm i yargs
```

- Parse what was typed after the script name; hideBin drops the first two entries of process.argv for you.

```
import yargs from 'yargs';
import {hideBin} from 'yargs/helpers';
const argv = yargs(hideBin(process.argv)).parse();
```


### License
Free to use, also in paid and closed-source products, under the MIT license. Keep the copyright and license notice when you pass its files on.

### Good to know
- Version 18 needs Node.js 20.19 or newer (or 22.12 or newer on the 22 line) and is built for ES modules first.
- Version 18 removed the old shortcut yargs.argv that many older examples still use.
- By default yargs ends the program after printing help, the version or an error; turn that off inside servers and bots.
- The browser version loads two helper files from unpkg.com when the page runs.
- The project is active; version 18.2.0 came out on 2026-09-20 and added fish shell completion.

Checked 2026-11-10 against: https://yargs.js.org/, https://github.com/yargs/yargs/blob/main/README.md, https://github.com/yargs/yargs/blob/main/docs/api.md, https://github.com/yargs/yargs/blob/main/docs/tricks.md, https://github.com/yargs/yargs/blob/main/docs/browser.md, https://github.com/yargs/yargs/blob/main/CHANGELOG.md, https://github.com/yargs/yargs/blob/main/LICENSE, https://github.com/yargs/yargs/blob/main/lib/platform-shims/browser.mjs, https://registry.npmjs.org/yargs, https://registry.npmjs.org/yargs/18.2.0

### Mistakes to avoid
- Don't: const argv = require('yargs').argv (yargs 17 and older examples) → Do: import yargs from 'yargs'; import {hideBin} from 'yargs/helpers'; const argv = yargs(hideBin(process.argv)).parse() (yargs 18 is ES modules first and removed the global yargs.argv shortcut.)
- Don't: Installing yargs 18 on Node.js 18 or 20.0-20.18 → Do: Use Node.js 20.19+ or 22.12+, or stay on yargs 17.7.x for older Node.js (Version 18 raised the minimum Node.js versions.)
- Don't: Leaving out .strict(), so --widht 640 is quietly accepted → Do: Add .strict() (or .strictOptions()) so unknown options are reported as errors (Without it, a mistyped option just becomes an extra value; in our run .strict() turned it into "Unknown argument widht".)
- Don't: Trusting type: 'number' to reject text such as --port eighty → Do: Add .check(argv => Number.isInteger(argv.port) || 'port must be a whole number') (In our run --port eighty gave NaN with no error; only the .check() rule stopped it.)
- Don't: import Yargs from 'https://unpkg.com/yargs@…/browser.mjs' in a production web page → Do: Bundle yargs/browser with your build tool, or map the two unpkg.com addresses it imports to local copies (The browser entry imports cliui and yargs-parser straight from unpkg.com at run time.)

### Questions
- Can I still use require('yargs') and yargs.argv from old examples? Not as before. Version 18 is ES modules first and removed the yargs.argv shortcut; use import and yargs(hideBin(process.argv)).parse().
- Does it work outside the terminal? Yes. Pass the text to parse() with a callback and yargs returns the values and any help or error text instead of printing it, which suits chat bots.
- Does it come with TypeScript types? The types live in the separate @types/yargs package.
- Which value wins if a setting comes from both a flag and an environment variable? The typed flag wins, then the environment variable, then a config file, then the default.
- Can I use it in a paid product? Yes. It is MIT licensed; keep the license notice with its files.

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