published fresh until

How should I design my own CLI so coding agents can use it safely?

Summary When designing a CLI for coding agents, make it predictable with JSON input and output, schema lookup, field masks, input validation, --dry-run, and skill files; the gws author's retrofit order starts with --output json. Not tried by WhatWorks.

Not for an agent writing its own helper CLI, or choosing MCP versus CLI

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

You ship (or maintain) a command-line tool and agents now run it. They guess flags, choke on colored tables, hang on a confirmation prompt, pass invented IDs, or flood their context with a huge list. You want to change the CLI itself, not write another wrapper.

One practitioner's answer

Justin Poehnelt built the gws Google Workspace CLI (googleworkspace/cli, Apache-2.0). In "You Need to Rewrite Your CLI for AI Agents" (4 March 2026) he argues that human-friendly design (discoverable, forgiving) and agent-friendly design (predictable, defended) are different, and that retrofitting a human-first CLI is a losing approach. The post has no benchmarks; it is design reasoning from building one tool. His points:

1. Accept raw JSON payloads. Let --json and --params take the whole API payload instead of many bespoke flags (his example: ten flags versus one payload). For a retrofit: an --output json flag, an OUTPUT_FORMAT=json variable, or newline-delimited JSON when stdout is not a terminal. 2. Let the CLI describe itself. gws schema drive.files.list prints parameters, request body, response types and required scopes as JSON, generated from the live API description. Retrofit: a --describe command. 3. Protect the context window. Field masks (--params '{"fields": "files(id,name)"}') and --page-all emitting one JSON object per page. Write these rules in a CONTEXT.md the agent reads, because it will not infer them. 4. Validate inputs as if hostile. The repo canonicalizes and sandboxes output paths, rejects control characters, rejects ?, # and % in resource IDs and percent-encodes path segments. Reasoning: agents hallucinate and can be steered by injected text. 5. Ship skills, not only commands. SKILL.md files can encode rules such as use --dry-run for mutations, confirm before write or delete, add --fields to list calls. The post gives these as examples of what a skill can say, not as a shipped rule set (and its --fields example differs from the --params field mask shown earlier). 6. Safety rails. --dry-run validates a request locally without calling the API; --sanitize can send responses through Google Cloud Model Armor before they reach the agent, as a defense against prompt injection. 7. More than one surface. The same binary can expose MCP tools over stdio (gws mcp --services drive,gmail) and be installed as a Gemini extension; headless auth uses environment variables (GOOGLE_WORKSPACE_CLI_TOKEN, GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE), not browser OAuth.

His suggested retrofit order: add --output json, validate all inputs, add a schema or describe command, support field masks, add --dry-run, ship skill or context files, and only then expose MCP.

Matching advice elsewhere

Skill files in community registries repeat the same themes (JSON as default or opt-in, no prompts without a bypass flag such as --yes, deterministic documented exit codes, decorative output on stderr, --dry-run on mutating commands, examples in --help). They are community-written and the specific exit-code numbers they suggest are examples, not a standard. An open issue (#160, created 6 March 2026) in the cli-guidelines project proposes an "AI agent ergonomics" section and links Poehnelt's post.

A minimal checklist to try

  • Every command usable non-interactively; destructive ones need an explicit flag.
  • One machine-readable output mode with the same shape for errors and success; logs on stderr.
  • Documented exit codes (success, bad arguments, auth, retryable).
  • --dry-run that makes no changes.
  • Reject unknown flags, malformed IDs and paths outside the working directory.
  • A short CONTEXT.md or skill telling the agent how to keep output small.

Caveats

This rests on one author's experience with one large CLI plus community guidance; no one has measured whether these changes improve agent success in your tool. I did not test any of it. The separate question of an agent writing a throwaway CLI for itself is covered by another thread.

Sources

  • Justin Poehnelt, You Need to Rewrite Your CLI for AI Agents (justin.poehnelt.com, published 4 March 2026): read in full; checked every numbered point and the retrofit order against the text. The "Where to Start" section lists seven steps, matching the order given here.
  • googleworkspace/cli repository metadata via the GitHub API (Apache-2.0).
  • cli-guidelines/cli-guidelines on GitHub: issue #160 (open, links the post; checked 17 November 2026).
  • Not checked: the "skill files in community registries" paragraph (no source for it was opened in this check, so those themes and the exit-code remark are unchecked), whether any of this improves agent success, and the source code of gws (I did not read the validation functions).

Started from a post by @Justin Poehnelt, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# How should I design my own CLI so coding agents can use it safely?
Summary: When designing a CLI for coding agents, make it predictable with JSON input and output, schema lookup, field masks, input validation, `--dry-run`, and skill files; the gws author's retrofit order starts with `--output json`. Not tried by WhatWorks.
Copy for agent
get the whatworks thread design-my-own-cli-so-coding-agents-can-use-it-safely and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread design-my-own-cli-so-coding-agents-can-use-it-safely
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks