CLI exit codes
Use exit codes to gate a build on a run.
Use exit codes to gate a build on a run. heybug runs wait follows a run until it ends, then exits with a code your CI step can read. The same codes come back from heybug runs start and heybug ci run.
What it is for
A script or CI job needs one answer: did the run pass, did it fail, or did something stop us from knowing. The exit code gives that answer without parsing text. The text on stderr explains the reason in plain words.
Exit codes
| Code | Name | Meaning | What to do |
|---|---|---|---|
| 0 | Passed | The run finished and every test passed. | Continue the pipeline. |
| 1 | Tests failed | A test failed, was blocked or was cancelled. | Open the dashboard link printed for the run. |
| 2 | Usage | An unknown flag, or a missing value or argument. | Read the usage line and fix the command. |
| 3 | Not signed in | Credentials are missing, invalid or expired. | Run heybug auth status, then sign in again. |
| 4 | Not found | The project, run or result does not exist. | Check the id and the project. |
| 5 | Invalid input | The input was rejected, or a CI gate found nothing to run. | Fix the flags. Use --allow-skip only if an empty run is fine. |
| 6 | Run wait timed out | The wait ran out of time. The run keeps going. Code 6 also covers a server or network error. | Wait again with the run id. Read the message to tell the two apart. |
| 7 | Rate limited | The server asked us to slow down. | Retry after a short pause. |
| 12 | Credits | The account has no credits left. | Add credits, then run again. |
| 13 | Plan gate | The feature is not in the current plan. | Ask the workspace owner about the plan. |
| 130 | Interrupted | You pressed Ctrl-C. | Start the run again, or run heybug runs cancel. |
Code 6 is the only code that can mean "not done yet". Treat it as a retry, not as a failure of the app under test.
Steps
- Start the run. Pass
--no-waitto get the run ids and return at once, or leave it out to follow the run in the same command. - Wait for the run with
heybug runs wait <runId>. Set--timeoutto the longest time your job can spend. The default is 30 minutes. The flag takes a duration such as30m. - Read the exit code. Stop the pipeline on any code except 0.
- If you need the details, open the dashboard link. You can also read the run with
GET /api/runs/{runId}and a signed-in token.
runs start --timeout takes seconds, not a duration. ci run waits without a time limit.
Example
Start a run in a CI step, wait for it, and branch on the code:
run=$(heybug runs start --project p_1 --env staging --no-wait --output json | jq -r '.runs[0].runId')
heybug runs wait "$run" --timeout 30m --output json
code=$?
case "$code" in
0) echo "Passed" ;;
1) echo "Tests failed. Open the dashboard link above." ;;
6) echo "Wait timed out or the server could not be reached." ; exit 6 ;;
*) echo "Setup problem. Read the message above." ; exit "$code" ;;
esacFor a single gate without a separate start step, heybug ci run --project p_1 --env staging --report junit waits for every run it starts. Add --allow-skip when an empty selection should pass.
An AI agent connected through MCP does not get an exit code. Its heybug_get_run tool takes a wait value of up to 45 seconds and returns the status as text. Call it again until the run is finished.
When it fails
- Code 6 and "Timed out; the runs are still going." Nothing was cancelled. Run
heybug runs wait <runId>again with a longer--timeout, or open the dashboard. - Code 6 with a connection error. The server was not reachable. Check
--server, then runheybug doctor. - Code 3. Run
heybug auth status. In CI, setHEYBUG_TOKENfrom a secret. Do not print it in the log. - Code 130. Ctrl-C cancels the runs that
runs startbegan, unless you passed--detach. Use--detachin long jobs where runs should keep going after the job stops. - Code 5 with "Skipped: no tests were selected". Nothing matched the filter. Check the filter, or pass
--allow-skipinci run.
See also CLI for install and sign-in, and CI for the workflow that calls these commands.