autonomous iterative development loop with claude code cli orchestration
Implements a continuous execution loop that repeatedly invokes the Claude Code CLI with 15-minute timeouts, analyzes responses for completion signals, and automatically re-enters the loop for multi-step development tasks. The loop integrates five quality gates: rate limiting checks via can_make_call(), circuit breaker pre-checks via should_halt_execution() to detect stagnation, exit detection via should_exit_gracefully() to identify task completion, Claude execution with timeout enforcement, and post-execution analysis via analyze_response() and record_loop_result() to evaluate progress and decide whether to continue or exit.
Unique: Implements a five-stage quality gate system (rate limiting, circuit breaker, exit detection, execution, analysis) with explicit stagnation detection via circuit_breaker.sh pattern matching, rather than naive retry loops. The 15-minute timeout is enforced at the shell level using timeout command, preventing hung Claude Code processes from blocking the loop indefinitely.
vs alternatives: More sophisticated than simple shell scripts that call Claude Code once; includes built-in safety mechanisms (rate limiting, circuit breaker, exit detection) that prevent runaway API costs and infinite loops, which are critical for autonomous agents.
intelligent exit detection with multi-signal analysis
Analyzes Claude Code responses using the should_exit_gracefully() function to detect task completion by evaluating multiple signals: explicit completion markers in Claude's output, convergence detection (no meaningful changes between iterations), error state analysis, and timeout conditions. The response_analyzer.sh library module implements two-stage error filtering to distinguish between recoverable errors (retry) and terminal errors (exit), using pattern matching against known Claude Code failure modes and success indicators.
Unique: Implements two-stage error filtering (response_analyzer.sh) that distinguishes recoverable errors from terminal errors using pattern matching against known Claude Code failure modes, rather than treating all errors identically. Convergence detection compares iteration outputs to detect stagnation (no meaningful changes between runs), preventing infinite loops on stuck tasks.
vs alternatives: More nuanced than simple iteration counters or timeout-based exits; analyzes actual task progress and Claude's explicit signals to make intelligent termination decisions, reducing wasted API calls while ensuring tasks aren't terminated prematurely.
claude code cli invocation with timeout enforcement and output capture
Implements execute_claude_code() function that invokes the Claude Code CLI with a 15-minute timeout using the timeout command, captures stdout/stderr to temporary files, and parses the output to extract generated code and status information. The function handles timeout scenarios (kills the process and logs timeout error), exit codes from Claude Code, and streams output to both log files and the terminal for real-time visibility.
Unique: Wraps Claude Code CLI invocation with explicit timeout enforcement using the timeout command, preventing hung processes from blocking the loop indefinitely. Output is captured to temporary files and parsed for analysis, enabling downstream error detection and exit decision logic.
vs alternatives: More robust than direct Claude Code invocation without timeouts; prevents runaway processes that could consume resources indefinitely. Output capture enables detailed analysis and logging without requiring Claude Code to support structured output formats.
response analysis and error classification with pattern matching
Implements response_analyzer.sh library module that performs two-stage error filtering on Claude Code responses: first stage identifies error patterns (compilation failures, infinite loops, resource exhaustion) using regex matching against known failure modes; second stage classifies errors as recoverable (retry) or terminal (exit) based on error type and context. The analyzer extracts key information from Claude's output (files modified, errors encountered, progress indicators) and returns structured analysis for decision-making.
Unique: Implements two-stage error filtering with explicit classification of errors as recoverable vs. terminal, rather than treating all errors identically. Pattern matching against known Claude Code failure modes enables fast identification of specific error types without requiring structured output from Claude.
vs alternatives: More nuanced than simple error/success binary classification; distinguishes between errors that Claude can fix (retry) and unrecoverable errors (exit), reducing wasted API calls on impossible tasks.
rate limiting and api quota management with hourly enforcement
Implements rate limiting via the can_make_call() function that tracks API calls in state files and enforces configurable hourly quotas before invoking Claude Code. The system records call timestamps in ~/.ralph/state/call_history.json and checks against MAX_CALLS_PER_HOUR configuration parameter using date_utils.sh for timestamp calculations. If the hourly quota is exceeded, the loop sleeps until the oldest call in the window expires, then retries.
Unique: Implements sliding-window rate limiting using local state files (call_history.json) with timestamp-based expiration, rather than simple counters. The can_make_call() function calculates the oldest call timestamp and sleeps until it expires from the window, enabling automatic quota recovery without manual intervention.
vs alternatives: More flexible than hard API key limits; allows per-project or per-task quota enforcement without modifying Anthropic account settings. Sliding-window approach is more accurate than fixed hourly buckets, preventing burst behavior at hour boundaries.
circuit breaker pattern for stagnation detection and graceful degradation
Implements a circuit breaker via should_halt_execution() and circuit_breaker.sh library module that detects when Ralph is stuck in a loop making no meaningful progress. The circuit breaker tracks consecutive iterations with no file changes or identical responses, maintains a state machine with OPEN/CLOSED/HALF_OPEN states, and triggers exit when stagnation threshold is exceeded. Pattern matching in circuit_breaker.sh identifies known failure modes (compilation errors, infinite loops, resource exhaustion) and immediately opens the circuit without waiting for iteration count threshold.
Unique: Implements a three-state circuit breaker (OPEN/CLOSED/HALF_OPEN) with pattern matching for known failure modes, rather than simple iteration counters. The circuit breaker can immediately OPEN on detection of specific error patterns (e.g., 'compilation failed', 'infinite loop detected'), without waiting for stagnation threshold, enabling fast failure on unrecoverable errors.
vs alternatives: More sophisticated than max-iteration limits; detects actual stagnation (no progress) rather than just elapsed time. Pattern matching for known failure modes enables immediate exit on unrecoverable errors, preventing wasted API calls on impossible tasks.
project initialization with template system and prd import
Provides ralph-setup command that initializes a new Ralph project by copying template files (PROMPT.md, @fix_plan.md, @AGENT.md, .ralph.config) from ~/.ralph/templates/ to the target directory, creating .git repository, and setting up directory structure. Additionally, ralph-import command parses product requirement documents (PRDs) using Claude Code to automatically generate PROMPT.md and @fix_plan.md templates, reducing manual setup time for new projects.
Unique: Combines two-phase initialization (global install.sh + per-project ralph-setup) with optional PRD-to-PROMPT conversion via ralph-import, leveraging Claude Code to parse documents and generate task definitions. Template system enables consistent project structure across multiple Ralph instances.
vs alternatives: Faster than manual project setup; PRD import feature eliminates manual translation of requirements into Claude instructions, reducing setup friction for teams with existing documentation.
live monitoring dashboard with real-time log tailing and status display
Provides ralph-monitor command that displays a live dashboard showing Ralph's current execution status, recent log entries, progress metrics (iterations completed, files modified, API calls made), and real-time log tailing from ~/.ralph/logs/. The monitor uses shell-based UI rendering with periodic updates (default 2-second interval) to show loop progress without requiring separate terminal windows or external monitoring tools.
Unique: Implements a shell-based live dashboard using terminal control sequences (ANSI colors, cursor positioning) rather than external monitoring tools or web UIs. Periodic polling of log files and state files enables real-time updates without requiring Ralph to emit structured events.
vs alternatives: Simpler than external monitoring tools (Prometheus, Grafana) for single-machine deployments; no additional dependencies or configuration required. Real-time log tailing provides immediate visibility into agent behavior without manual log file inspection.
+4 more capabilities