# What each surfacedd exit code means, and how to handle it in a script

> The surfacedd command exits 0 on success, 1 on an error such as a missing database or a failed run, 2 on a usage mistake, 3 on a licence problem, 4 when a spending limit or a missing confirmation stops a paid run, and 5 when an agent readiness check scores under --fail-under.

Source: https://surfacedd.com/docs/cli/exit-codes · Updated 2026-11-19

Exit codes are the contract between `surfacedd` and whatever runs it: your shell, cron, a CI runner or an AI agent. The same number also appears as `error.exit_code` in the [JSON output](/docs/cli/json-output), so a script that only kept the file still knows what happened. 

## The six codes

| Code | Meaning and examples |
|---|---|
| 0 | **OK.** The command did what you asked. A paid run that finished `completed` or `partial` also exits 0 |
| 1 | **Error.** Not found, the sample workspace, a missing API key, no database, another CLI job running, a run that ended `failed` or `cancelled`, a URL the check couldn't load or refused |
| 2 | **Usage.** Unknown command or option, a bad `--range`, a missing argument, an API key passed as a flag |
| 3 | **Licence.** This computer isn't activated, or a run or audit was started on a read-only licence |
| 4 | **Budget or confirmation needed.** Before a run: the estimate is over `--max-usd` or a hard budget cap, no `--yes` outside a terminal, or "no" at the prompt. During a run: it stopped at `--max-usd` or a monthly hard cap, keeping the answers it had |
| 5 | **Threshold failed.** `agent-readiness check --fail-under N` scored under N, or produced no score |

## Codes 4 and 5 are the ones scripts plan for

**Exit 4 means a limit or a missing yes stopped a paid run.** Before anything starts, a run checks, in order: an active licence (3), not the sample (1), then shows the estimate, then checks it against `--max-usd` and your hard budget caps (4), then asks for confirmation (4 if it can't). A refusal at this stage spends nothing. In a script there is no terminal to answer the question, so `report run` needs `--yes`.

Once a run has started, `--max-usd` keeps working as a hard limit on actual spend. If the next paid call could take the run past it, nothing new starts, the answers so far are kept, the run ends partial and the command exits 4. Read `data.limit.reached` and `data.limit.skipped` in the JSON to tell this case from a refusal. 

**Exit 5 is a result, not a crash.** `agent-readiness check` prints its full result first, including every failing rule, and then exits 5. In JSON the document still says `ok: true`, with `data.passed: false`. Treat 5 as "the site regressed" and 1 as "the check itself didn't run", for example because the URL didn't load. 

## A shell pattern

```bash
surfacedd agent-readiness check "$SITE_URL" --fail-under 70 --json > agent-readiness.json
case $? in
  0) echo "Agent readiness passed" ;;
  5) echo "Agent readiness under 70:"; jq -r '.data.problems[] | .id' agent-readiness.json; exit 1 ;;
  *) echo "Check didn't run: $(jq -r '.error.message // "see log"' agent-readiness.json)"; exit 1 ;;
esac
```

For a scheduled paid run, decide in advance what a refusal should do:

```bash
surfacedd report run "Weekly visibility" --max-usd 5 --yes --quiet || echo "not run: exit $?"
```

If the estimate climbs past 5 dollars, for example because you added prompts or engines, that line refuses with exit 4 and spends nothing. If the run starts but would pass 5 dollars part-way, it stops there, keeps its answers and also exits 4. Set the cap at or above the high estimate the command prints, and raise it on purpose, not by accident. 

## Fixes by code

| Code | First thing to check |
|---|---|
| 1 | The message on stderr, or `error.code` in JSON (`not_found`, `sample`, `keys`, `database`, `busy`). `surfacedd doctor` lists what's missing |
| 2 | `surfacedd help <command>` for the options. Keys are never accepted as flags; save them in the app |
| 3 | Settings › Licence & devices in the app. Reading and exports work on every licence state once this computer is activated |
| 4 | Read the estimate it printed. Raise `--max-usd` to at least the high estimate, adjust a budget, or add `--yes` if you meant to run it. After a stop, the partial run's answers are already in the app |
| 5 | The failing rules in the output. Fix them, or lower `--fail-under` deliberately |

See the [CI recipe](/docs/cli/ci) for the full agent readiness job.
