Claude Skills Guide

Claude Code for Runbook Testing Workflow Tutorial

Runbooks are essential documentation for DevOps and SRE teams, but they’re often neglected because testing them manually is time-consuming and error-prone. This tutorial shows you how to leverage Claude Code to automate runbook testing, ensuring your operational procedures remain accurate and up-to-date.

Why Automate Runbook Testing?

Manual runbook testing suffers from several problems that automation can solve:

Claude Code can help you create executable runbook tests that verify procedures work correctly across environments.

Setting Up Your Runbook Testing Framework

Before you can test runbooks with Claude Code, you need a proper testing infrastructure. Create a dedicated directory for your runbook tests:

mkdir -p runbook-tests/{scripts,fixtures,reports}
cd runbook-tests

Creating a Runbook Test Skill

The foundation of automated runbook testing is a Claude Code skill that understands your infrastructure. Here’s a basic skill structure:

# CLAUDE_SKILL.md
name: Runbook Tester
description: Tests runbook procedures against live infrastructure
version: 1.0.0
trigger: when I need to test a runbook

Your skill should include functions that can execute runbook steps and verify their outcomes. The key is creating idempotent test commands that can run repeatedly.

Writing Testable Runbooks

The first step in runbook testing is authoring runbooks that can actually be tested. Here’s a pattern for writing testable runbook steps:

Instead of This:

1. Check the database connection
2. If successful, restart the service
3. Verify the service is running

Write This:

# Step 1: Verify database connectivity
pg_isready -h db.example.com -p 5432 -U app_user
# Expected: exit code 0 within 5 seconds

# Step 2: Gracefully restart the service
systemctl restart myapp.service
# Expected: service stops within 10 seconds

# Step 3: Verify service health
curl -f http://localhost:8080/health || exit 1
# Expected: HTTP 200 response

Practical Example: Testing a Database Failover Runbook

Let’s walk through testing a real runbook. Assume you have a failover procedure:

The Runbook (database-failover.md)

# Database Failover Runbook

## Prerequisites
- Primary database is unreachable
- Replication lag < 1 second

## Steps

### 1. Verify Primary Unreachable
```bash
pg_isready -h primary.db.example.com -p 5432
# Must return: "primary.db.example.com:5432 - no response"

2. Promote Replica

pg_ctl promote -D /var/lib/postgresql/data
# Must return: "promote succeeded"

3. Update Connection String

sed -i 's/primary.db.example.com/replica.db.example.com/' /etc/myapp/db.conf
# Verify: grep "replica.db.example.com" /etc/myapp/db.conf

4. Restart Application

systemctl restart myapp

5. Verify Application Health

curl -s http://localhost:8080/api/health | jq -r '.status'
# Expected: "healthy"

Rollback

If anything fails: git checkout /etc/myapp/db.conf && systemctl restart myapp


### Testing This Runbook with Claude Code

You can prompt Claude Code to test this runbook systematically:

Test the database-failover.md runbook against staging environment. For each step:

  1. Execute the command
  2. Capture output and exit code
  3. Verify against expected result
  4. Record pass/fail with evidence
  5. If step fails, attempt rollback and report

Use these test parameters:

Claude Code will execute each step, verify the expected outcomes, and generate a test report:

## Runbook Test Report: database-failover.md
### Environment: staging
### Date: 2026-03-15

| Step | Command | Expected | Actual | Status |
|------|---------|----------|--------|--------|
| 1 | pg_isready primary | no response | exit code 1 | PASS |
| 2 | pg_ctl promote | succeeded | "promote succeeded" | PASS |
| 3 | sed update connection | replica.db.example.com | grep found | PASS |
| 4 | systemctl restart | exit 0 | exit 0 | PASS |
| 5 | curl health | "healthy" | "healthy" | PASS |

### Result: ALL TESTS PASSED
### Time: 45 seconds

Advanced: Continuous Runbook Testing

For enterprise environments, you can integrate runbook testing into your CI/CD pipeline. Create a GitHub Actions workflow:

name: Runbook Tests
on:
  schedule:
    - cron: '0 2 * * *'  # Daily at 2 AM
  push:
    paths:
      - 'runbooks/**'

jobs:
  test-runbooks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Claude Code
        uses: anthropic/claude-code-action@v1
        
      - name: Test All Runbooks
        run: |
          claude --print "Test all runbooks in ./runbooks directory. \
            Execute each step and verify expected outcomes. \
            Generate JSON report to ./runbook-tests/results.json"
            
      - name: Upload Results
        uses: actions/upload-artifact@v4
        with:
          name: runbook-test-results
          path: ./runbook-tests/results.json

Best Practices for Runbook Testing

Follow these guidelines for effective runbook testing:

1. Test in Staging First

Always test runbooks in non-production environments before running them in production. Use Claude Code to run parallel tests in staging and compare results.

2. Add Timeout Guards

Long-running steps can hang your automation. Specify timeouts for each step:

timeout 30s pg_isready -h primary.db.example.com || echo "timeout or error"

3. Implement Rollback Verification

Every critical runbook should have a rollback procedure. Test that rollback works correctly:

After testing the main runbook, execute the rollback procedure
and verify the system returns to its original state.

4. Version Your Runbooks

Use Git to version control your runbooks and test results:

git add runbooks/ runbook-tests/
git commit -m "Test runbook: database-failover - all steps passed"

5. Monitor Test Coverage

Track which runbooks have been tested and when:

{
  "runbook_tests": {
    "database-failover.md": {
      "last_tested": "2026-03-15T02:00:00Z",
      "status": "passing",
      "test_count": 5,
      "average_duration_seconds": 45
    }
  }
}

Common Pitfalls to Avoid

Be aware of these common mistakes when implementing runbook testing:

Conclusion

Automated runbook testing with Claude Code transforms static documentation into executable, verifiable procedures. By following this tutorial, you can reduce operational incidents, improve team confidence in runbooks, and ensure your emergency procedures actually work when you need them.

Start small: pick one critical runbook, add testable commands with expected outputs, and prompt Claude Code to execute it. Once you see the value, expand to your full runbook library.