frankbria / ralph-claude-code
- понедельник, 12 января 2026 г. в 00:00:02
Autonomous AI development loop for Claude Code with intelligent exit detection
Autonomous AI development loop with intelligent exit detection and rate limiting
Ralph is an implementation of the Geoffrey Huntley's technique for Claude Code that enables continuous autonomous development cycles he named after Ralph Wiggum. It enables continuous autonomous development cycles where Claude Code iteratively improves your project until completion, with built-in safeguards to prevent infinite loops and API overuse.
Install once, use everywhere - Ralph becomes a global command available in any directory.
Version: v0.9.8 - Active Development Core Features: Working and tested Test Coverage: 276 tests, 100% pass rate
--continue flag for context preservation--output-format, --allowed-tools, --no-continuev0.9.8 - Modern CLI for PRD Import
ralph_import.sh to use Claude Code CLI JSON output format--output-format json for structured responsesv0.9.7 - Session Lifecycle Management
--reset-session CLI flag for manual session resetv0.9.6 - JSON Output & Session Management
parse_json_response() to support Claude Code CLI JSON formatstore_session_id(), get_last_session_id(), should_resume_session()v0.9.5 - PRD Import Tests
ralph_import.sh PRD conversion scriptv0.9.4 - Project Setup Tests
setup.sh project initialization scriptv0.9.3 - Installation Tests
install.sh global installation scriptv0.9.2 - Prompt File Fix
--prompt-file CLI flag with -p flag-p "$(cat file)"build_claude_command()v0.9.1 - Modern CLI Commands (Phase 1.1)
--output-format json (default)--continue flag for cross-loop context--allowed-tools flagv0.9.0 - Circuit Breaker Enhancements
"is_error": false)Timeline to v1.0: ~4 weeks | Full roadmap | Contributions welcome!
Ralph has two phases: one-time installation and per-project setup.
INSTALL ONCE USE MANY TIMES
+-----------------+ +----------------------+
| ./install.sh | -> | ralph-setup project1 |
| | | ralph-setup project2 |
| Adds global | | ralph-setup project3 |
| commands | | ... |
+-----------------+ +----------------------+
Install Ralph globally on your system:
git clone https://github.com/frankbria/ralph-claude-code.git
cd ralph-claude-code
./install.shThis adds ralph, ralph-monitor, and ralph-setup commands to your PATH.
Note: You only need to do this once per system. After installation, you can delete the cloned repository if desired.
For each new project you want Ralph to work on:
# Convert existing PRD/specs to Ralph format (recommended)
ralph-import my-requirements.md my-project
cd my-project
# Review and adjust the generated files:
# - PROMPT.md (Ralph instructions)
# - @fix_plan.md (task priorities)
# - specs/requirements.md (technical specs)
# Start autonomous development
ralph --monitor# Create blank Ralph project
ralph-setup my-awesome-project
cd my-awesome-project
# Configure your project requirements manually
# Edit PROMPT.md with your project goals
# Edit specs/ with detailed specifications
# Edit @fix_plan.md with initial priorities
# Start autonomous development
ralph --monitorOnce Ralph is installed and your project is initialized:
# Navigate to any Ralph project and run:
ralph --monitor # Integrated tmux monitoring (recommended)
# Or use separate terminals:
ralph # Terminal 1: Ralph loop
ralph-monitor # Terminal 2: Live monitor dashboardRalph operates on a simple but powerful cycle:
PROMPT.md with your project requirementsRalph automatically stops when it detects:
@fix_plan.md marked completeRalph can convert existing PRDs, specifications, or requirement documents into the proper Ralph format using Claude Code.
# Convert a markdown PRD
ralph-import product-requirements.md my-app
# Convert a text specification
ralph-import requirements.txt webapp
# Convert a JSON API spec
ralph-import api-spec.json backend-service
# Let Ralph auto-name the project from filename
ralph-import design-doc.pdfRalph-import creates a complete project with:
The conversion is intelligent and preserves your original requirements while making them actionable for autonomous development.
Ralph-import uses modern Claude Code CLI features for improved reliability:
Note: These features require Claude Code CLI version 2.0.76 or later. Older versions will work with standard text output.
Ralph includes intelligent rate limiting and circuit breaker functionality:
# Default: 100 calls per hour
ralph --calls 50
# With integrated monitoring
ralph --monitor --calls 50
# Check current usage
ralph --statusThe circuit breaker automatically:
When Claude's 5-hour usage limit is reached, Ralph:
# Use custom prompt file
ralph --prompt my_custom_instructions.md
# With integrated monitoring
ralph --monitor --prompt my_custom_instructions.md# Set Claude Code execution timeout (default: 15 minutes)
ralph --timeout 30 # 30-minute timeout for complex tasks
# With monitoring and custom timeout
ralph --monitor --timeout 60 # 60-minute timeout
# Short timeout for quick iterations
ralph --verbose --timeout 5 # 5-minute timeout with progress# Enable detailed progress updates during execution
ralph --verbose
# Combine with other options
ralph --monitor --verbose --timeout 30Ralph maintains session context across loop iterations for improved coherence:
# Sessions are enabled by default with --continue flag
ralph --monitor # Uses session continuity
# Start fresh without session context
ralph --no-continue # Isolated iterations
# Reset session manually (clears context)
ralph --reset-session # Clears current session
# Check session status
cat .ralph_session # View current session file
cat .ralph_session_history # View session transition historySession Auto-Reset Triggers:
--reset-circuit)Sessions are persisted to .ralph_session with a 24-hour expiration. The last 50 session transitions are logged to .ralph_session_history for debugging.
Modify these variables in ~/.ralph/ralph_loop.sh:
Exit Detection Thresholds:
MAX_CONSECUTIVE_TEST_LOOPS=3 # Exit after 3 test-only loops
MAX_CONSECUTIVE_DONE_SIGNALS=2 # Exit after 2 "done" signals
TEST_PERCENTAGE_THRESHOLD=30 # Flag if 30%+ loops are test-onlyCircuit Breaker Thresholds:
CB_NO_PROGRESS_THRESHOLD=3 # Open circuit after 3 loops with no file changes
CB_SAME_ERROR_THRESHOLD=5 # Open circuit after 5 loops with repeated errors
CB_OUTPUT_DECLINE_THRESHOLD=70 # Open circuit if output declines by >70%Ralph creates a standardized structure for each project:
my-project/
├── PROMPT.md # Main development instructions for Ralph
├── @fix_plan.md # Prioritized task list (@ prefix = Ralph control file)
├── @AGENT.md # Build and run instructions
├── specs/ # Project specifications and requirements
│ └── stdlib/ # Standard library specifications
├── src/ # Source code implementation
├── examples/ # Usage examples and test cases
├── logs/ # Ralph execution logs
└── docs/generated/ # Auto-generated documentation
@fix_plan.md to guide Ralph's focusspecs/@fix_plan.md for prioritized task tracking@AGENT.md updated with build instructionsralph-monitor for live status updateslogs/ for detailed execution historystatus.json for programmatic accessnpm install -g @anthropic-ai/claude-codeSee TESTING.md for the comprehensive testing guide.
If you want to run the test suite:
# Install BATS testing framework
npm install -g bats bats-support bats-assert
# Run all tests (276 tests)
npm test
# Run specific test suites
bats tests/unit/test_rate_limiting.bats
bats tests/unit/test_exit_detection.bats
bats tests/unit/test_json_parsing.bats
bats tests/unit/test_cli_modern.bats
bats tests/unit/test_cli_parsing.bats
bats tests/unit/test_session_continuity.bats
bats tests/integration/test_loop_execution.bats
bats tests/integration/test_prd_import.bats
bats tests/integration/test_project_setup.bats
bats tests/integration/test_installation.bats
# Run error detection and circuit breaker tests
./tests/test_error_detection.sh
./tests/test_stuck_loop_detection.shCurrent test status:
Note on Coverage: Bash code coverage measurement with kcov has fundamental limitations when tracing subprocess executions. Test pass rate (100%) is the quality gate. See bats-core#15 for details.
# Ubuntu/Debian
sudo apt-get install tmux
# macOS
brew install tmux
# CentOS/RHEL
sudo yum install tmux# Integrated tmux monitoring (recommended)
ralph --monitor
# Manual monitoring in separate terminal
ralph-monitorShows real-time:
tmux Controls:
Ctrl+B then D - Detach from session (keeps Ralph running)Ctrl+B then ←/→ - Switch between panestmux list-sessions - View active sessionstmux attach -t <session-name> - Reattach to session# JSON status output
ralph --status
# Manual log inspection
tail -f logs/ralph.log@fix_plan.md for unclear or conflicting tasks--timeout value for complex operationstmux list-sessions and tmux attach to reconnectRalph is actively seeking contributors! We're working toward v1.0.0 with clear priorities and a detailed roadmap.
See CONTRIBUTING.md for the complete contributor guide including:
# Fork and clone
git clone https://github.com/YOUR_USERNAME/ralph-claude-code.git
cd ralph-claude-code
# Install dependencies and run tests
npm install
npm test # All 276 tests must passEvery contribution matters - from fixing typos to implementing major features!
This project is licensed under the MIT License - see the LICENSE file for details.
./install.sh # Install Ralph globally
./install.sh uninstall # Remove Ralph from system
./install.sh --help # Show installation helpralph [OPTIONS]
-h, --help Show help message
-c, --calls NUM Set max calls per hour (default: 100)
-p, --prompt FILE Set prompt file (default: PROMPT.md)
-s, --status Show current status and exit
-m, --monitor Start with tmux session and live monitor
-v, --verbose Show detailed progress updates during execution
-t, --timeout MIN Set Claude Code execution timeout in minutes (1-120, default: 15)
--output-format FORMAT Set output format: json (default) or text
--allowed-tools TOOLS Set allowed Claude tools (default: Write,Bash(git *),Read)
--no-continue Disable session continuity (start fresh each loop)
--reset-circuit Reset the circuit breaker
--circuit-status Show circuit breaker status
--reset-session Reset session state manuallyralph-setup project-name # Create new Ralph project
ralph-import prd.md project # Convert PRD/specs to Ralph project
ralph --monitor # Start with integrated monitoring
ralph --status # Check current loop status
ralph --verbose # Enable detailed progress updates
ralph --timeout 30 # Set 30-minute execution timeout
ralph --calls 50 # Limit to 50 API calls per hour
ralph --reset-session # Reset session state manually
ralph-monitor # Manual monitoring dashboardtmux list-sessions # View active Ralph sessions
tmux attach -t <name> # Reattach to detached session
# Ctrl+B then D # Detach from session (keeps running)Ralph is under active development with a clear path to v1.0.0. See IMPLEMENTATION_PLAN.md for the complete roadmap.
What's Delivered:
Test Coverage Breakdown:
Enhanced Testing
Core Features
Advanced Features & Polish
See IMPLEMENTATION_STATUS.md for detailed progress tracking.
Ralph is seeking contributors! See CONTRIBUTING.md for the complete guide. Priority areas:
Ready to let AI build your project? Start with ./install.sh and let Ralph take it from there!