Model or dataset
frankbria/ralph-claude-code avatar
frankbria/ralph-claude-code

Ralph for Claude Code: Autonomous Development Loops with Intelligent Exit Detection

Autonomous AI development loop for Claude Code with intelligent exit detection

9,639 stars722 forksShellMIT

At a glance

What is it?
Ralph is a Bash-based loop runner that drives Claude Code through repeated development cycles and stops only when both a completion signal and an explicit EXIT_SIGNAL are present, protecting against infinite loops and runaway API costs.
Who is it for?
Ralph fits engineers who want Claude Code to iterate autonomously until a project goal is met, not just run a single session. The dual-condition exit gate makes it resilient to premature stops, but it also means the loop will keep running if Claude never produces EXIT_SIGNAL: true.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 2 days ago.
What is it written in?
Mainly Shell, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 30, 2026, and from our analysis. They are not legal advice.

Editorial analysis

The Problem Ralph Solves: Claude Code Does Not Loop Itself

Claude Code, Anthropic's terminal-native coding agent, runs one session at a time. When a session ends, whether because the task is done, an error occurs, or a rate limit is hit, the work stops. Engineers who want truly autonomous iteration, where the agent continues improving a project until a goal is fully met, have had to wire their own shell scripts around the CLI.

Ralph is Geoffrey Huntley's technique for doing that, implemented as a set of installable Bash scripts. It wraps each Claude Code invocation, reads the output to detect whether the session completed successfully or stalled, and decides whether to launch another iteration or exit. The README credits the approach to Huntley's original concept, named after Ralph Wiggum from The Simpsons.

The target user is a developer who has a well-defined project goal in CLAUDE.md and wants the agent to keep working on it across multiple sessions without manual intervention. It is not a tool for exploratory or conversational Claude Code use.

How the Dual-Condition Exit Gate Works

The central mechanism in Ralph is what the README calls the dual-condition exit gate. A loop iteration ends and triggers a real exit only when both of two conditions are true at the same time: the session output contains completion indicators (phrases or patterns that suggest the task is done), AND Claude has emitted EXIT_SIGNAL: true explicitly.

Before version 0.9.9, Ralph would exit on completion indicators alone, which caused premature stops when Claude described progress in language that resembled a completion. The current gate requires Claude to actively assert the exit intent. The README documents this in the project status section.

For JSON output mode (using the --output-format flag that passes Claude Code's structured output), Ralph parses EXIT_SIGNAL from the JSON directly. When JSON parsing fails or the flag is absent, it falls back to text parsing. The README also documents a safety circuit breaker: if five consecutive completion indicators accumulate without a confirmed exit, Ralph forces the loop to stop anyway, preventing a scenario where EXIT_SIGNAL: true is never produced.

The response analyzer applies semantic understanding and a two-stage error filter to distinguish genuine completion signals from stuck loops, where the same error message repeats across iterations without progress.

Installing Ralph and Running a First Autonomous Cycle

The README describes Ralph as install-once, use-everywhere. The install script sets up a global command.

Clone the repository and run the installer:

bash
git clone https://github.com/frankbria/ralph-claude-code.git
cd ralph-claude-code
bash install.sh

After installation, ralph is on your PATH and can be called from any project directory. To enable Ralph for a specific project, the README points to the ralph-enable wizard:

bash
ralph-enable

This interactive five-phase wizard detects the project type (TypeScript, Python, Rust, or Go) and framework (Next.js, FastAPI, Django, and others), then generates a .ralphrc configuration file and any needed scaffolding. For CI environments or non-interactive use, ralph-enable-ci performs the same setup without prompts.

Once a project is configured, launch a loop with:

bash
ralph

The loop starts, calls the Claude Code CLI, monitors the output, and automatically relaunches sessions. Add --live to see Claude Code's output in real time as it streams:

bash
ralph --live

To simulate a full loop run without making API calls, useful for testing your configuration:

bash
ralph --dry-run

If a previous session has a known session ID and you want continuity, pass it with --resume rather than --continue, which the README notes was the old flag that caused session hijacking:

bash
ralph --resume <session_id>

Rate Limiting, Circuit Breakers, and API Limit Handling

Ralph enforces a rate limit of 100 calls per hour by default, with the counter resetting on the hour. This cap is configurable through environment variables that the README references in the circuit breaker section. The circuit breaker itself tracks consecutive errors and stuck patterns: if the loop detects the same error state repeating without progress, it halts before exhausting the API budget.

API rate limit handling went through several iterations in recent versions. Version 0.11.5 introduced a three-layer detection stack for the five-hour API limit that Claude Code imposes:

1. A timeout guard that prevents a process exit (code 124) from being misidentified as an API limit event. 2. Structural JSON detection for the rate_limit_event field in Claude Code's JSON output. 3. A filtered text fallback for cases where JSON output is unavailable.

In unattended mode, when the five-hour API limit is hit, Ralph auto-waits rather than exiting, so an overnight run does not abort at the limit boundary. The README describes this behavior in the v0.11.5 release notes.

Log rotation is also handled automatically: ralph.log rotates at 10 MB and keeps four archived files. For monitoring multiple simultaneous Ralph instances, tmux integration is available.

Metrics are tracked per loop iteration in JSON Lines format, accessible through:

bash
ralph-stats

Project Layout and Configuration with .ralphrc

Since v0.10.0, all Ralph-specific files live in a .ralph/ subfolder within the project directory, leaving the project root clean for source files, README, and user content. Existing projects on the older layout can be upgraded:

bash
ralph-migrate

The .ralphrc file stores per-project settings: allowed tools, output format, session timeout (default 24 hours), and circuit breaker thresholds. Both ralph-setup and ralph-enable generate an identical .ralphrc, so starting from either entry point produces a consistent result.

GitHub issues can be imported directly as task input:

bash
ralph-import --github-issue

The importer supports metadata filters (labels, title, assignee, milestone, state) and has first, interactive, and priority selection modes. The --dry-run flag on ralph-import previews the import without writing any files, which is documented in the v0.11.0 notes.

For automatic code backups during long runs, the --backup flag creates git branches before each loop iteration, and --rollback restores from a named backup:

bash
ralph --backup
ralph --rollback <branch_name>

Desktop notifications on macOS and Linux are available with --notify, and fire on key loop events.

Docker Sandbox Mode and Cross-Platform Considerations

The repository ships a Dockerfile that builds a sandbox image for running Claude Code inside a container while Ralph itself remains on the host. The Dockerfile installs node:20-slim, common development tooling (git, jq, python3, curl), and the Claude Code CLI via npm. The build instruction is:

bash
docker build -t ralph-sandbox .

In sandbox mode, invoked with --sandbox docker, Ralph's loop calls Claude Code through docker exec per iteration, with the project directory bind-mounted at /workspace. A custom image can be built by extending ralph-sandbox and adding your own toolchain.

Cross-platform compatibility has been an ongoing concern. Version 0.11.4 fixed date command incompatibilities between macOS and GNU/Linux caused by Homebrew coreutils, and version 0.11.5 replaced bash 3.x lowercase substitution (${,,}) with POSIX tr for compatibility with macOS's default Bash.

Windows is not supported natively; the README does not document a Windows path. The docker sandbox approach could be adapted for Windows with WSL, but the README does not describe that configuration.

When Ralph Is Not the Right Tool and What to Consider Instead

Ralph introduces real API costs that accumulate with every loop iteration. If your project goal is not expressed in a form that Claude Code can test and signal completion on, Ralph will loop until the circuit breaker or rate limit stops it, spending credits without making useful progress.

The tool also assumes bash is available. The scripts rely on bash-specific features and external tools (jq, tmux for monitoring), so minimal container environments without those dependencies need extra setup.

For tasks that are genuinely exploratory, where the developer needs to review each step and redirect, Ralph's autonomous model is counterproductive. The tool is designed for defined, repeatable work where the exit criteria are clear.

An alternative approach is the official --continue flag in Claude Code combined with a shell loop written in-house. That gives the developer complete control over exit conditions and rate behavior. The trade-off is that all the safeguards Ralph provides: the dual-condition gate, the circuit breaker, the session expiration handling, and the API limit recovery, have to be reimplemented. Ralph packages those concerns into a tested, versioned tool.

The repository has 784 tests run with bats (Bash Automated Testing System), covering unit and integration scenarios. The project uses GitHub Actions for CI.

Editorial conclusion

Ralph fits engineers who want Claude Code to iterate autonomously until a project goal is met, not just run a single session. The dual-condition exit gate makes it resilient to premature stops, but it also means the loop will keep running if Claude never produces EXIT_SIGNAL: true. Before adopting Ralph, verify that your CLAUDE.md gives Claude Code explicit, testable completion criteria it can signal against. The MIT license and pure Bash runtime mean the entire implementation is readable before you commit to running it. The absence of GitHub releases means you are tracking main directly; check the changelog in IMPLEMENTATION_STATUS.md before updating.

Frequently asked questions

What is a Ralph Loop in Claude Code?

A Ralph Loop is an autonomous development cycle where Ralph repeatedly calls the Claude Code CLI, checks the output for both completion indicators and an explicit EXIT_SIGNAL, and relaunches the session if neither condition is met. It automates the iteration that a developer would otherwise manage manually.

Why is it called the Ralph Wiggum Loop?

The README states that Ralph is an implementation of a technique developed by Geoffrey Huntley, who named the looping approach after Ralph Wiggum from The Simpsons. The name refers to the character's tendency to persist regardless of the situation.

What is the AI Ralph technique?

The Ralph technique, as described in the repository, involves running an AI coding agent in a loop with safeguards that prevent infinite execution: a dual-condition exit gate requiring both completion signals and an explicit exit assertion, a rate limiter, and a circuit breaker that forces a stop on repeated errors.

How do I install Ralph for Claude Code?

Clone the repository and run bash install.sh from the project root. The installer registers ralph as a global command available in any directory. Use ralph-enable inside a specific project to generate the .ralphrc configuration file.

How do I run Ralph for Claude Code after setup?

After installing and running ralph-enable in a project, invoke ralph from the project directory to start the loop. Add --live for real-time output streaming, --dry-run to simulate without API calls, and --backup to create automatic git backup branches before each iteration.

Official sources

  1. frankbria/ralph-claude-code on GitHub
  2. Issues
  3. License: MIT
  4. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/frankbria-ralph-claude-code.svg)](https://hysenlabs.com/projects/frankbria-ralph-claude-code)