Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

CodeNameDescription
0SuccessCommand completed successfully
1General ErrorUnspecified error occurred
2Invalid ArgumentsInvalid command-line arguments
3Configuration ErrorInvalid or missing configuration
4Provider ErrorLLM provider connection failed
5Authentication ErrorAPI key invalid or missing
6Rate LimitProvider rate limit exceeded
7TimeoutOperation timed out
8Parse ErrorFailed to parse input or output
10Validation FailedConfidence 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

  1. Always check exit codes β€” Don’t assume success
  2. Handle rate limits β€” Implement exponential backoff
  3. Log failures β€” Capture stderr for debugging
  4. Use timeouts β€” Set reasonable --timeout values
  5. Fail fast β€” Exit early on critical errors