Overview
agent-desktop uses three exit codes to indicate the outcome of a command. These codes enable precise error handling in scripts and automation workflows.
Exit Code Reference
Success - Command completed successfullyThe command executed without errors. JSON output on stdout contains
"ok": true.Structured Error - Command failed with a known error conditionThe command encountered a runtime error (permission denied, element not found, timeout, etc.). JSON output on stdout contains
"ok": false with error details.Argument Parse Error - Invalid command-line argumentsThe command syntax was incorrect or required arguments were missing. Error message printed to stderr (not JSON).
Error Codes (Exit Code 1)
When exit code is1, the JSON output includes a machine-readable error code:
| Code | Meaning | Recovery |
|---|---|---|
PERM_DENIED | Accessibility permission not granted | Grant permission in System Settings |
ELEMENT_NOT_FOUND | No element matched the ref or query | Run snapshot to get updated refs |
APP_NOT_FOUND | Application not running or no windows | Launch the app first |
STALE_REF | Ref is from a previous snapshot | Run snapshot to refresh refs |
ACTION_FAILED | The OS rejected the action | Verify element supports the action |
TIMEOUT | Wait condition expired | Increase timeout or check condition |
INVALID_ARGS | Invalid argument values | Check argument format |
ACTION_NOT_SUPPORTED | Action not available for this element | Use a different action |
WINDOW_NOT_FOUND | Window not found | Verify window exists with list-windows |
PLATFORM_NOT_SUPPORTED | Feature not available on this OS | Check platform support |
INTERNAL | Unexpected internal error | Report as bug |
Scripting Examples
Bash: Handle Errors
Python: Parse JSON Errors
Node.js: Retry on Stale Ref
Best Practices
Always check exit codes in scripts to handle errors gracefully
Parse JSON on exit code 1 to get structured error information
Use error codes for conditional logic rather than parsing error messages
Related
- JSON Output - Structured response format
- Error Handling - Recovery strategies