How to Build a CLI Tool Developers Actually Enjoy Using

Most command line tools fail in the same quiet way. They work, but nobody reaches for them twice. The flags are hard to remember, the output is noisy, and the first error reads like a stack trace. If you want to build a CLI tool that developers actually enjoy using, start from the experience of typing the command, not from the language you plan to write it in.

A good CLI feels like a short conversation. You ask for one thing, it does that thing, and it tells you what happened in plain language. Every choice in this guide comes back to that test.

How to build a cli tool around one job

Every tool people love does one job well before it does anything else. The Unix tools survived for decades because grep searches, curl fetches, and jq filters. They did not try to become platforms on day one.

Before you write code, write the sentence your tool completes. “I run deploy and my site goes live.” “I run backup and my database lands in safe storage.” If you cannot finish that sentence in one line, the scope is too wide. Cut it until you can.

Then list the three commands a user will run in the first week. Build those first and make them solid. A tool with three commands that work every time beats a tool with thirty commands that half work.

Pick a name that is short, easy to type, and easy to say out loud. Two syllables is a good target. Check that the name does not clash with a common command on Linux or macOS, and that it is not already taken in the package registry you plan to use. Renaming a tool after people have scripts that call it is painful.

Design commands that read like sentences

Good CLI tool design starts with verbs. Commands should read like instructions: app deploy, app backup create, app user invite. Nouns first, verbs second, and the order stays the same across the whole tool. When users can guess the next command, they stop reading the docs.

Keep the nesting shallow. One level of subcommand is usually enough. Two levels is acceptable for a large tool. Three levels means users need a map, and they will not carry one.

Use the same flag names other tools use. --output for a file path, --format for json or table, --dry-run for a preview, --verbose for extra detail. Inventing a clever synonym for a standard flag only buys confusion. These are command line interface best practices that hold up across languages and ecosystems: people bring habits from every other tool they use, so match those habits.

Short flags are fine for the two or three options people use constantly, such as -f for force or -o for output. Give every other flag a clear long form and let users type it.

Flags, defaults, and config files

Defaults decide whether your tool feels friendly or hostile. A sensible default lets a new user run the tool with no flags at all and get a useful result. Ask yourself what happens when someone types the bare command. If the answer is an error asking for six required flags, the defaults are wrong.

Required flags should be rare. Each one is a question the user must answer before they get any value. Where a value has an obvious answer, fill it in: the current directory for the working path, the project file in the current folder for the target.

Config files belong in a predictable place and follow a clear order of priority. Command line flags beat environment variables, which beat the config file, which beats the built-in default. Write that order in your help text so users can reason about it.

Secrets deserve special care. Never ask users to paste a token into a config file in plain text and call it done. Point them at a proper secret store or an environment variable, and warn when a key looks like it was committed to a repository. Our comparison of secret storage options for developers covers the trade-offs between a vault, a password manager CLI, and encrypted files.

Output, errors, and help text

Output is the part users see most, so design it first and code it second. The default output should be short, readable, and easy to scan. Show the result, then one line of context if it matters. Save the detail for --verbose and the machine-readable format for --format json. A tool that prints a wall of text for a simple success has failed at its main job.

Follow the old Unix rule: silence means success. When a command works, print a short confirmation or nothing at all. When it fails, say so loudly. Reserve stderr for errors and warnings, and keep stdout clean so users can pipe it into other tools.

Good cli error messages name the problem, name the fix, and point at the exact thing that went wrong. Compare these two:

$ app deploy
Error: invalid input

$ app deploy
Error: config file ./app.yaml is missing the "region" field.
Fix: add region: us-east-1, or run: app init --region us-east-1

The first one leaves the user guessing. The second one tells them what is missing, where it is missing, and the exact command that fixes it. Write every error message as if the reader is tired, in a hurry, and has never seen your code. Because usually they are.

Exit codes matter too. Use 0 for success, 1 for a general error, and 2 for bad usage such as a missing argument. Scripts depend on these codes, so never return 0 when the command failed.

Help text is part of the product, not an afterthought. Good cli help text shows one example for each common task, right next to the command it explains. Run --help on every command yourself before each release and read it as a stranger would.

Test it like a stranger will use it

Developers test their own tools with full knowledge of how they work, which hides the rough edges. Hand the tool to someone who has never seen it and watch them use it without helping. Note every place they pause, mistype, or ask a question. Those pauses are your real bug list.

Automate the boring checks. A test suite for a CLI should cover the happy path, the common mistakes, and the exit codes. Run the tool with no arguments, with a bad flag, with a missing file, and with a slow network. Each of these should produce a clear message and the right exit code.

Test on a clean machine, or at least in a fresh container, before every release. Your laptop has environment variables, config files, and cached credentials that your users do not have. The same habit applies to server tools: if you manage containers from the terminal, our comparison of Portainer and the command line for Docker shows where a CLI earns its keep and where a dashboard is the better choice.

Ship it, then keep it boring

Distribution is where many side projects stall. Pick one install method and make it smooth: a package manager your audience already uses, a single binary download, or a one-line install script. Document the uninstall steps too. Users trust a tool more when they know they can remove it cleanly.

Version your releases and write a short changelog for each one. When a command changes behavior, say so plainly and give the old behavior a deprecation warning for at least one release before removing it. People build scripts around your tool, and a silent breaking change will break their morning.

Keep the tool fast to start. A CLI that takes two seconds to print help feels broken, even if the work it does takes longer. Slow startup usually comes from loading too much at import time. Defer heavy imports until the command that needs them actually runs.

Finally, resist the urge to keep adding features. Every new flag is a promise you have to keep forever. When someone asks for a feature, ask what job they are trying to finish and whether an existing command already covers it with a small change. The tools people keep using for years are the ones that stayed focused.

Build the tool you wish existed, keep the commands short, make the errors helpful, and ship a version people can install in a minute. That is most of what it takes to build a CLI tool developers actually enjoy using, and the rest is listening to the people who use it.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.