Exit Codes
π’ Understand CLI exit codes for scripting and automation.
ReasonKit uses standard exit codes to indicate success or failure, making it easy to integrate into scripts and CI/CD pipelines.
Exit Code Reference
| Code | Name | Description |
|---|---|---|
0 | Success | Command completed successfully |
1 | General Error | Unspecified error occurred |
2 | Invalid Arguments | Invalid command-line arguments |
3 | Configuration Error | Invalid or missing configuration |
4 | Provider Error | LLM provider connection failed |
5 | Authentication Error | API key invalid or missing |
6 | Rate Limit | Provider rate limit exceeded |
7 | Timeout | Operation timed out |
8 | Parse Error | Failed to parse input or output |
10 | Validation Failed | Confidence threshold not met |
Using Exit Codes in Scripts
Bash
#!/bin/bash
# Run analysis and check result
if rk-core think "Should we deploy?" --profile quick; then
echo "Analysis complete"
else
exit_code=$?
case $exit_code in
5)
echo "Error: API key not set"
;;
6)
echo "Error: Rate limited, try again later"
;;
7)
echo "Error: Analysis timed out"
;;
*)
echo "Error: Analysis failed (code: $exit_code)"
;;
esac
exit $exit_code
fi
Check Specific Conditions
# Retry on rate limit
max_retries=3
retry_count=0
while [ $retry_count -lt $max_retries ]; do
rk-core think "question" --profile balanced
exit_code=$?
if [ $exit_code -eq 0 ]; then
break
elif [ $exit_code -eq 6 ]; then
echo "Rate limited, waiting 60s..."
sleep 60
retry_count=$((retry_count + 1))
else
exit $exit_code
fi
done
CI/CD Integration
# GitHub Actions example
- name: Run ReasonKit Analysis
run: |
rk-core think "Is this PR ready to merge?" --profile balanced --output json > analysis.json
continue-on-error: true
- name: Check Analysis Result
run: |
if [ $? -eq 10 ]; then
echo "::warning::Analysis confidence below threshold"
fi
Verbose Exit Information
Use --verbose to get more details on errors:
rk-core think "question" --profile balanced --verbose
On error, this outputs:
- Error message
- Error code
- Suggested resolution
- Debug information (if available)
Exit Code Categories
Success (0)
- Analysis completed
- Output written successfully
- All validations passed
Client Errors (1-9)
- User-fixable issues
- Configuration problems
- Invalid input
Provider Errors (10-19)
- LLM provider issues
- Network problems
- External service failures
Validation Errors (20-29)
- Confidence thresholds not met
- Output validation failed
- Quality gates not passed
Scripting Best Practices
- Always check exit codes β Donβt assume success
- Handle rate limits β Implement exponential backoff
- Log failures β Capture stderr for debugging
- Use timeouts β Set reasonable
--timeoutvalues - Fail fast β Exit early on critical errors
Related
- Scripting β Full scripting guide
- Environment Variables β Configure via environment
- Commands β Full command reference