error.code changes.
Error Shape
schemaVersion and CostHQVersion fields are present on every response, including errors. Parse error.code to branch your logic. Never branch on error.message — it is human-readable prose that may change between versions.
Exit Codes
There is no ambiguity: any non-zero exit code means the command failed and an
error object is present in the JSON output.
Error Codes
Parsing Error Codes
When a command exits with code
1, execSync throws. The error object’s .stdout property still contains the full --json error payload — read it from there, not from stderr.Failsafe Pattern for Agents
Check thatcs is installed before attempting any tracking. If it is absent, skip gracefully rather than blocking your agent’s primary task.