home / guide

How to build a CLI for any service

The definitive guide to building command-line tools that work for humans and AI agents.

Why CLIs matter in the agent era

Every major platform is shipping a CLI: Google released gws for Workspace, GitHub has gh, Cloudflare has wrangler. This isn't a coincidence.

CLIs are the perfect interface layer for AI agents. They take structured input, produce structured output, and can be composed into pipelines. An agent can't click buttons in a web UI, but it can run gws gmail +triage --format json and parse the result.

If a service has a public API but no CLI, that's a gap waiting to be filled. Here's how to fill it.

The process

1

Find the API

Check if the service has a public REST/GraphQL API. Most do — look for "Developer" or "API" in the footer. Read the docs. Understand the auth flow (OAuth2, API key, token).

2

Create an app / Get credentials

Register a developer application on the platform. Get your client ID, client secret, or API key. For OAuth2 services (Google, GitHub, Spotify), you'll need to set up redirect URIs for the token exchange flow.

3

Authenticate & store tokens

Implement the auth flow. For OAuth2: open browser → user authorizes → exchange code for access + refresh tokens → store in ~/.config/your-cli/. For API keys: read from environment variable or config file.

4

Map API endpoints to commands

Each API endpoint becomes a subcommand. GET /messagesmycli messages list. Keep it intuitive. Follow the noun verb pattern.

5

Make it agent-friendly

This is what separates a good CLI from a great one:

  • JSON output: --format json or --json flag
  • Non-interactive mode: Don't prompt when piped (isatty() check)
  • Exit codes: 0 success, 1 error, 2 bad usage
  • Agent Skill: Write a SKILL.md for AI agent discovery
  • MCP Server: Expose tools via Model Context Protocol
6

Ship it

Publish as a single binary (Go is ideal), npm package, pip package, or brew formula. Write a README, add it to clis.dev, and share it.

Recommended stack

Go

Single binary, cross-compile, fast. Best for: CLIs you want to distribute widely. Libraries: cobra, bubbletea.

Rust

Peak performance, zero dependencies. Best for: file processing, system tools. Libraries: clap, ratatui.

TypeScript (Node)

Fast to build, npm distribution. Best for: API wrappers, dev tools. Libraries: commander, ink.

Python

Quick prototypes, AI/ML tools. Best for: data tools, AI integrations. Libraries: click, typer, rich.

Case study: The CLIs powering OpenClaw

Peter Steinberger built an army of CLI tools that became the backbone of OpenClaw, the fastest-growing open-source project on GitHub (270k+ stars). Each tool wraps a single service API — together, they give AI agents access to the real world.

Here's what he built and why each one matters:

The pattern is clear: one CLI per service, structured output, composable. Each tool is small (most under 2k lines of Go), but together they give an AI agent superhuman access to the digital world.

Built something? We want to list it.

Submit your CLI