← 返回
未分类 中文

Agent-Friendly CLI

Design and audit CLIs for agent usability. Use when building a new CLI tool, auditing an existing CLI for agent compatibility, reviewing CLI UX for AI agents...
为智能体可用性设计并审计CLI。适用于构建新CLI工具、审计现有CLI的智能体兼容性及审查AI代理的CLI用户体验。
g9pedro g9pedro 来源
未分类 clawhub v1.0.1 2 版本 100000 Key: 无需
★ 0
Stars
📥 437
下载
💾 0
安装
2
版本
#latest

概述

Agent-Friendly CLI Design

Checklist and patterns for building CLIs that agents can use effectively. Most CLIs assume a human at the keyboard — these patterns close the gap.

Core Principles

1. Non-Interactive by Default

Every input must be passable as a flag. Interactive prompts block agents.

# ❌ Blocks agents
$ mycli deploy
? Which environment? (use arrow keys)

# ✅ Works
$ mycli deploy --env staging

Keep interactive mode as fallback when flags are missing, never the primary path.

2. Progressive Help Discovery

Don't dump all docs upfront. Let agents discover via --help per subcommand.

# Agent runs top-level, sees subcommands
$ mycli --help

# Picks one, gets specific help
$ mycli deploy --help

An agent wastes no context on commands it won't use.

3. Useful --help with Examples

Every subcommand gets --help. Every --help includes examples. Agents pattern-match off examples faster than descriptions.

$ mycli deploy --help
Options:
  --env     Target environment (staging, production)
  --tag     Image tag (default: latest)
  --force   Skip confirmation

Examples:
  mycli deploy --env staging
  mycli deploy --env production --tag v1.2.3
  mycli deploy --env staging --force

4. Flags and stdin for Everything

Agents think in pipelines. Support chaining and piping.

cat config.json | mycli config import --stdin
mycli deploy --env staging --tag $(mycli build --output tag-only)

Don't require positional args in weird orders. Don't fall back to interactive prompts for missing values.

5. Fail Fast with Actionable Errors

Missing flag? Error immediately with correct invocation. Don't hang or print vague messages.

# ❌ Bad
$ mycli deploy
Error: missing required arguments

# ✅ Good
$ mycli deploy
Error: --env is required
Usage: mycli deploy --env <staging|production> [--tag <version>]

Agents self-correct when given something to work with.

6. Idempotent Commands

Agents retry constantly — network timeouts, context loss mid-task. Running the same command twice should be safe.

$ mycli deploy --env staging --tag v1.2.3
✓ Deployed v1.2.3 to staging

$ mycli deploy --env staging --tag v1.2.3
✓ Already deployed, no-op

7. --dry-run for Destructive Actions

Let agents preview before committing.

$ mycli deploy --env production --tag v1.2.3 --dry-run
Would deploy v1.2.3 to production
  - Stop 3 running instances
  - Pull image registry.io/app:v1.2.3
  - Start 3 new instances
No changes made.

8. --yes / --force to Skip Confirmations

Humans get "are you sure?" — agents pass --yes.

$ mycli delete-all --yes

Make the safe path the default but allow bypassing.

9. Predictable Command Structure

Pick a pattern and use it everywhere. If an agent learns one, it can guess the rest.

# resource + verb pattern
mycli service list
mycli deploy list
mycli config list

10. Structured Output on Success

Return actionable data, not just decorative messages.

# ❌ Cute but unhelpful
$ mycli deploy
🚀 Deployed successfully!

# ✅ Actionable
$ mycli deploy --env staging --tag v1.2.3
deployed v1.2.3 to staging
url: https://staging.myapp.com
deploy_id: dep_abc123
duration: 34s

Support --json for machine-readable output when possible.

11. Consistent Exit Codes

  • 0 = success
  • 1 = general error
  • 2 = usage error (bad args)

Agents use exit codes to decide next steps.

Audit Checklist

When reviewing an existing CLI for agent compatibility, check each item:

#PatternCheck
-------------------
1Non-interactiveCan every input be passed as a flag?
2Progressive helpDoes each subcommand have its own --help?
3Examples in helpDoes --help include usage examples?
4Stdin supportCan data be piped in via --stdin or -?
5Fast failuresDo missing args error immediately with usage hint?
6IdempotencyIs running the same command twice safe?
7Dry runDo destructive commands support --dry-run?
8Skip promptsIs there --yes / --force for confirmations?
9Predictable structureIs command naming consistent (resource + verb)?
10Structured outputDoes success output include actionable data?
11JSON outputIs --json available for machine parsing?
12Exit codesAre exit codes consistent (0/1/2)?

When Designing a New CLI

  1. Start with the flag-only interface. Add interactive prompts later as convenience.
  2. Write the --help examples before writing the implementation.
  3. Default to --json output internally, add human-friendly formatting on top.
  4. Every write operation gets --dry-run. No exceptions.
  5. Test by having an agent use it. Watch where it gets stuck.

Source

Based on Eric Zakariasson's (Cursor) "Building CLIs for agents" (March 2026), field-tested across ClawVault, WorkGraph, and Versatly CLI ecosystem.

版本历史

共 2 个版本

  • v1.0.1 当前
    2026-05-03 06:57 安全 安全
  • v1.0.0
    2026-03-31 18:39 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

Find Skills

root
帮助用户发现和安装智能体技能,当用户询问如「如何做X」、「找X的技能」、「有能做...的吗」等问题时
★ 1,518 📥 574,328
ai-agent

self-improving agent

pskoett
记录自身发现以实现自我改进的技能
★ 4,163 📥 935,826
design-media

OpenAI Image CLI

g9pedro
通过 OpenAI 的 GPT Image 和 DALL‑E 模型生成、编辑和管理图像。
★ 0 📥 2,500