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
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).
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.
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.
Map API endpoints to commands
Each API endpoint becomes a subcommand. GET /messages → mycli messages list. Keep it intuitive. Follow the noun verb pattern.
Make it agent-friendly
This is what separates a good CLI from a great one:
- JSON output:
--format jsonor--jsonflag - Non-interactive mode: Don't prompt when piped (
isatty()check) - Exit codes: 0 success, 1 error, 2 bad usage
- Agent Skill: Write a
SKILL.mdfor AI agent discovery - MCP Server: Expose tools via Model Context Protocol
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
Single binary, cross-compile, fast. Best for: CLIs you want to distribute widely. Libraries: cobra, bubbletea.
Peak performance, zero dependencies. Best for: file processing, system tools. Libraries: clap, ratatui.
Fast to build, npm distribution. Best for: API wrappers, dev tools. Libraries: commander, ink.
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:
Google Workspace — Gmail, Calendar, Drive, Contacts. The CLI that proved you don't need Google to build a Google CLI.
Point at any URL, YouTube video, or podcast. Get the gist. CLI + Chrome Extension.
Apple Messages from the terminal. Lets agents send and receive iMessages.
WhatsApp CLI. Full WhatsApp access from the command line.
Like the macOS `say` command, but with ElevenLabs voices. Modern TTS from terminal.
Google Places from the terminal. Search, details, reviews — structured output.
Spotify in the terminal. Search, play, queue — using web cookies for auth.
Apple Reminders from the CLI. Create, list, complete reminders.
Control Sonos speakers. Play, pause, volume, grouping — all from terminal.
Check Foodora and Deliveroo orders. Because your agent should know when lunch arrives.
Eight Sleep pod control. Temperature, schedules, sleep data.
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.
Resources
Built something? We want to list it.
Submit your CLI