cac: a single-file CLI framework for Node and Deno
Simple yet powerful framework for building command-line apps.
At a glance
- What is it?
- cac is a TypeScript command-line framework with four core APIs and no runtime dependencies beyond an inlined argument parser. It suits small to mid-size CLIs that want commander-style ergonomics without the dependency tree.
- Who is it for?
- Adopt cac if you are writing a Node CLI with a handful of commands and want help text, version output and option validation without pulling in a parser dependency. Do not adopt it if you need plugin registration, command discovery from a directory, or a lifecycle of hooks around each command; oclif and commander-plus-plugins target that shape instead.
- Can I use it commercially?
- Check first. The repository uses a licence we do not classify automatically, so read its LICENSE file before any commercial use.
- Is it still maintained?
- Yes. The repository last received commits 2 days ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.
Star history
- cacjs/cac3,151 ★ · +18
| Repository | 2026-09-24 | 2026-11-22 |
|---|---|---|
| cacjs/cac | 3.1k | 3.2k |
18 Stars in the last 59 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The gap cac fills between raw argv and a full CLI toolkit
Parsing process.argv by hand gets ugly fast. You end up writing index arithmetic for flags, a help formatter, a version printer, and validation for required arguments. The README positions cac as the middle ground: a JavaScript library for building CLI apps that stays small enough to read in one sitting. It states there are only four APIs needed for simple CLIs: cli.option, cli.version, cli.help and cli.parse.
The intended audience is a developer who already knows what their commands are. cac does not scan a directory for command modules or load plugins from package.json. You declare commands in code, and the framework handles parsing, bracket semantics, help output and error reporting on unknown options. That is a narrower job than oclif's, and the README does not pretend otherwise. If your CLI is three commands and one config file, the four-API surface is the whole pitch.
How parsing, bracket syntax and command matching fit together
The architecture is a single class instance. You call cac() to create a CLI, register options and commands on it, then call cli.parse() to read the arguments. Option values land in an options object passed to each action. The package.json shows mri 1.2.0 listed under inlinedDependencies, so the underlying argument parser is bundled into the build output rather than installed as a separate package.
Bracket syntax carries the type information. In command names, angled brackets mark required arguments and square brackets mark optional ones. In option names, the same distinction applies to values: --scale [level] can be true when the flag appears alone, while --out <dir> requires a string. The README's deploy example uses both forms in one command. Variadic arguments use the rest-operator spelling: build <entry> [...otherFiles]. The README states that only the last argument can be variadic.
Option names follow a kebab-to-camel rule. --clear-screen and --clearScreen both map to options.clearScreen. Negation is explicit rather than automatic. To let a value be false, you declare both --no-config and --config <path>, and cac sets config to true by default. Dot-nested options merge into a single option, which the README demonstrates with --env.API_SECRET. Repeated flags collect into an array: passing --include twice yields { include: ['project-a', 'project-b'] }.
Command matching also supports a default command, registered by omitting the command name and writing only brackets, as in .command('[...files]', 'Build files'). That command runs when nothing else matches.
Installing cac and building a first command
The README gives one install line. It works with npm, and the repository is set up as a pnpm workspace for its own development, which does not affect consumers.
npm i cacAfter that, the smallest useful program registers one option and parses. The README's basic-usage example creates the CLI, declares --type with a default of node, then prints the parsed result as JSON. Running it with no arguments should show the default applied.
import cac from 'cac'
const cli = cac()
cli.option('--type <type>', 'Choose a project type', {
default: 'node',
})
const parsed = cli.parse()
console.log(JSON.stringify(parsed, null, 2))A more realistic first CLI adds help, version and one command with its own option. The README's command-specific example attaches -r, --recursive to an rm command and reads options.recursive inside the action. Note the argument order in the action signature: the command argument comes first, options last.
import cac from 'cac'
const cli = cac()
cli
.command('rm <dir>', 'Remove a dir')
.option('-r, --recursive', 'Remove recursively')
.action((dir, options) => {
console.log(`remove ${dir}${options.recursive ? ' recursively' : ''}`)
})
cli.help()
cli.parse()Calling cli.help() makes -h and --help print generated usage text, and cli.version('0.0.0') makes -v and --version print the version, which the README notes is also used in the help message. One behavior worth knowing before you ship: a command's options are validated when the command is used, and unknown options are reported as errors. The README adds a caveat that if an action-based command does not define an action, its options are not validated. command.allowUnknownOptions exists for the cases where you want to pass through flags you have not declared.
Where cac stops: no plugin system, no command discovery
The README's feature list is explicit about what cac does: default command, git-like subcommands, validation for required arguments and options, variadic arguments, dot-nested options, automated help generation. What is absent is a plugin registry, a hooks lifecycle, or a convention that turns a directory of files into subcommands. Everything is registered imperatively in one place.
That becomes a limitation at scale. A CLI with forty commands and per-command middleware has to manage all of that wiring itself, and the four-API promise stops being the relevant measure. The README does not document a rollback or undo mechanism for anything, because the library does not own state beyond the parsed options object.
Error handling is the other thin spot. The README shows a global pattern using cli.parse(process.argv, { run: false }) followed by await cli.runMatchedCommand() inside a try block, with a comment that you only need await when your command action returns a Promise. The code block in the README is truncated mid-statement, so the intended catch body is not shown in full. Anyone relying on that pattern should read the tests directory rather than the README for the exact contract.
The engine floor is also a real constraint. package.json declares node >=20.19.0. If you support older Node lines, v7.0.0 will not install cleanly for your users.
cac against commander and oclif
commander is the closest comparison and the one people search for alongside cac. Both use a chained registration style and both generate help text. The difference is packaging philosophy. commander ships its own parser and a broader built-in surface; cac inlines mri and keeps the public API to four methods for simple cases. If you want the smaller dependency footprint and you are comfortable writing your own conventions on top, cac is the leaner choice. If you want a larger set of built-in behaviors without writing them, commander has more of them already.
oclif takes the opposite approach from cac. It is a framework for CLIs that expect many commands, with plugin installation, command discovery and a defined project structure. That is more machinery than a single-purpose tool needs. cac's README describes a library, not a project scaffold, and the repository layout reflects that: src, tests, examples and a tsdown build config, with no command directory convention for consumers to follow.
Maintenance status and what the MIT licence means here
The repository is not archived, and the last push was on 2026-09-18. The most recent release is v7.0.0, published on 2026-02-27, following a beta on 2026-02-20. The prior stable line, v6.7.14, dates from 2022-08-29, so the v7 major is a deliberate break after a long gap rather than a steady release cadence. The maintainers listed in package.json are the original author and Kevin Deng.
Upgrade cost from v6 to v7 is the thing to budget for. The engine field requires Node 20.19.0 or later, and the package is ESM-first with "type": "module" and an exports map pointing at ./dist/index.js. A CommonJS consumer on an older Node line cannot simply bump the version. The README does not include a migration guide, so the release notes for v7.0.0 are the place to look for behavior changes.
The licence is MIT. That permits commercial and closed-source use with the copyright notice retained, but this is a description of the licence identifier, not legal advice. If your organization has rules about bundled third-party code, note that mri is inlined into the distributed build, so its MIT terms travel with the artifact.
Editorial conclusion
Adopt cac if you are writing a Node CLI with a handful of commands and want help text, version output and option validation without pulling in a parser dependency. Do not adopt it if you need plugin registration, command discovery from a directory, or a lifecycle of hooks around each command; oclif and commander-plus-plugins target that shape instead. Before committing, verify the Node engine floor of 20.19.0 against your support matrix, confirm that v7.0.0 is the version your registry serves, and check whether your error handling needs the run:false parse path, since the README's example for it is cut off mid-block.
Frequently asked questions
What does CAC stand for in the cacjs/cac project?
The README expands the name as Command And Conquer, described as a JavaScript library for building CLI apps. It is unrelated to the other common meanings of the acronym.
How do I install cac?
The README gives a single install command, npm i cac. The package requires Node 20.19.0 or later according to its engines field.
Does cac have any runtime dependencies?
The README describes it as having no dependency and being a single file. The package.json lists mri 1.2.0 under inlinedDependencies, meaning the parser is bundled into the build output rather than installed separately.
How does cac handle unknown options on a command?
A command's options are validated when the command is used, and unknown options are reported as an error. The README notes that options are not validated when an action-based command defines no action, and command.allowUnknownOptions exists if you want to accept undeclared flags.
Can cac be used with Deno?
The repository includes examples/deno.ts and lists deno among its topics, and jsr.json is present at the top level of the repository. The README itself does not document a Deno install command.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/cacjs-cac)Star history chart for your README
[](https://hysenlabs.com/projects/cacjs-cac)Was this useful?