audit-agentic-cli
Make a CLI an agent can drive without human babysitting. The contract: pure machine-readable stdout, semantic exit codes, non-interactive defaults, structured errors with retry guidance, and — for workflows that produce repairable artifacts — an iterative feedback loop the agent can finish on its own.
When To Use
Trigger this skill when the user is doing CLI-only agent-readiness work:
- "make my CLI agent-friendly" / "audit CLI for LLM use"
- the agent keeps failing to parse a CLI result
- stdout mixes JSON with progress text or spinners
- every failure exits 1 with no structured error body
- a command hangs waiting for an interactive prompt
- the workflow validates, rejects, repairs, and resubmits a generated artifact
- a fresh CLI needs agent-first constraints from day one
- help text is unreliable as a contract for an agent caller
Do not use this skill for:
- Surface choice (CLI vs MCP vs hybrid). Make the surface decision first using your normal architecture process. Only after the surface decision is fixed as CLI does this skill apply.
- MCP server audits, schemas, transports, auth, or context budgets. Route to
audit-agentic-mcp for audit/architecture, build-mcp-use-server for mcp-use implementation (raw @modelcontextprotocol/sdk work has no skill in this pack: follow the SDK's own docs), test-by-mcpc-cli for live MCP verification.
- Vendor CLI operations when a vendor skill exists. Use
run-railway instead.
- Generic shell scripting unrelated to the CLI's agent contract.
Five Core Audit Checks
Before recommending features, verify these. If any fail, fix them first.
--json (or equivalent) exists and stdout is pure machine output — no progress, no banners, no prose.
- Logs, spinners, banners, and progress go to stderr.
- Exit codes distinguish success, usage error, auth, not-found, conflict, validation, and transient/retryable failures — not all
0 or 1.
- Headless runs never block without an explicit
--no-input/--yes path or a clear non-interactive error.
- Error responses include a stable error code and a retryable boolean (or equivalent guidance).
When a command must emit a non-JSON artifact (patch, diff, query, prompt, translation), keep stdout one canonical artifact format and put status on stderr or in a sidecar — never mix prose into the data channel.
Severity Rubric
Classify findings in agent terms, not human-UX terms.
| Severity |
Use when |
| Critical |
Agents cannot safely parse, continue, or avoid unintended side effects (e.g. JSON mixed with progress on stdout; destructive command with no --dry-run/--yes). |
| High |
Agents act but are likely to fail, retry incorrectly, or block (e.g. prompt with no --no-input; opaque exit 1 for every error class). |
| Medium |
Agents finish only with extra probing or brittle assumptions (e.g. undocumented output fields, missing help examples). |
| Low |
Polish or consistency only (e.g. nonstandard alias when long flag is documented). |
Minimum Output Envelope
Aim for one stable JSON envelope across all commands.
Success:
{ "ok": true, "result": {}, "error": null, "schema_version": "v1" }
Failure:
{
"ok": false,
"result": null,
"error": {
"class": "validation",
"code": "MISSING_FLAG",
"message": "Flag --target is required.",
"retryable": false,
"suggestion": "Run `mycli deploy --target <name>`."
},
"schema_version": "v1"
}
Stdout = data channel. Stderr = operator channel. Exit code = semantic class. All three must agree.
Build Order (Repair Existing CLI)
When fixing an existing CLI, do the work in this order. Skipping ahead wastes effort.
- Pure JSON output and stdout/stderr separation.
- Structured errors and semantic exit codes.
- Non-interactive flags and safe defaults (
--no-input, --yes, --dry-run).
- Iterative feedback loops for any command whose output the agent might need to repair.
- Discovery: help text, examples, documented exit codes and output fields.
- Async / JSONL / job-style flows for long-running operations.
Audit Workflow
Before recommending changes:
- Inspect top-level help and each relevant subcommand. Use
scripts/audit-cli-help.sh (read scripts/audit-cli-help.md first) to capture standard flags, examples, and missing affordances.
- Look for machine-readable output flags:
--json, --output json, --quiet, --fields, --jq.
- Test stdout/stderr separation on safe read-only commands.
- Classify exit codes across success, usage, auth, not-found, validation, conflict, and transient paths.
- Probe non-interactive behavior on prompt-prone commands.
- Inspect destructive flow safety:
--dry-run, --yes, --force, explicit confirmation semantics.
- Verify help documents realistic examples, output fields, and exit codes.
- If auditing a CLI you've snapshotted before, diff with
scripts/diff-cli-help.sh (read scripts/diff-cli-help.md first) to spot command/flag drift.
Iterative Repair Loop
Use this pattern when an agent generates an artifact, the CLI validates it, and the agent must repair on rejection.
input artifact -> CLI validation -> structured diff/errors -> agent repair -> retry -> accepted -> finalize
Typical fits: translation/localization batches, code generation with validation gates, manifest/config/migration generation, bulk import or sync.
Each iteration must tell the agent:
- current stage
- accepted / rejected / partial
- what failed, with identifiers or locations
- whether the failure is retryable
- the next command to run (
next_action.command)
- progress complete vs work remaining
One-shot read/list/get/status commands do not need this — use the simpler envelope.
For the full design pattern and a worked case study, read references/iterative-cli.md.
Design Rules
- One stable envelope shape across all commands.
- Stdout = data. Stderr = operator. Exit code = semantic class.
- Command names and field types stay consistent across releases.
- Destructive flows are explicit:
--yes, --force, --dry-run.
--help documents examples, output fields, and exit codes.
- For repairable workflows, return enough structure for an agent to fix and retry without human interpretation.
Output Contract (Deliverable Shape)
Pick one based on the task.
Audit report: scorecard by audit dimension, severity-ranked findings, command evidence (exact safe command + observed stdout/stderr/exit), why it matters for agents, recommended fix, verification command.
Refactored CLI contract: proposed command grammar, flags and non-interactive behavior, stdout/stderr rules, JSON envelope and stream format, exit-code map, migration notes for existing users and scripts.
Iterative repair-loop design: phases and command family, artifact channel, validation response shape, retry budget, next_action.command, finalization criteria.
Local Exemplars
linear-cli — strong agent-ready CLI: JSON everywhere, --dry-run, --id-only, non-pager flags, exit-code contract, bulk-mutation gates.
run-railway — drift-aware CLI: installed-help snapshot, upstream-vs-local distinction, refresh scripts, version-drift routing.
Reference Routing
Read the smallest reference set that matches the task.
| Problem |
Read |
| JSON envelopes, schemas, error fields, stream separation, exit-code taxonomy |
references/output-contracts.md |
| Retries, idempotency, async jobs, batch, timeout, pagination, rate limits |
references/execution-patterns.md |
| Help, auth, config, flags, environment detection |
references/discovery-and-auth.md |
| Iterative repair-loop CLI design and case study |
references/iterative-cli.md |
| CLI vs MCP vs hybrid (when surface is still in question) |
references/mcp-vs-cli-decision.md |
| Worked code examples (Go, Python, Node, Rust, Shell) and real-world audits |
references/examples.md |
| Patterns for the agent or service that calls the CLI |
references/agent-integration.md |
These are canonical homes — do not duplicate their content here.
Bundled Scripts
Read-only discovery support. Do not treat them as agent-readiness proofs.
| Script |
Read first |
Use for |
scripts/audit-cli-help.sh |
scripts/audit-cli-help.md |
Inspect top-level and subcommand help for standard flags, examples, exit-code docs, and missing affordances. |
scripts/diff-cli-help.sh |
scripts/diff-cli-help.md |
Compare captured help snapshots for command/flag additions, removals, and likely breaking changes. |
These cover discoverability and drift only. They do not replace stdout/stderr, exit-code, non-interactive, and destructive-flow checks — run those by hand.
Finish Criteria
Do not call a CLI agent-ready until:
- The five core audit checks pass.
- The JSON envelope is stable enough to script against across commands.
--help documents the command contract (examples, output fields, exit codes).
- A non-interactive run can succeed or fail deterministically with no human keystroke.
- Any iterative workflow returns enough structured feedback for an agent to repair without human interpretation.
1---2name: audit-agentic-cli3description: "Use if auditing or designing a CLI for agent/LLM use — JSON output, exit codes, non-interactive."4disable-model-invocation: true5metadata:6 source: https://skillmd.com/skills/yigitkonur/audit-agentic-cli7---89# audit-agentic-cli1011Make a CLI an agent can drive without human babysitting. The contract: pure machine-readable stdout, semantic exit codes, non-interactive defaults, structured errors with retry guidance, and — for workflows that produce repairable artifacts — an iterative feedback loop the agent can finish on its own.1213## When To Use1415Trigger this skill when the user is doing CLI-only agent-readiness work:1617- *"make my CLI agent-friendly"* / *"audit CLI for LLM use"*18- *the agent keeps failing to parse a CLI result*19- *stdout mixes JSON with progress text or spinners*20- *every failure exits 1 with no structured error body*21- *a command hangs waiting for an interactive prompt*22- *the workflow validates, rejects, repairs, and resubmits a generated artifact*23- *a fresh CLI needs agent-first constraints from day one*24- *help text is unreliable as a contract for an agent caller*2526Do **not** use this skill for:2728- **Surface choice (CLI vs MCP vs hybrid).** Make the surface decision first using your normal architecture process. Only after the surface decision is fixed as CLI does this skill apply.29- **MCP server audits, schemas, transports, auth, or context budgets.** Route to `audit-agentic-mcp` for audit/architecture, `build-mcp-use-server` for mcp-use implementation (raw `@modelcontextprotocol/sdk` work has no skill in this pack: follow the SDK's own docs), `test-by-mcpc-cli` for live MCP verification.30- **Vendor CLI operations** when a vendor skill exists. Use `run-railway` instead.31- **Generic shell scripting** unrelated to the CLI's agent contract.3233## Five Core Audit Checks3435Before recommending features, verify these. If any fail, fix them first.36371. `--json` (or equivalent) exists and **stdout is pure machine output** — no progress, no banners, no prose.382. Logs, spinners, banners, and progress go to **stderr**.393. **Exit codes** distinguish success, usage error, auth, not-found, conflict, validation, and transient/retryable failures — not all `0` or `1`.404. Headless runs **never block** without an explicit `--no-input`/`--yes` path or a clear non-interactive error.415. Error responses include a stable **error code** and a **retryable** boolean (or equivalent guidance).4243When a command must emit a non-JSON artifact (patch, diff, query, prompt, translation), keep stdout one canonical artifact format and put status on stderr or in a sidecar — never mix prose into the data channel.4445## Severity Rubric4647Classify findings in agent terms, not human-UX terms.4849| Severity | Use when |50|---|---|51| Critical | Agents cannot safely parse, continue, or avoid unintended side effects (e.g. JSON mixed with progress on stdout; destructive command with no `--dry-run`/`--yes`). |52| High | Agents act but are likely to fail, retry incorrectly, or block (e.g. prompt with no `--no-input`; opaque exit `1` for every error class). |53| Medium | Agents finish only with extra probing or brittle assumptions (e.g. undocumented output fields, missing help examples). |54| Low | Polish or consistency only (e.g. nonstandard alias when long flag is documented). |5556## Minimum Output Envelope5758Aim for one stable JSON envelope across all commands.5960Success:6162```json63{ "ok": true, "result": {}, "error": null, "schema_version": "v1" }64```6566Failure:6768```json69{70 "ok": false,71 "result": null,72 "error": {73 "class": "validation",74 "code": "MISSING_FLAG",75 "message": "Flag --target is required.",76 "retryable": false,77 "suggestion": "Run `mycli deploy --target <name>`."78 },79 "schema_version": "v1"80}81```8283Stdout = data channel. Stderr = operator channel. Exit code = semantic class. All three must agree.8485## Build Order (Repair Existing CLI)8687When fixing an existing CLI, do the work in this order. Skipping ahead wastes effort.88891. Pure JSON output and stdout/stderr separation.902. Structured errors and semantic exit codes.913. Non-interactive flags and safe defaults (`--no-input`, `--yes`, `--dry-run`).924. Iterative feedback loops for any command whose output the agent might need to repair.935. Discovery: help text, examples, documented exit codes and output fields.946. Async / JSONL / job-style flows for long-running operations.9596## Audit Workflow9798Before recommending changes:991001. Inspect top-level help and each relevant subcommand. Use `scripts/audit-cli-help.sh` (read `scripts/audit-cli-help.md` first) to capture standard flags, examples, and missing affordances.1012. Look for machine-readable output flags: `--json`, `--output json`, `--quiet`, `--fields`, `--jq`.1023. Test stdout/stderr separation on safe read-only commands.1034. Classify exit codes across success, usage, auth, not-found, validation, conflict, and transient paths.1045. Probe non-interactive behavior on prompt-prone commands.1056. Inspect destructive flow safety: `--dry-run`, `--yes`, `--force`, explicit confirmation semantics.1067. Verify help documents realistic examples, output fields, and exit codes.1078. If auditing a CLI you've snapshotted before, diff with `scripts/diff-cli-help.sh` (read `scripts/diff-cli-help.md` first) to spot command/flag drift.108109## Iterative Repair Loop110111Use this pattern when an agent generates an artifact, the CLI validates it, and the agent must repair on rejection.112113```114input artifact -> CLI validation -> structured diff/errors -> agent repair -> retry -> accepted -> finalize115```116117Typical fits: translation/localization batches, code generation with validation gates, manifest/config/migration generation, bulk import or sync.118119Each iteration must tell the agent:120121- current stage122- accepted / rejected / partial123- what failed, with identifiers or locations124- whether the failure is retryable125- the next command to run (`next_action.command`)126- progress complete vs work remaining127128One-shot read/list/get/status commands do not need this — use the simpler envelope.129130For the full design pattern and a worked case study, read `references/iterative-cli.md`.131132## Design Rules133134- One stable envelope shape across all commands.135- Stdout = data. Stderr = operator. Exit code = semantic class.136- Command names and field types stay consistent across releases.137- Destructive flows are explicit: `--yes`, `--force`, `--dry-run`.138- `--help` documents examples, output fields, and exit codes.139- For repairable workflows, return enough structure for an agent to fix and retry without human interpretation.140141## Output Contract (Deliverable Shape)142143Pick one based on the task.144145**Audit report:** scorecard by audit dimension, severity-ranked findings, command evidence (exact safe command + observed stdout/stderr/exit), why it matters for agents, recommended fix, verification command.146147**Refactored CLI contract:** proposed command grammar, flags and non-interactive behavior, stdout/stderr rules, JSON envelope and stream format, exit-code map, migration notes for existing users and scripts.148149**Iterative repair-loop design:** phases and command family, artifact channel, validation response shape, retry budget, `next_action.command`, finalization criteria.150151## Local Exemplars152153- `linear-cli` — strong agent-ready CLI: JSON everywhere, `--dry-run`, `--id-only`, non-pager flags, exit-code contract, bulk-mutation gates.154- `run-railway` — drift-aware CLI: installed-help snapshot, upstream-vs-local distinction, refresh scripts, version-drift routing.155156## Reference Routing157158Read the smallest reference set that matches the task.159160| Problem | Read |161|---|---|162| JSON envelopes, schemas, error fields, stream separation, exit-code taxonomy | `references/output-contracts.md` |163| Retries, idempotency, async jobs, batch, timeout, pagination, rate limits | `references/execution-patterns.md` |164| Help, auth, config, flags, environment detection | `references/discovery-and-auth.md` |165| Iterative repair-loop CLI design and case study | `references/iterative-cli.md` |166| CLI vs MCP vs hybrid (when surface is still in question) | `references/mcp-vs-cli-decision.md` |167| Worked code examples (Go, Python, Node, Rust, Shell) and real-world audits | `references/examples.md` |168| Patterns for the agent or service that calls the CLI | `references/agent-integration.md` |169170These are canonical homes — do not duplicate their content here.171172## Bundled Scripts173174Read-only discovery support. Do not treat them as agent-readiness proofs.175176| Script | Read first | Use for |177|---|---|---|178| `scripts/audit-cli-help.sh` | `scripts/audit-cli-help.md` | Inspect top-level and subcommand help for standard flags, examples, exit-code docs, and missing affordances. |179| `scripts/diff-cli-help.sh` | `scripts/diff-cli-help.md` | Compare captured help snapshots for command/flag additions, removals, and likely breaking changes. |180181These cover discoverability and drift only. They do not replace stdout/stderr, exit-code, non-interactive, and destructive-flow checks — run those by hand.182183## Finish Criteria184185Do not call a CLI agent-ready until:186187- The five core audit checks pass.188- The JSON envelope is stable enough to script against across commands.189- `--help` documents the command contract (examples, output fields, exit codes).190- A non-interactive run can succeed or fail deterministically with no human keystroke.191- Any iterative workflow returns enough structured feedback for an agent to repair without human interpretation.