A bash function for running Claude CLI in a loop with automatic escape phrase detection.
- Run Claude prompts multiple times in succession
- Automatic stopping when an escape phrase is detected in output
- Configurable timeout per iteration
- Docker container mode (default) or local mode running directly on the host
- Graceful interrupt handling (single Ctrl-C waits for current job, double Ctrl-C kills immediately)
Add the following to your ~/.bashrc or ~/.bash_profile:
source /path/to/ralph/bash_ralph.shThen reload your shell:
source ~/.bashrcecho "your prompt here" | ralph <count> <escape_phrase> [options] [claude_args...]count- Number of iterations to runescape_phrase- Phrase to detect in output to stop early
--timeout <seconds>- Timeout per iteration (default: 600 seconds)--local- Run Claude directly on the host instead of in a Docker container
Run a prompt 5 times, stopping early if "DONE" appears in the output:
echo "Write a haiku about coding" | ralph 5 "DONE"Run with a custom timeout of 5 minutes:
echo "Solve this complex problem" | ralph 10 "SOLUTION FOUND" --timeout 300Run in local mode (without Docker):
echo "Quick task" | ralph 3 "COMPLETE" --localPass additional arguments to Claude:
echo "Help me with this" | ralph 5 "FINISHED" --model claude-3-opusBy default, ralph runs Claude inside a Docker container using ~/git/claude-container/docker-compose.yml. If this file doesn't exist, ralph automatically falls back to local mode.
The code to build the optional container can be found at https://github.com/Tipmethewink/claude-container
To use the containerized mode, ensure you have:
- Docker and Docker Compose installed
- A valid
docker-compose.ymlat~/git/claude-container/docker-compose.yml
- Single Ctrl-C: Waits for the current iteration to complete, then stops
- Double Ctrl-C: Immediately kills the current job and any running containers