Install
openclaw skills install ralph-loop-writerGenerate ready-to-run shell loop commands for Claude Code, Gemini CLI, or Grok CLI, customized by AI tool, model, shell, complexity, and loop features.
openclaw skills install ralph-loop-writername: ralph description: "Generate Claude Code, Gemini CLI, or Grok CLI automation loop commands. Asks questions about your requirements and outputs a ready-to-run command for PowerShell, Windows CMD, or Bash/Linux." allowed-tools:
Generate optimized loop commands for automating Claude Code, Gemini CLI, or Grok CLI with PROMPT.md.
Use AskUserQuestion:
Store the choice for later.
Use AskUserQuestion based on AI tool choice:
If Claude Code selected:
If Gemini CLI selected:
If Grok CLI selected:
Store the choice for later.
Use AskUserQuestion:
Store the choice for later.
Use AskUserQuestion:
Use AskUserQuestion:
Use AskUserQuestion:
Use AskUserQuestion:
Based on selected features, ask for values:
If fixed iterations selected:
If time limit selected:
If delay selected:
If file monitoring selected:
Build the appropriate command based on:
IMPORTANT - Command Syntax:
For Claude Code (PowerShell/Bash):
Use claude-code (NOT claude -p) to accept piped input. The -p flag requires an argument, not pipe.
Get-Content PROMPT.md -Raw | claude-code --dangerously-skip-permissionsGet-Content PROMPT.md -Raw | claude-code --model haiku --dangerously-skip-permissionsGet-Content PROMPT.md -Raw | claude-code --model sonnet --dangerously-skip-permissionsGet-Content PROMPT.md -Raw | claude-code --model opus --dangerously-skip-permissionsFor Claude Code (Bash):
cat PROMPT.md | claude-code --dangerously-skip-permissionscat PROMPT.md | claude-code --model haiku --dangerously-skip-permissionsFor Gemini CLI (PowerShell): Gemini CLI accepts stdin piping.
Get-Content PROMPT.md -Raw | gemini --yoloGet-Content PROMPT.md -Raw | gemini --model gemini-3-flash --yoloGet-Content PROMPT.md -Raw | gemini --model gemini-3-pro --yoloGet-Content PROMPT.md -Raw | gemini --model gemini-2.5-flash --yoloGet-Content PROMPT.md -Raw | gemini --model gemini-2.5-pro --yoloFor Grok CLI (PowerShell):
Get-Content PROMPT.md -Raw | grok-auto (uses default model from GROK_MODEL env var, auto-approves permissions)Get-Content PROMPT.md -Raw | grok-auto -m grok-code-fast-1Get-Content PROMPT.md -Raw | grok-auto -m grok-4-latestGet-Content PROMPT.md -Raw | grok-auto -m grok-betaIMPORTANT - Placeholder Replacement:
For Claude Code: Replace [AI_COMMAND_WITH_PROMPT] with the FULL command including the prompt argument:
claude -p (Get-Content PROMPT.md -Raw) --dangerously-skip-permissionsclaude -p (Get-Content PROMPT.md -Raw) --model haiku --dangerously-skip-permissionsFor Gemini CLI: Replace [AI_COMMAND_WITH_PROMPT] with piped command:
Get-Content PROMPT.md -Raw | gemini --yoloGet-Content PROMPT.md -Raw | gemini --model gemini-3-flash --yoloFor Grok CLI: Replace [AI_COMMAND_WITH_PROMPT] with piped command:
Get-Content PROMPT.md -Raw | grok-autoGet-Content PROMPT.md -Raw | grok-auto -m grok-4-latestCRITICAL: Claude Code requires the prompt as a command-line argument. Piping does NOT work with claude -p.
PowerShell - Simple Fixed:
for ($i=1; $i -le N; $i++) { $start = Get-Date; Write-Host "`n=== Run $i/N ===" -ForegroundColor Cyan; [AI_COMMAND_WITH_PROMPT]; $duration = ((Get-Date) - $start).TotalSeconds; Write-Host "⏱️ Time: $([math]::Round($duration, 2))s" -ForegroundColor Magenta }
PowerShell - Simple Fixed + Delay:
for ($i=1; $i -le N; $i++) { $start = Get-Date; Write-Host "`n=== Run $i/N ===" -ForegroundColor Cyan; [AI_COMMAND_WITH_PROMPT]; $duration = ((Get-Date) - $start).TotalSeconds; Write-Host "⏱️ Time: $([math]::Round($duration, 2))s" -ForegroundColor Magenta; if ($i -lt N) { Write-Host "⏸️ Waiting X seconds..." -ForegroundColor Yellow; Start-Sleep -Seconds X } }
PowerShell - Simple Infinite + Delay:
$i=1; while ($true) { $start = Get-Date; Write-Host "`n=== Run $i ===" -ForegroundColor Cyan; [AI_COMMAND_WITH_PROMPT]; $duration = ((Get-Date) - $start).TotalSeconds; Write-Host "⏱️ Time: $([math]::Round($duration, 2))s" -ForegroundColor Magenta; Write-Host "⏸️ Waiting X seconds..." -ForegroundColor Yellow; Start-Sleep -Seconds X; $i++ }
PowerShell - Advanced Full Control:
$end = (Get-Date).AddMinutes(M); for ($i=1; $i -le N -and (Get-Date) -lt $end -and -not (Test-Path STOP.txt); $i++) { $start = Get-Date; Write-Host "`n[$(Get-Date -Format 'HH:mm:ss')] Run $i" -ForegroundColor Cyan; [AI_COMMAND_WITH_PROMPT]; $duration = ((Get-Date) - $start).TotalSeconds; Write-Host "⏱️ Time: $([math]::Round($duration, 2))s" -ForegroundColor Magenta; if ($i -lt N) { Write-Host "⏸️ Waiting X seconds..." -ForegroundColor Yellow; Start-Sleep -Seconds X } }; Write-Host "`n✅ Complete!" -ForegroundColor Green
CMD - Simple Fixed:
for /L %i in (1,1,N) do @(echo. & echo === Run %i === & type PROMPT.md | [AI_COMMAND])
Note: CMD has limited capabilities. For time tracking, recommend PowerShell.
CMD - Simple Infinite + Delay:
for /L %i in (1,0,2) do @(echo. & echo === Run %i === & type PROMPT.md | [AI_COMMAND] & timeout /t X /nobreak > nul)
CMD - Advanced:
for /L %i in (1,1,N) do @(if exist STOP.txt exit & echo. & echo [%time%] Run %i & type PROMPT.md | [AI_COMMAND] & timeout /t X /nobreak > nul)
Note: For time tracking, use PowerShell (see RalphPowerShellComands.md).
Bash - Simple Fixed:
for i in {1..N}; do echo -e "\n=== Run $i/N ==="; start=$(date +%s); cat PROMPT.md | [AI_COMMAND]; dur=$(($(date +%s) - start)); echo "⏱️ Time: ${dur}s"; done
Bash - Simple Fixed + Delay:
for i in {1..N}; do echo -e "\n=== Run $i/N ==="; start=$(date +%s); cat PROMPT.md | [AI_COMMAND]; dur=$(($(date +%s) - start)); echo "⏱️ Time: ${dur}s"; [ $i -lt N ] && { echo "⏸️ Waiting X seconds..."; sleep X; }; done
Bash - Simple Infinite + Delay:
i=1; while :; do echo -e "\n=== Run $i ==="; start=$(date +%s); cat PROMPT.md | [AI_COMMAND]; dur=$(($(date +%s) - start)); echo "⏱️ Time: ${dur}s"; echo "⏸️ Waiting X seconds..."; sleep X; ((i++)); done
Bash - Advanced:
end=$(($(date +%s) + M*60)); for i in {1..N}; do [ $(date +%s) -ge $end ] && break; [ -f STOP.txt ] && break; echo -e "\n[$(date +%H:%M:%S)] Run $i"; start=$(date +%s); cat PROMPT.md | [AI_COMMAND]; dur=$(($(date +%s) - start)); echo "⏱️ Time: ${dur}s"; [ $i -lt N ] && { echo "⏸️ Waiting X seconds..."; sleep X; }; done; echo -e "\n✅ Complete!"
Create a timestamped filename in the format: ralphcommand-YYYY-MM-DD-HHMMSS.md
Example: ralphcommand-2026-01-14-233045.md
Use the Write tool to create this file in the current directory with:
File structure:
# Ralph Command
Generated: [timestamp]
Shell: [PowerShell/CMD/Bash]
## Command
```[shell-type]
[THE ACTUAL COMMAND]
echo $null > STOP.txt / touch STOP.txt] (if stop file enabled)Runs [claude/gemini/grok] with PROMPT.md as input [N times / for M minutes / until stopped]. [Pauses X seconds between runs.] [Shows timestamp and run number.] [Displays execution time for each run.]
## Step 9: Notify User
After creating the file, tell the user the exact filename created:
✅ Created ralphcommand-YYYY-MM-DD-HHMMSS.md in your current directory!
The file contains your command ready to run. Just open it and copy the command.
For more variations and explanations, see:
## Notes
- **CRITICAL FOR CLAUDE CODE**: The prompt MUST be passed as a command-line argument, NOT via stdin pipe. Use `claude -p (Get-Content PROMPT.md -Raw) --dangerously-skip-permissions`. Piping does NOT work with `claude -p`.
- **For Gemini and Grok**: Stdin piping works fine. Use `Get-Content PROMPT.md -Raw | gemini --yolo` or `Get-Content PROMPT.md -Raw | grok-auto`.
- **Model Selection is Optional**: Always ask which model, but "Default" option omits the `--model` flag
- **For Claude Code (PowerShell)**:
- Default format: `claude -p (Get-Content PROMPT.md -Raw) --dangerously-skip-permissions`
- With model: `claude -p (Get-Content PROMPT.md -Raw) --model <model> --dangerously-skip-permissions`
- Models: `haiku`, `sonnet`, `opus`
- **For Gemini CLI**:
- Default format: `Get-Content PROMPT.md -Raw | gemini --yolo`
- With model: `Get-Content PROMPT.md -Raw | gemini --model <model> --yolo`
- Models: `gemini-3-flash`, `gemini-3-pro`, `gemini-2.5-flash`, `gemini-2.5-pro`
- Note: `-p` flag is deprecated in Gemini
- **For Grok CLI**:
- Use `grok-auto` PowerShell function which calls xAI API directly (perfect for automation)
- Default format: `Get-Content PROMPT.md -Raw | grok-auto` (no -m flag, uses GROK_MODEL env var if set)
- With model: `Get-Content PROMPT.md -Raw | grok-auto -m <model>`
- Models: `grok-code-fast-1`, `grok-4-latest`, `grok-beta`, `grok-4`
- Note: `grok-auto` is a PowerShell function that calls the xAI API directly (no CLI needed)
- Default model (grok-code-fast-1 via GROK_MODEL env var) is recommended for automation loops (fastest responses)
- Default to "Recommended" options when user is unsure
- Keep commands on one line when possible for easy copy-paste
- **Always include time tracking** - Show how long each run takes using `Get-Date` (PowerShell) or `date +%s` (Bash)
- **Always create timestamped file** - Format: `ralphcommand-YYYY-MM-DD-HHMMSS.md`
- **DO NOT include cost tracking** - No Get-LastCallCost function, no cost calculations, only time tracking
- For cost tracking with Claude, tell users to check https://console.anthropic.com for actual API usage
- When generating the final command for PowerShell:
- For Claude: Replace `[AI_COMMAND_WITH_PROMPT]` with the full claude command including prompt argument
- For Gemini/Grok: The piping is included in the template, just replace `[AI_COMMAND]` with the command after the pipe