> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codemod.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Exit codes

> What each exit code of codemod workflow run, workflow resume and codemod <package> means, and how to read the run's result in a script.

`codemod workflow run`, `codemod workflow resume` and `codemod <package>` exit with a code that says how the run ended. Use it in CI and scripts; for the details, read the run with `codemod workflow status --id <id> --format json`.

| Code | Run status | Meaning | What to do |
| - | - | - | - |
| `0` | `succeeded` | The run finished. | Nothing. |
| `1` | `failed`, `paused`, `canceled`, `rejected` | A step failed, the run was stopped (Ctrl-C, `stop` over `--control stdio`), canceled with `workflow cancel`, or an approval was rejected. Also: an error before the run started, such as a workflow that doesn't build. | Read the error. Resume a failed or paused run with `workflow resume --id <id>`. |
| `2` | `succeeded` or `failed` | The run finished, but some files failed (`succeeded`), or the workflow called [`fail()`](https://docs.codemod.com/community/workflows/reference#failing-a-run-with-a-report) (`failed`). The run keeps its output. | Read the output: `Output: …`, or `output` in `workflow status --format json`. |
| `3` | `awaiting-approval` | The run stopped at an approval nobody could answer (`--no-interactive`, CI) and is waiting. Nothing after the approval ran. | Approve with `workflow resume --id <id> --approve <question-id>`, or end the run with `workflow cancel --id <id>`. |
| `3` | Unchanged | Resume needs a decision about a step that may already have taken effect. The workflow body does not run. | Check what the step did, then resume with `--rerun-step <step-id>` or `--skip-step <step-id>`. |
| other | `failed` | The workflow called `fail(message, { exitCode })` with that code (1 to 125). | Depends on the workflow. |

> [!NOTE]
>
> A run waiting at an approval exits `3`, not `0`, so a CI job doesn't pass with half a migration done. To get past approvals in CI, pass `--approve` on `workflow run`.

A workflow can also deliberately return `3` with `fail()`. Read the error and check `workflow status` to distinguish it from an approval or interrupted step that needs input.

A command line the CLI can't parse (an unknown flag, a missing value) exits `2` before any run starts, and prints usage instead of a run. Check for it before treating `2` as "finished with failures" in a script that builds its command line.

A dry run is never saved, so it can't wait at an approval: a dry run that reaches one exits `1` and says to pass `--approve`. With `--control stdio`, it waits for an answer like a real run.

## Read the result in a script

```bash theme={null}
npx codemod@next workflow run -w workflow.ts --target . --no-interactive
code=$?
case $code in
  0) echo "done" ;;
  2) echo "finished with failures" ;;
  3) echo "waiting for approval" ;;
  *) echo "failed ($code)"; exit $code ;;
esac
```

To read the run itself, get its id from `workflow list --format json` (newest first) and its status from `workflow status`:

```bash theme={null}
id=$(npx codemod@next workflow list --format json | jq -r '.[0].id')
npx codemod@next workflow status --id "$id" --format json | jq '{status, exitCode, question, output}'
```

```json theme={null}
{
  "status": "failed",
  "exitCode": 2,
  "question": null,
  "output": { "total": 3, "max": 0, "perPackage": { "api": 2, "web": 1 } }
}
```

`exitCode` is the code `fail()` gave, or `null` when the workflow didn't call it. `question` is the approval a waiting run needs, such as `"approval:1"`. A paused run keeps it too, so you can resume it with `--approve <question>` without remembering it.

With `--format jsonl`, a run that started ends with a `run_finished` event with the same `status`, `output` and `question`. An unattended resume that needs an interrupted-step decision prints the step and flags to stderr instead. See [Running in CI and from agents](https://docs.codemod.com/community/workflows/ci-and-agents.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.