How to run:
- install docker
- run
docker sandbox run --credentials host claudeand log in to Claude
Then, make script executable:
chmod +x ralph.shRun it:
./ralph.sh 10 This will run for 10 iterations.
How to run:
docker sandbox run --credentials host claude and log in to ClaudeThen, make script executable:
chmod +x ralph.shRun it:
./ralph.sh 10 This will run for 10 iterations.
| #!/bin/bash | |
| set -e | |
| if [ -z "$1" ]; then | |
| echo "Usage: $0 <iterations>" | |
| exit 1 | |
| fi | |
| # jq filter to extract streaming text from assistant messages | |
| stream_text='select(.type == "assistant").message.content[]? | select(.type == "text").text // empty | gsub("\n"; "\r\n") | . + "\r\n\n"' | |
| # jq filter to extract final result | |
| final_result='select(.type == "result").result // empty' | |
| for ((i=1; i<=$1; i++)); do | |
| tmpfile=$(mktemp) | |
| trap "rm -f $tmpfile" EXIT | |
| docker sandbox run --credentials host claude \ | |
| --verbose \ | |
| --print \ | |
| --output-format stream-json \ | |
| "<your prompt here>" \ | |
| | grep --line-buffered '^{' \ | |
| | tee "$tmpfile" \ | |
| | jq --unbuffered -rj "$stream_text" | |
| result=$(jq -r "$final_result" "$tmpfile") | |
| if [[ "$result" == *"<promise>COMPLETE</promise>"* ]]; then | |
| echo "Ralph complete after $i iterations." | |
| exit 0 | |
| fi | |
| done |