Writes ralph loops for you that you can copy and paste
by @walkamolee
Generate ready-to-run shell loop commands for Claude Code, Gemini CLI, or Grok CLI, customized by AI tool, model, shell, complexity, and loop features.
clawhub install ralph-loop-writer📖 About This Skill
name: 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: - AskUserQuestion - Write - Read
Ralph Command Generator
Generate optimized loop commands for automating Claude Code, Gemini CLI, or Grok CLI with PROMPT.md.
Step 1: Choose AI Tool
Use AskUserQuestion:
Store the choice for later.
Step 2: Choose Model
Use AskUserQuestion based on AI tool choice:
If Claude Code selected:
If Gemini CLI selected:
If Grok CLI selected:
Store the choice for later.
Step 3: Choose Operating System
Use AskUserQuestion:
Store the choice for later.
Step 4: Choose Complexity Level
Use AskUserQuestion:
Step 5: Choose Loop Type (Based on Complexity)
If Simple:
Use AskUserQuestion:If Intermediate:
Use AskUserQuestion:If Advanced:
Use AskUserQuestion:Step 6: Gather Parameters
Based on selected features, ask for values:
If fixed iterations selected:
If time limit selected:
If delay selected:
If file monitoring selected:
Step 7: Generate Command
Build the appropriate command based on: 1. AI tool choice (Claude or Gemini) 2. Model choice 3. Shell choice (PowerShell, CMD, Bash) 4. Complexity level 5. Selected features 6. Parameter values
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-betaCommand Templates
IMPORTANT - 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!"
Step 8: Create Command File
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 CommandGenerated: [timestamp]
Shell: [PowerShell/CMD/Bash]
Command
[shell-type]
[THE ACTUAL COMMAND]
echo $null > STOP.txtHow to run
1. Make sure you have a PROMPT.md file in this directory 2. Copy the command above 3. Paste into your [PowerShell/CMD/Bash] terminal 4. Press Enter
How to stop
Press Ctrl+C at any time [- OR create STOP.txt:/touch STOP.txt] (if stop file enabled)What it does
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:
RalphPowerShellComands.md - Full PowerShell reference
RalphWindowsCommands.md - Full CMD reference
RalphLinuxCommands.md - Full Bash reference
RalphGemini.md - Full Gemini CLI guide
RalphGrok.md - Full Grok CLI guide
Notes
. Piping does NOT work with claude -p. or Get-Content PROMPT.md -Raw | grok-auto. flag
- With model: claude -p (Get-Content PROMPT.md -Raw) --model
- 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
- 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
- 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
📋 Tips & Best Practices
claude -p (Get-Content PROMPT.md -Raw) --dangerously-skip-permissions. Piping does NOT work with claude -p.Get-Content PROMPT.md -Raw | gemini --yolo or Get-Content PROMPT.md -Raw | grok-auto.--model flagclaude -p (Get-Content PROMPT.md -Raw) --dangerously-skip-permissions
- With model: claude -p (Get-Content PROMPT.md -Raw) --model --dangerously-skip-permissions
- Models: haiku, sonnet, opus
Get-Content PROMPT.md -Raw | gemini --yolo
- With model: Get-Content PROMPT.md -Raw | gemini --model --yolo
- Models: gemini-3-flash, gemini-3-pro, gemini-2.5-flash, gemini-2.5-pro
- Note: -p flag is deprecated in Gemini
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
- 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)
Get-Date (PowerShell) or date +%s (Bash)ralphcommand-YYYY-MM-DD-HHMMSS.md[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