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?

← All notes