Skip to content

Commit 42b3ced

Browse files
Kasper Jungeclaude
authored andcommitted
docs: add GitHub Actions CI/CD recipe for users who want to run autonomous loops in CI
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c54d6ee commit 42b3ced

2 files changed

Lines changed: 115 additions & 0 deletions

File tree

docs/cookbook.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,119 @@ When both a `command` in frontmatter and a `run.*` script exist, the script take
455455

456456
---
457457

458+
## Running in GitHub Actions
459+
460+
Run ralphify as a GitHub Actions workflow — useful for automated bug fixing, documentation generation, or scheduled code maintenance.
461+
462+
### Workflow
463+
464+
Create `.github/workflows/ralph-loop.yml`:
465+
466+
```yaml
467+
name: Ralph Loop
468+
469+
on:
470+
workflow_dispatch:
471+
inputs:
472+
iterations:
473+
description: "Number of iterations to run"
474+
default: "5"
475+
type: string
476+
477+
permissions:
478+
contents: write
479+
480+
jobs:
481+
loop:
482+
runs-on: ubuntu-latest
483+
steps:
484+
- uses: actions/checkout@v4
485+
486+
- uses: actions/setup-python@v5
487+
with:
488+
python-version: "3.11"
489+
490+
- name: Install tools
491+
run: |
492+
pip install ralphify
493+
npm install -g @anthropic-ai/claude-code
494+
495+
- name: Run ralph loop
496+
env:
497+
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
498+
run: |
499+
ralph run \
500+
-n ${{ inputs.iterations }} \
501+
--stop-on-error \
502+
--timeout 300 \
503+
--log-dir ralph-logs
504+
505+
- name: Upload logs
506+
if: always()
507+
uses: actions/upload-artifact@v4
508+
with:
509+
name: ralph-logs
510+
path: ralph-logs/
511+
512+
- name: Push changes
513+
run: |
514+
git config user.name "github-actions[bot]"
515+
git config user.email "github-actions[bot]@users.noreply.github.com"
516+
git add -A
517+
git diff --staged --quiet || git commit -m "chore: apply changes from ralph loop"
518+
git push
519+
```
520+
521+
### Key settings for CI
522+
523+
| Setting | Why |
524+
|---|---|
525+
| `-n 5` | Cap iterations to control cost and runtime |
526+
| `--stop-on-error` | Stop immediately if the agent fails instead of burning credits |
527+
| `--timeout 300` | Kill stuck iterations after 5 minutes |
528+
| `--log-dir ralph-logs` | Capture output so you can debug via artifacts |
529+
530+
### Tips for CI usage
531+
532+
**Store your API key as a repository secret.** Go to Settings → Secrets and variables → Actions and add `ANTHROPIC_API_KEY`. Never hardcode keys in the workflow file.
533+
534+
**Use `workflow_dispatch` for manual control.** This lets you choose how many iterations to run each time. You can also add a `schedule` trigger for recurring loops:
535+
536+
```yaml
537+
on:
538+
schedule:
539+
- cron: "0 9 * * 1-5" # 9 AM UTC on weekdays
540+
workflow_dispatch:
541+
inputs:
542+
iterations:
543+
default: "5"
544+
type: string
545+
```
546+
547+
**Create a PR instead of pushing directly.** For safer workflows, open a pull request so you can review the agent's changes before merging:
548+
549+
```yaml
550+
- name: Create pull request
551+
env:
552+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
553+
run: |
554+
BRANCH="ralph/run-$(date +%Y%m%d-%H%M%S)"
555+
git checkout -b "$BRANCH"
556+
git add -A
557+
git diff --staged --quiet && exit 0
558+
git commit -m "chore: apply changes from ralph loop"
559+
git push -u origin "$BRANCH"
560+
gh pr create \
561+
--title "Ralph loop: automated changes" \
562+
--body "Automated changes from ralph loop run." \
563+
--base main
564+
```
565+
566+
!!! note "Adapt for your agent"
567+
This example uses Claude Code, but ralphify works with any CLI that reads stdin. Replace the agent install step and environment variables to match your agent. See [Using a different agent](cli.md#using-a-different-agent).
568+
569+
---
570+
458571
## Static context (no command)
459572

460573
Contexts don't need a command — you can use them for static text that you want to inject without editing the prompt file.

docs/faq.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ ralph run -n 5 --stop-on-error --timeout 300 --log-dir artifacts/ralph-logs
5151

5252
Make sure the agent CLI is installed and authenticated in your CI environment. Use `-n` and `--stop-on-error` to keep runs bounded.
5353

54+
See [Running in GitHub Actions](cookbook.md#running-in-github-actions) for a complete workflow you can copy into your repo.
55+
5456
## Usage
5557

5658
### Can I edit the prompt while the loop is running?

0 commit comments

Comments
 (0)