Chaining Commands with Shell Pipes

OpenClaw integrates naturally with the Unix shell pipeline philosophy. Use --quiet --format json to produce machine-readable output for piping:

# Count security issues found in a review
openclaw run --context ./src "Find all SQL injection risks" --format json --quiet \
  | python3 -c "import json,sys; d=json.load(sys.stdin); print(len(d['result']['issues']))"

# Pipe file list into openclaw via stdin context
find ./src -name "*.py" | xargs openclaw run "Check these files for hardcoded secrets" --no-confirm

Using OpenClaw in Shell Scripts

OpenClaw works seamlessly in bash and other shell scripts. Always check exit codes for reliable automation:

#!/usr/bin/env bash
set -euo pipefail

# Run security audit
echo "Starting security audit..."
openclaw run \
  --context ./src \
  --format markdown \
  --output reports/security-$(date +%Y%m%d).md \
  --quiet \
  --no-confirm \
  "Perform a comprehensive security audit. Report all high and critical severity findings."

if [ $? -eq 0 ]; then
  echo "Audit complete. Report saved to reports/"
  # Send notification
  curl -s -X POST "$SLACK_WEBHOOK" \
    -d "{\"text\": \"Security audit complete. See reports/security-$(date +%Y%m%d).md\"}"
else
  echo "Audit failed. Check logs at ~/.openclaw/logs/" >&2
  exit 1
fi

PowerShell Script

# PowerShell automation script
$ErrorActionPreference = "Stop"

$outputFile = "reports\security-$(Get-Date -Format 'yyyyMMdd').md"

openclaw run `
  --context .\src `
  --format markdown `
  --output $outputFile `
  --quiet `
  --no-confirm `
  "Perform a security audit and list all findings"

if ($LASTEXITCODE -eq 0) {
  Write-Host "Audit complete: $outputFile"
} else {
  Write-Error "Audit failed with exit code $LASTEXITCODE"
  exit $LASTEXITCODE
}

Environment Variable Reference

VariableDefaultDescription
OPENCLAW_PROVIDERopenaiDefault LLM provider
OPENCLAW_MODELgpt-4oDefault model name
OPENCLAW_API_KEY(none)Generic API key (provider-auto-detected)
OPENCLAW_LOG_LEVELinfoLogging verbosity (debug/info/warn/error)
OPENCLAW_TIMEOUT300Default timeout in seconds
OPENCLAW_MAX_STEPS20Default maximum agent steps
OPENCLAW_CONFIG_PATH~/.openclaw/config.yamlConfig file path
OPENCLAW_PROFILEdefaultActive config profile
OPENCLAW_NO_COLORfalseDisable colored terminal output

CI/CD Integration

OpenClaw integrates with GitHub Actions, GitLab CI, and other CI systems. Here is a complete GitHub Actions workflow for automated code review on every pull request:

# .github/workflows/ai-review.yml
name: AI Code Review

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"

      - name: Install OpenClaw
        run: pip install openclaw

      - name: Run security audit
        env:
          OPENCLAW_OPENAI_KEY: ${{ secrets.OPENAI_API_KEY }}
          OPENCLAW_PROVIDER: openai
          OPENCLAW_MODEL: gpt-4o
        run: |
          openclaw run \
            --context ./src \
            --format markdown \
            --output review-report.md \
            --quiet \
            --no-confirm \
            "Review all changed files for bugs, security issues, and code quality problems"

      - name: Post review as PR comment
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const report = fs.readFileSync('review-report.md', 'utf8');
            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: '## AI Code Review\n\n' + report
            });

Configuration Profiles

Use profiles to switch between different environments (dev, staging, production) with different settings:

# Create a dev profile with Ollama (free, offline)
openclaw config set --profile dev provider ollama
openclaw config set --profile dev ollama.model llama3.2

# Create a prod profile with GPT-4o
openclaw config set --profile prod provider openai
openclaw config set --profile prod model gpt-4o

# Use a specific profile for a task
openclaw run --profile prod "Generate executive summary of Q1 sales data" --context data/q1.csv

# Set default profile via environment
export OPENCLAW_PROFILE=dev
💡
Pro tip

Use --profile dev for experimentation with local/cheap models, and --profile prod for high-stakes tasks requiring the best model. This can dramatically reduce API costs during development.

Output Control & Filtering

When integrating OpenClaw into pipelines, controlling output format is critical.

# JSON output for downstream processing
openclaw run "List all TODO items in src/" ./src --format json | jq '.results[]'

# Suppress progress indicators, print only final answer
openclaw run "Summarize this PR" --quiet --format text

# Write output to file directly
openclaw run "Generate release notes for v2.0" --output release-notes.md

# Combine flags for CI/CD
openclaw run "Run code quality check" \
  --format json \
  --quiet \
  --max-steps 20 \
  --timeout 120 \
  --output report.json

Error Handling in Scripts

#!/usr/bin/env bash
# Exit immediately if openclaw fails
set -e

result=$(openclaw run "Validate config" --format json 2>&1)
exit_code=$?

if [ $exit_code -ne 0 ]; then
  echo "ERROR: OpenClaw task failed"
  echo "$result"
  exit 1
fi

echo "Task succeeded: $(echo "$result" | jq -r '.summary')"

See also: openclaw run for full flags reference and Debugging Guide for advanced diagnostics.