Building CLIs That Agents Actually Use π₯
Yo, fam, agents (those AI tools chaining commands like a boss) choking on human-centric CLIs? That's the pain. π
1οΈβ£ WHY Does This Even Matter? (The Sucky Before)
Before agent-friendly CLIs:
PROBLEM (Human CLIs) β AGENT NIGHTMARE
ββββββββββββββββββββββ ββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β Interactive β β Stuck on prompt β
β prompts β ββββββββββΊ β Can't arrow-key β
β No examples β β Parses walls β
β Weird args β β of useless text β
β Retries dupes β β Timeouts crash β
βββββββββββββββββββ βββββββββββββββββββ
Agents get stuck forever on "Press Y?" or parse garbage docs. Humans guess intuitively; agents need explicit paths. This exists to make CLIs pipeable, retry-safe, and previewable π. Ohhhhh moment: Agents automate your ops, but only if your CLI doesn't treat 'em like noobs.
2οΈβ£ BIG PICTURE: Agent CLI Blueprint
Think resource + verb pattern:
mycli [resource] [action] [flags]
Examples:
βββ mycli deploy --env staging
βββ mycli config list
βββ mycli service list (predictable AF)
Core Principles:
- Non-interactive by default β
- Discoverable via
--help+ examples - Pipe-friendly (stdin/stdout)
- Safe (idempotent, dry-run, fail-fast)
- Output data, not just "done β "
3οΈβ£ HOW It Works: Key Patterns (Step-by-Step)
Let's break down the tips with examples. Follow this, your CLI slays agents.
Non-Interactive: Flags Over Prompts
Why? Agents can't "press enter". Blocks mid-run.
BAD β GOOD β
$ mycli deploy $ mycli deploy --env staging
? Env? (arrows) βββSTUCK Runs smooth
- Make flags required/defaulted.
- Interactive? Fallback only.
Killer --help with Examples
Why? Agents pattern-match examples faster than prose.
$ mycli deploy --help
Options:
--env staging/prod
--tag v1.2.3 (default: latest)
Examples: π AGENT GOLD
mycli deploy --env staging
mycli deploy --env prod --tag v1.2.3 --force
No doc dumpsβlet 'em discover subcommands dynamically.
Flags + Stdin/Pipes for Pipelines
Why? Agents chain like cat | cmd | next.
cat config.json | mycli config import --stdin
mycli deploy --env staging --tag $(mycli build --output tag-only)
- Positional args? Nah, flags everywhere.
- Stdout machine-readable (JSON?).
Fail Fast + Actionable Errors
Why? Agents self-fix from hints.
Error: Missing tag.
Try: mycli deploy --env staging --tag <tag>
Hints: mycli build list --output tags
Exit code 1, no hanging.
Idempotent Commands
Why? Retries on flakesβdon't dupe deploys!
$ mycli deploy --env staging (1st time)
β Deployed
$ mycli deploy --env staging (retry)
Already deployed, no-op β
--dry-run for Safety
Why? Preview destructo before commit.
$ mycli deploy --prod --tag v1 --dry-run
Would:
- Stop 3 instances
- Pull image
- Start 3 new
No changes π»
$ mycli deploy --prod --tag v1 (real)
β Deployed! ID: dep_abc
Perfect for agent "plan + execute".
--yes / --force Bypass
Why? Safe defaults for humans, opt-out for agents.
Default: ? Sure? [y/N]
Agent: --yes
Predictable Structure + Data Output
Why? Agents guess deploy list from service list.
Output:
deployed v1 to staging
url: https://staging.app.com
deploy_id: dep_abc123
duration: 34s
Parseable, no emojis fluff.
π₯ BURN THIS IN: TL;DR Agent CLI Checklist
βββββββββββββββββββββββββββββββ
β Agent-Ready CLI β
β
βββββββββββββββββββββββββββββββ€
β β’ Flags > prompts β
β β’ Examples in --help β
β β’ Pipes/stdin β
β β’ Fail-fast errors β
β β’ Idempotent β
β β’ --dry-run β
β β’ --yes β
β β’ Predictable nouns+verbs β
β β’ Data stdout β
βββββββββββββββββββββββββββββββ
Your CLI now agent's BFF. They save you debug hell. Got more tips? Hit me! π
Tracking? Wanna code example?