Skip to content
Cisco AI Defense logo
CiscoAI Security

Exit codes — DefenseClaw

Overview

DefenseClaw uses a narrow, stable exit-code vocabulary shared between both CLIs (defenseclaw, defenseclaw-gateway) and echoed by the REST API's problem+json error bodies. Scripts can rely on these codes indefinitely.

Canonical code table plus every call-site discovered by AST scan.

CodeLabelMeaningCall-sites
0SuccessCommand completed normally.
1Generic failureUnhandled error, runtime exception, or unspecified failure.cli/defenseclaw/commands/cmd_quickstart.py:224, cli/defenseclaw/commands/cmd_setup_provider.py:678, cmd/docgen-go/main.go:117, cmd/docgen-go/main.go:124
2Usage errorClick / argparse rejects invalid flags or arguments.
3Configuration errorconfig.yaml missing, malformed, or fails schema validation.
4Policy violation / scan-gate blockedScanner or policy blocked the operation (e.g. skill install denied).
5Daemon not runningOperation required the gateway sidecar but it is down.
6Already runningdefenseclaw start invoked while daemon is up.
7Resource not foundSkill, MCP server, plugin, or audit row not found.
8Permission deniedInsufficient privileges (sandbox, filesystem, elevated ops).
9Provider / upstream failureLLM provider, webhook, or external API returned an error after retries.
10Sandbox erroropenshell-sandbox subsystem misbehaved.
100Feature disabledAttempted to use a guardrailed/gated feature that is off.

Patterns

  • 0 means success. Always.
  • 1 is a generic runtime failure.
  • 2 is the normal Click/Cobra usage error path for invalid flags or arguments.
  • Command-specific non-zero codes should be treated as failure unless the command page documents a softer automation contract.

Script examples

# Fail a build if config validation fails
defenseclaw config validate --quiet || {
  code=$?
  case $code in
    1) echo "config is invalid" ;;
    2) echo "invalid config validate invocation" ;;
    *) echo "unexpected code $code" ;;
  esac
  exit $code
}

# Export audit rows and preserve the exact failure code
defenseclaw-gateway audit export --output audit-events.jsonl
rc=$?
if [ "$rc" != "0" ]; then
  echo "audit export failed with code $rc"
  exit $rc
fi

Related