Exit codes
Memory Layer follows normal CLI conventions: 0 means success, non-zero means the command did not complete the requested operation. Treat command output contracts (--json, stdout/stderr) as more important than hard-coding every possible failure number.
Common cases
| Exit code | Meaning | Typical cause |
|---|---|---|
0 | Success | Command completed. |
2 | CLI usage error | Unknown subcommand, missing required flag, invalid argument shape from clap. |
1 | Operational failure | Service down, database/migration error, invalid token, provider failure, failed postcondition, or command-specific error. |
Some subcommands may return other non-zero values through wrapped tools or platform service managers. Scripts should handle any non-zero as failure unless a command's JSON contract says otherwise.
Scripting guidance
Use --json where available. Machine-readable output is written to stdout; diagnostics and errors should be treated as stderr.
if ! memory status --project memory --json >status.json; then
echo "Memory Layer status failed" >&2
exit 1
fiUsage errors are quick to detect:
memory query --project memory
# exits 2 because --question is requiredOperational failures need diagnostics:
memory doctor
memory health
memory service statusFor write-capable commands, run dry-runs first when supported:
memory scan --project memory --dry-run --json
memory embeddings reindex --project memory --dry-run
memory bundle import --project memory ./memory.mlbundle.zip --dry-runNext
Use Doctor and health when a command exits non-zero for operational reasons.
