P4: Fail Fast with Actionable Errors

Definition

CLI tools MUST detect invalid state early, exit with a structured error, and tell the caller three things: what failed, why, and what to do next. An error that says "operation failed" gives an agent nothing to act on.

Why Agents Need It

Agents operate in a retry loop: attempt, observe, decide. When an error is vague or unstructured — a bare stack trace, a one-word failure, a mixed-channel splurge — the agent cannot tell whether to retry, re-authenticate, fix configuration, or escalate to the user. Distinct exit codes with actionable messages let the agent act correctly on the first read. The difference between exit code 77 (re-authenticate) and exit code 78 (fix config) determines whether the agent retries OAuth or asks the user to check their config file. Getting that wrong wastes entire conversation turns.

Requirements

MUST:

SHOULD:

Evidence

Anti-Patterns

Measured by check IDs p4-bad-args, p4-process-exit, p4-unwrap, p4-exit-codes. Run agentnative check --principle 4 . against your CLI to see each.