$? directly — no need to parse error messages, which may change between releases. This pairs with the structured stderr JSON (see Output Format) for cases where you need both the code and a human-readable explanation.
Exit code reference
| Code | Name | Meaning |
|---|---|---|
0 | ok | Command succeeded. |
1 | internal | An unexpected internal error occurred. |
2 | usage | Invalid arguments or flags were passed. |
3 | vault_not_found | No vault with that name is registered in config, or no default vault is set and --vault was not provided. |
4 | note_not_found | The note ID passed to get, links, or backlinks does not exist in the index. |
5 | index_missing | The vault is registered but has not been indexed yet — run smolbren index first. |
Shell scripting examples
Checking the exit code after a search
Auto-indexing on a missing index (exit code 5)
A common pattern in setup scripts is to index automatically the first time a vault is used:Distinguishing vault errors from missing notes
Exit code
2 is emitted by the argument parser when a command is malformed — for example, a missing required argument or an unrecognised flag. The error message will appear on stderr as plain text (not JSON), because the error occurs before smolbren’s own error handling runs.error and code fields) that accompanies non-zero exits, see Output Format.