# Exit codes (/workflows/code/exit-codes)

The `sim workflows source` and `sim workspaces source` commands exit with a code a script or CI job can branch on. Findings print on stderr, and the result of a command goes to stdout. A code of its own is set aside for each outcome a script handles differently, so test for the code you act on, not for any non-zero status.

`status` is the command to branch on: it exits `0` when nothing differs, `11` when only your edits are unsaved, and `12` when the server changed since the directory was read.

```bash
sim workspaces source status --dir workspace --output json > status.json
case $? in
  0)  echo "in sync" ;;
  11) echo "local edits to apply" ;;
  12) echo "the workspace changed in Sim since the get" ;;
  *)  echo "status failed"; exit 1 ;;
esac
```

## Codes \[#codes]

The table for the kind of directory you work in. Both are built from the table `--help`, the generated [CLI reference](/cli/workflows#workflows-as-code) and `.sim/AGENTS.md` print, so they cannot disagree with the CLI.

Tab: Workflow directory

| Code | Meaning | What to do |
| - | - | - |
| `0` | Applied or created, a dry run or check with no errors, or a clean status | Go on |
| `1` | The source has errors (each printed as `file:line:column` with a hint), a locked block (`E_APPLY_LOCKED_BLOCK`), a name another workflow holds (`SOURCE_NAME_TAKEN`), a `--run` test run that did not complete, a cancelled prompt, or the command failed | Fix what it printed and run it again |
| `5` | Stale (`SOURCE_STALE`, or `E_APPLY_STALE` on a dry run): the server changed what this directory was read from, and nothing was written | `sim workflows source get --dir <fresh dir>`, reapply your edit there, dry-run, apply |
| `6` | A workflow or its folder is locked (`E_APPLY_LOCKED`); a locked block exits 1 instead | Ask someone to unlock it in the workflow builder |
| `7` | The source is over the size limits (on a get, status or diff too) | Split function code, or remove blocks or resources |
| `8` | `sim workspaces source apply` stopped part-way: what was written is saved into the directory | Apply again until it exits 0 |
| `9` | Still rate limited (HTTP 429) after the CLI's retries (up to 6, at most a minute apart); nothing more was written | Wait a minute and run the same command again |
| `10` | Busy: another apply is writing the workspace (`SOURCE_BUSY`), or another sim command is using this directory (`SOURCE_DIR_BUSY`); nothing was written | Run it again once the other finished |
| `11` | `status`: only your edits, which applying writes | Dry-run, then apply |
| `12` | `status`: the server changed since the get (drift, or a conflict with your edits) | Follow the `Next:` line it prints |
| `13` | Not logged in, the login expired, or the server refused the credential (`AUTH_REQUIRED`); nothing was sent | `sim login`, or fix or unset `SIM_API_KEY` when the key comes from it; then the same command again |
| `14` | `apply` or `create` without `--yes` and no terminal to ask: it printed the plan, found no errors, and wrote nothing | Run the same command with `--yes` |
| `15` | `sim workspaces source apply` (or `--to`) wrote part of its plan and held the rest back: a change that uses a declared secret the workspace has no value for, or a credential key nothing binds to. Its dry run exits 15 too, so a script can tell beforehand that the apply would write only part | Set the secret (`sim secrets set`) or connect the credential, then apply again |
| `130` | Interrupted (Ctrl-C). An apply or create already sent is finished and saved into the directory first, waiting up to 60s for its answer; a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written | `sim workflows source status --dir .` |

Tab: Workspace directory

| Code | Meaning | What to do |
| - | - | - |
| `0` | Applied or created, a dry run or check with no errors, or a clean status | Go on |
| `1` | The source has errors (each printed as `file:line:column` with a hint), a locked block (`E_APPLY_LOCKED_BLOCK`), a name another resource holds (`E_NAME_TAKEN`), a `--run` test run that did not complete, a cancelled prompt, or the command failed | Fix what it printed and run it again |
| `5` | Stale (`SOURCE_STALE`, or `E_APPLY_STALE` on a dry run): the server changed what this directory was read from, and nothing was written | `sim workspaces source get --dir <fresh dir>`, reapply your edit there, dry-run, apply |
| `6` | A resource is locked (`E_APPLY_LOCKED`): a workflow or its folder, or a table; a locked block exits 1 instead | Ask someone to unlock it: a workflow in the workflow builder, a table in its settings (the finding's hint names which) |
| `7` | The source is over the size limits (on a get, status or diff too) | Split function code, or remove blocks or resources |
| `8` | `sim workspaces source apply` stopped part-way: what was written is saved into the directory | Apply again until it exits 0 |
| `9` | Still rate limited (HTTP 429) after the CLI's retries (up to 6, at most a minute apart); nothing more was written | Wait a minute and run the same command again |
| `10` | Busy: another apply is writing the workspace (`SOURCE_BUSY`), or another sim command is using this directory (`SOURCE_DIR_BUSY`); nothing was written | Run it again once the other finished |
| `11` | `status`: only your edits, which applying writes | Dry-run, then apply |
| `12` | `status`: the server changed since the get (drift, or a conflict with your edits) | Follow the `Next:` line it prints |
| `13` | Not logged in, the login expired, or the server refused the credential (`AUTH_REQUIRED`); nothing was sent | `sim login`, or fix or unset `SIM_API_KEY` when the key comes from it; then the same command again |
| `14` | `apply` or `create` without `--yes` and no terminal to ask: it printed the plan, found no errors, and wrote nothing | Run the same command with `--yes` |
| `15` | `sim workspaces source apply` (or `--to`) wrote part of its plan and held the rest back: a change that uses a declared secret the workspace has no value for, or a credential key nothing binds to. Its dry run exits 15 too, so a script can tell beforehand that the apply would write only part | Set the secret (`sim secrets set`) or connect the credential, then apply again |
| `130` | Interrupted (Ctrl-C). An apply or create already sent is finished and saved into the directory first, waiting up to 60s for its answer; a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written | `sim workspaces source status --dir .` |

Exit `9` follows the CLI's retries: it resends a request the API answered `429` only when sending it twice is safe, which includes every `GET`, a source `apply` and a `create`. See [Scripting](/cli/scripting#exit-codes) for the retry schedule and the codes every command shares (`13` and `9`).

## Related docs \[#related-docs]

- [Troubleshooting](/workflows/code/troubleshooting): the causes behind each code
- [Run in CI](/workflows/code/ci)
- [Diagnostic codes](/workflows/code/diagnostics)
- [Limits](/workflows/code/limits)
- [Scripting: exit codes](/cli/scripting#exit-codes)
- [CLI workflow commands](/cli/workflows#workflows-as-code) and [workspace commands](/cli/workspaces#workspace-as-code)
