Autonomous AI development loop for Claude Code with intelligent exit detection
Find a file
frankbria 6d64be9b01 Transform Ralph into global command system
Major architectural change to make Ralph available as global commands:

🌟 New Global Installation System:
- Add install.sh script for global installation to ~/.local/bin
- Creates ralph, ralph-monitor, ralph-setup global commands
- Installs templates and scripts to ~/.ralph/ directory
- Automatic dependency checking and PATH configuration

🚀 Enhanced User Experience:
- ralph-setup my-project (run from anywhere, no directory constraints)
- ralph --monitor (start from any project directory)
- ralph-monitor (global monitoring command)
- No more ../ralph_loop.sh relative path requirements

🔧 Improved Architecture:
- Global template system in ~/.ralph/templates/
- Smart path detection (global commands vs local scripts)
- Maintains backward compatibility during transition
- Clean separation of installation vs project files

📚 Updated Documentation:
- All examples now use global commands (ralph vs ../ralph_loop.sh)
- Clear installation instructions with ./install.sh
- Global command reference in CLAUDE.md
- Streamlined Quick Start workflow

This makes Ralph much more professional and user-friendly by eliminating
directory structure requirements and providing standard Unix command experience.
2025-08-27 09:39:43 -07:00
docs/generated Add directory structure with .gitkeep files 2025-08-27 09:27:33 -07:00
examples Add directory structure with .gitkeep files 2025-08-27 09:27:33 -07:00
logs Add directory structure with .gitkeep files 2025-08-27 09:27:33 -07:00
specs/stdlib Add directory structure with .gitkeep files 2025-08-27 09:27:33 -07:00
src Add directory structure with .gitkeep files 2025-08-27 09:27:33 -07:00
templates Add directory structure with .gitkeep files 2025-08-27 09:27:33 -07:00
.gitignore Add directory structure with .gitkeep files 2025-08-27 09:27:33 -07:00
CLAUDE.md Transform Ralph into global command system 2025-08-27 09:39:43 -07:00
create_files.sh Fix create_files.sh syntax errors and complete Ralph implementation 2025-08-27 09:15:00 -07:00
install.sh Transform Ralph into global command system 2025-08-27 09:39:43 -07:00
LICENSE Initial commit 2025-08-27 09:03:46 -07:00
ralph_loop.sh Transform Ralph into global command system 2025-08-27 09:39:43 -07:00
ralph_monitor.sh Fix create_files.sh syntax errors and complete Ralph implementation 2025-08-27 09:15:00 -07:00
README.md Transform Ralph into global command system 2025-08-27 09:39:43 -07:00
setup.sh Fix create_files.sh syntax errors and complete Ralph implementation 2025-08-27 09:15:00 -07:00

Ralph for Claude Code

Autonomous AI development loop with intelligent exit detection and rate limiting

Ralph is an implementation of the Ralph technique specifically designed for Claude Code. 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.

🌟 Features

  • 🔄 Autonomous Development Loop - Continuously executes Claude Code with your project requirements
  • 🛡️ Intelligent Exit Detection - Automatically stops when project objectives are complete
  • Rate Limiting - Built-in API call management with hourly limits and countdown timers
  • 📊 Live Monitoring - Real-time dashboard showing loop status, progress, and logs
  • 🎯 Task Management - Structured approach with prioritized task lists and progress tracking
  • 🔧 Project Templates - Quick setup for new projects with best-practice structure
  • 📝 Comprehensive Logging - Detailed execution logs with timestamps and status tracking

🚀 Quick Start

1. Install Ralph Globally

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

2. Create Your First Project

# Run from anywhere - no need to be in specific directory
ralph-setup my-awesome-project
cd my-awesome-project

3. Configure Your Project

Edit the generated files:

  • PROMPT.md - Define your project requirements and objectives
  • specs/ - Add detailed specifications and requirements
  • @fix_plan.md - Set initial priorities and tasks

4. Start the Ralph Loop

# Recommended: Start with integrated tmux monitoring (requires tmux)
ralph --monitor

# Alternative: Manual monitoring (two separate terminals)
ralph                    # Terminal 1: Ralph loop
ralph-monitor           # Terminal 2: Live monitor

📖 How It Works

Ralph operates on a simple but powerful cycle:

  1. 📋 Read Instructions - Loads PROMPT.md with your project requirements
  2. 🤖 Execute Claude Code - Runs Claude Code with current context and priorities
  3. 📊 Track Progress - Updates task lists and logs execution results
  4. 🔍 Evaluate Completion - Checks for exit conditions and project completion signals
  5. 🔄 Repeat - Continues until project is complete or limits are reached

Intelligent Exit Detection

Ralph automatically stops when it detects:

  • All tasks in @fix_plan.md marked complete
  • 🎯 Multiple consecutive "done" signals from Claude Code
  • 🧪 Too many test-focused loops (indicating feature completeness)
  • 📋 Strong completion indicators in responses

🛠️ Configuration

Rate Limiting

# Default: 100 calls per hour
ralph --calls 50

# With integrated monitoring
ralph --monitor --calls 50

# Check current usage
ralph --status

Custom Prompts

# Use custom prompt file
ralph --prompt my_custom_instructions.md

# With integrated monitoring
ralph --monitor --prompt my_custom_instructions.md

Exit Thresholds

Modify these variables in ~/.ralph/ralph_loop.sh:

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-only

📁 Project Structure

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

🎯 Best Practices

Writing Effective Prompts

  1. Be Specific - Clear requirements lead to better results
  2. Prioritize - Use @fix_plan.md to guide Ralph's focus
  3. Set Boundaries - Define what's in/out of scope
  4. Include Examples - Show expected inputs/outputs

Project Specifications

  • Place detailed requirements in specs/
  • Use @fix_plan.md for prioritized task tracking
  • Keep @AGENT.md updated with build instructions
  • Document key decisions and architecture

Monitoring Progress

  • Use ralph-monitor for live status updates
  • Check logs in logs/ for detailed execution history
  • Monitor status.json for programmatic access
  • Watch for exit condition signals

🔧 System Requirements

  • Bash 4.0+ - For script execution
  • Claude Code CLI - npx @anthropic/claude-code
  • tmux - Terminal multiplexer for integrated monitoring (recommended)
  • jq - JSON processing for status tracking
  • Git - Version control (projects are initialized as git repos)
  • Standard Unix tools - grep, date, etc.

Installing tmux

# Ubuntu/Debian
sudo apt-get install tmux

# macOS
brew install tmux

# CentOS/RHEL
sudo yum install tmux

📊 Monitoring and Debugging

Live Dashboard

# Integrated tmux monitoring (recommended)
ralph --monitor

# Manual monitoring in separate terminal
ralph-monitor

Shows real-time:

  • Current loop count and status
  • API calls used vs. limit
  • Recent log entries
  • Rate limit countdown

tmux Controls:

  • Ctrl+B then D - Detach from session (keeps Ralph running)
  • Ctrl+B then ←/→ - Switch between panes
  • tmux list-sessions - View active sessions
  • tmux attach -t <session-name> - Reattach to session

Status Checking

# JSON status output
ralph --status

# Manual log inspection
tail -f logs/ralph.log

Common Issues

  • Rate Limits - Ralph automatically waits and displays countdown
  • Stuck Loops - Check @fix_plan.md for unclear or conflicting tasks
  • Early Exit - Review exit thresholds if Ralph stops too soon
  • Missing Dependencies - Ensure Claude Code CLI and tmux are installed
  • tmux Session Lost - Use tmux list-sessions and tmux attach to reconnect

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Test with ./install.sh and sample projects
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Claude Code - The AI coding assistant that powers Ralph
  • Aider - Original Ralph technique implementation

Ready to let AI build your project? Start with ./install.sh and let Ralph take it from there! 🚀