Skip to content

Exit codes

Reference

The process exit codes of mare for headless runs, RPC and ACP servers, the interactive interface and subcommands, and the reason values of the final settled record.

This reference page is maintained by hand (not generated by scripts/gen_docs.py).

mare -p and mare --json finish with one of these codes. With --json, the same code and a matching reason appear in the last record (see JSON event stream).

Code settled.reason Meaning
0 completed The turn finished without an error.
1 error A provider, tool or runtime error. Also a session that -c or --resume could not find, and SIGTERM or SIGHUP.
2 usage Bad arguments or configuration: an unknown flag, no prompt, an unreadable stdin, a failing init.lua, a config warning under --strict-config, or a trust problem. The run never started.
3 approval_unavailable An approval was answered with “deny and stop” (abort) and the turn was stopped.
4 max_turns --max-turns was reached.
4 timeout --timeout was reached.
5 save_failed Session persistence failed. Any final answer is still written to stdout, unsaved records are written to <state>/quarantine/, and a warning is printed to stderr.
130 interrupted SIGINT (Ctrl+C).
141 none Stdout was closed by the reader, for example mare --json ... | head. The turn is stopped and no settled record is written.

Some notes on how these are chosen:

  • Code 3 is only for runs that stopped because an approval was answered abort. An approval nobody could answer is a denied call, not a stop: the model gets the denial, and if it works around it the turn completes with 0. Every denial is listed on stderr, whatever the exit code.
  • --timeout bounds the whole run, including delivering output. When it fires, mare cancels the turn, tries to write turn.failed and settled (with timeout) and exits 4. If the reader of stdout is blocked, the stream can end without them, so treat a missing settled as a failure.
  • The first SIGINT cancels the turn and finishes normally with 130. A second SIGINT exits at once with 130 and writes no settled record.
  • A usage error under --json still prints session, turn.failed and settled lines so a script reading the stream always gets an outcome.
  • --timeout is refused with 2 outside headless runs (-p and --json).
Terminal window
mare -p --timeout 5m --max-turns 30 "Fix the failing tests"
case $? in
0) echo done ;;
3) echo "stopped by an approval abort: rerun with a permission preset that allows it" ;;
4) echo "ran out of turns or time" ;;
*) echo "failed" ;;
esac
Mode Code When
mare --rpc 0 Stdin closed, shutdown received, or SIGTERM or SIGINT.
mare --rpc 2 Config warnings under --strict-config, a broken init.lua, or a trust problem at startup. mare writes the message to stderr.
mare acp 0 The editor closed the connection.
Interactive 0 Normal quit, or SIGTERM during startup.
Interactive 130 SIGINT before the interface took over.
Interactive 2 You chose to quit from the startup dialog for a failing config file.
Command Codes
mare doctor 0 when every check passes, 1 when any check fails. --json uses the same codes.
mare session ... new, list, fork, archive, unarchive, delete: 0 on success (new and fork print the id); 1 when new creates no session, delete is cancelled, or an operation fails; 2 for invalid --limit, an unresolved or ambiguous session selector, or delete without --yes on non-TTY stdin.
mare test 0 when all tests pass, 1 when one or more test cases fail, 2 on usage, spec discovery, host startup, or spec load/syntax errors.
mare token rotate 0 on success, 1 on failure.
mare web url 0 on success (prints the ?token= login URL), 1 when no listener is running or token lookup fails.
mare login, mare logout, mare model refresh 0 on success, 1 on failure, 2 when the host could not start or --with-api-key has no key on stdin.
mare mcp ... 0, or 1 when the action reports a config error or a failure.
mare peer send 0 once the receiving session accepted the message (it prints held, delivered or handled). 1 for a missing target, a refused message or no answer within 30 seconds.
mare sandbox status 0. With --require-full, 1 unless all sandbox isolation capabilities are fully enforced (currently exits 1 on Windows even when the enhanced self-test passes because per-call network isolation is not enforced).
mare sandbox setup 0 on success, 1 on failure. 2 on platforms other than Windows.
mare trust, mare init, mare runtime, mare plugin ..., mare completion, mare rpc schema 0 on success. Any error is reported on stderr with exit code 1.

Argument errors from the command-line parser itself, such as an unknown subcommand, exit with 2. A crash that ends the process writes a report under <state>/crashes/ and exits non-zero (see Files).