$? 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
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.