Implementation of the Ralph Wiggum technique for iterative, self-referential AI development loops with GitHub Copilot CLI.
Author: Sepehr Bayat
- What is Ralph?
- How It Works
- Quick Start
- Dev Container
- Copilot CLI Integration
- Custom Agents
- Auto-Agents
- Skills
- Hooks
- Security Considerations
- Network Resilience
- Quality Gates
- Usage Modes
- Commands Reference
- Best Practices
- Field Notes (Real-World Trial)
- File Structure
- MCP Server Integration
- Cross-Platform Support
- Testing
- Philosophy
- Credits
Ralph is a development methodology based on continuous AI agent loops. As Geoffrey Huntley describes it: "Ralph is a Bash loop" - a simple while true that repeatedly feeds an AI agent a prompt, allowing it to iteratively improve its work until completion.
The technique is named after Ralph Wiggum from The Simpsons, embodying the philosophy of persistent iteration despite setbacks.
This implementation is fully compatible with GitHub Copilot CLI, supporting all its features including custom agents, plan mode, MCP servers, and context management.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Ralph Loop β
β β
β ββββββββββββ ββββββββββββββ ββββββββββββ β
β β Prompt ββββββΆβ copilot ββββββΆβ Work β β
β β File β β -p ... β β on Task β β
β ββββββββββββ ββββββββββββββ ββββββ¬ββββββ β
β β² β β
β β ββββββββββββ β β
β βββββββββββββ Check βββββββββββββββ β
β β Complete β β
β ββββββ¬ββββββ β
β β β
β ββββββββββββ΄βββββββββββ β
β β β β
β βΌ βΌ β
β [Not Done] [Done! β
] β
β Continue Exit β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The Completion Promise is how the AI signals it's done:
<promise>DONE</promise>
- Only output when task is GENUINELY complete
- The statement must be TRUE
- Never lie to exit the loop
# Install GitHub CLI
# macOS
brew install gh
# Linux
sudo apt install gh
# Windows
winget install GitHub.cli
# Install GitHub Copilot CLI
# Recommended:
# npm install -g @github/copilot
# See: https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli
# Authenticate
gh auth login
# Verify Copilot CLI access
copilot --help
# β οΈ If GITHUB_TOKEN is set, Copilot CLI may fail auth (401).
# Unset it for CLI usage:
# unset GITHUB_TOKENThe easiest way to get started is using VS Code Dev Containers. This ensures a consistent development environment across all platforms.
Prerequisites:
Quick Start:
- Clone the repository
- Open in VS Code
- Click "Reopen in Container" when prompted (or run
Dev Containers: Reopen in Containerfrom command palette) - Wait for container to build (~2-3 minutes first time)
- Done! All tools pre-installed.
git clone https://github.com/sepehrbayat/copilot-ralph-mode.git
code copilot-ralph-mode
# VS Code will prompt to reopen in containerDev Container Features:
- β Python 3.11 with all dependencies
- β GitHub CLI pre-configured
- β
Zsh with helpful aliases (
ralph,test,lint) - β VS Code extensions auto-installed
- β Git configured with useful aliases
- β Consistent environment on Windows, macOS, Linux
macOS/Linux:
curl -fsSL https://raw.githubusercontent.com/sepehrbayat/copilot-ralph-mode/main/install.sh | bashWindows (PowerShell):
irm https://raw.githubusercontent.com/sepehrbayat/copilot-ralph-mode/main/install.ps1 | iexWindows (CMD): Download and run install.cmd
# Clone the repository
git clone https://github.com/sepehrbayat/copilot-ralph-mode.git
cd copilot-ralph-mode
# Make scripts executable (Linux/macOS)
chmod +x ralph_mode.py ralph-loop.sh
# Install development dependencies (optional)
pip install -r requirements-dev.txtpip install copilot-ralph-modegit clone https://github.com/sepehrbayat/copilot-ralph-mode.git
cd copilot-ralph-mode
make install # Install to ~/.local/bin
make dev-install # Install with dev dependencies# 1. Enable Ralph mode with a task
python3 ralph_mode.py enable "Create a Python calculator with unit tests" \
--max-iterations 20 \
--completion-promise "DONE"
# 2. Run the loop
./ralph-loop.sh run
# Or with a specific agent
./ralph-loop.sh run --agent ralphThat's it! Ralph will iterate until the task is complete.
Ralph Mode is fully integrated with GitHub Copilot CLI features.
While running Ralph loops, you can use these Copilot CLI commands:
| Command | Description |
|---|---|
/context |
View current token usage |
/compact |
Compress conversation history |
/usage |
View session statistics |
/review |
Review code changes |
/agent |
Select a custom agent |
/cwd |
Change working directory |
/add-dir |
Add a trusted directory |
/resume |
Resume a previous session |
/mcp add |
Add an MCP server |
/delegate |
Hand off to Copilot coding agent |
Press Shift+Tab during an interactive session to enter plan mode - collaborate on implementation plans before writing code.
Use @ to reference files in prompts:
Fix the bug in @src/auth/login.ts
Explain @config/ci/ci-required-checks.yml
Hand off complex tasks to Copilot coding agent:
/delegate complete the API integration tests
& fix all failing edge cases
Copilot CLI automatically manages context. Commands for context control:
# View current token usage
/context
# Compress conversation history when context fills up
/compact
# View session statistics
/usage# Resume the most recent session
copilot --continue
# Or cycle through previous sessions
copilot --resumeRalph Mode uses these permission flags:
# Enable all permissions (for trusted environments)
./ralph-loop.sh run --allow-all
# Pre-approve specific URLs
./ralph-loop.sh run --allow-url github.com
# Restrict permissions
./ralph-loop.sh run --no-allow-tools --no-allow-pathsRealβworld lessons learned from running Ralph on a public repository are captured here:
Highlights include Copilot CLI install pitfalls, strict task scoping, and PR hygiene for upstream contributions.
Ralph Mode includes custom agents optimized for different tasks.
| Agent | Description | Use For |
|---|---|---|
ralph |
Main iteration agent | Ralph Mode loop work |
plan |
Planning agent | Creating implementation plans |
code-review |
Review agent | Reviewing changes |
task |
Task runner | Running tests and builds |
explore |
Exploration agent | Quick codebase questions |
agent-creator |
Meta-agent | Creating new specialized agents |
# Use the ralph agent for iterations
./ralph-loop.sh run --agent ralph
# Use plan agent to create a plan first
copilot --agent=plan --prompt "Create a plan for implementing user authentication"
# Use task agent to run tests
copilot --agent=task --prompt "Run all tests and summarize results"Create agent profiles in .github/agents/:
# my-agent.md
## Description
What this agent does.
## Prompts
Instructions for behavior.
## Tools
Which tools it can use.
## Behavior
How it should act.Auto-Agents is a powerful feature that allows Ralph to dynamically create specialized sub-agents during task execution.
python ralph_mode.py enable "Complex refactoring task" \
--max-iterations 20 \
--auto-agents \
--completion-promise "DONE"When --auto-agents is enabled:
- Agent Creator Available: The
@agent-creatormeta-agent provides guidance - Dynamic Creation: Ralph can create new
.agent.mdfiles in.github/agents/ - Tracking: Each created agent is tracked in
state.jsonundercreated_agents - Invocation: Created agents can be invoked with
@agent-name <task>
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. Ralph encounters complex testing subtask β
β β
β 2. Creates .github/agents/test-specialist.agent.md β
β with specialized testing instructions β
β β
β 3. Invokes @test-specialist to handle testing workload β
β β
β 4. Continues main task while sub-agent handles tests β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
---
name: my-custom-agent
description: What this agent does
tools:
- read_file
- edit_file
- run_in_terminal
---
# Agent Instructions
Your specialized instructions here...- Complex subtasks requiring focused context
- Repetitive operations benefiting from dedicated tooling
- Parallel workstreams needing isolation
- Code review, testing, or refactoring tasks
- Single Responsibility: Each agent should do one thing well
- Minimal Tools: Only include tools the agent needs
- Clear Instructions: Be explicit about capabilities and limitations
Skills are folders of instructions, scripts, and resources that enhance Copilot's abilities for specialized tasks. Skills follow the Agent Skills open standard.
Located in .github/skills/ (each skill in its own directory with SKILL.md):
| Skill | Description |
|---|---|
ralph-iteration |
Guides through completing a Ralph Mode iteration |
test-runner |
Standardized test execution across languages |
code-analysis |
Quick codebase analysis techniques |
.github/skills/
βββ ralph-iteration/
β βββ SKILL.md # Required: skill instructions
βββ test-runner/
β βββ SKILL.md
βββ code-analysis/
βββ SKILL.md
Create a new skill directory with a SKILL.md file:
---
name: my-custom-skill
description: What this skill does. When Copilot should use it.
---
# My Custom Skill
Instructions for Copilot to follow...- name (required): Lowercase, hyphens for spaces
- description (required): What it does and when to use it
- license (optional): License information
Skills can also include scripts, examples, or other resources in the same directory.
Hooks allow you to execute custom shell commands at key points during Ralph Mode execution.
Located in .github/hooks/:
| Hook | When it Runs |
|---|---|
pre-iteration.sh |
Before each Copilot CLI iteration |
post-iteration.sh |
After each iteration completes |
pre-tool.sh |
Before Copilot executes a tool |
on-completion.sh |
When completion promise is detected |
on-network-wait.sh |
When network wait begins (for notifications) |
Hooks have access to these environment variables:
RALPH_ITERATION # Current iteration number
RALPH_MAX_ITERATIONS # Maximum iterations allowed
RALPH_TASK_ID # Current task ID (batch mode)
RALPH_MODE # "single" or "batch"
RALPH_EXIT_CODE # Exit code from Copilot CLI
RALPH_PROMISE # Completion promise (on-completion only)# .github/hooks/post-iteration.sh
#!/usr/bin/env bash
git add -A && git commit -m "Ralph iteration $RALPH_ITERATION" --no-verify 2>/dev/null || true# .github/hooks/post-iteration.sh
#!/usr/bin/env bash
npm audit --audit-level=high 2>/dev/null || echo "Security issues found"Copilot CLI asks to confirm trust for directories. Only launch Ralph Mode from directories you trust.
Warning: Do not launch from:
- Home directory
- Directories with untrusted executable files
- Directories with sensitive data you don't want modified
Ralph Mode runs with --allow-all-tools --allow-all-paths by default for automation. To restrict:
# Deny dangerous commands
./ralph-loop.sh run --deny-tool 'shell(rm)' --deny-tool 'shell(git push)'
# Allow only specific tools
./ralph-loop.sh run --no-allow-tools --allow-tool 'shell(git)' --allow-tool 'write'| Syntax | Description |
|---|---|
'shell(COMMAND)' |
Allow/deny specific shell command |
'shell(git push)' |
Allow/deny specific subcommand |
'shell' |
Allow/deny all shell commands |
'write' |
Allow/deny file modifications |
'MCP_SERVER(tool)' |
Allow/deny MCP server tool |
For maximum safety:
- Use a virtual machine or container
- Restrict network access
- Review hooks before running
- Use
--deny-toolfor dangerous commands
Ralph Mode includes professional-grade network resilience to handle connection interruptions gracefully. When network connectivity is lost, Ralph will automatically:
- Detect the disconnection
- Wait with exponential backoff
- Resume from the exact point where it stopped
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Network Resilience Flow β
β β
β ββββββββββββββ βββββββββββββββ ββββββββββββββββ β
β β Iteration ββββββΆβ Network ββββββΆβ Success β β
β β Start β β Check β β Continue β β
β ββββββββββββββ ββββββββ¬βββββββ ββββββββββββββββ β
β β β
β [Connection Lost] β
β β β
β βΌ β
β βββββββββββββββ β
β β Save β β
β β Checkpoint β β
β ββββββββ¬βββββββ β
β β β
β βΌ β
β βββββββββββββββ β
β β Wait ββββββββ β
β β (backoff) β β β
β ββββββββ¬βββββββ β β
β β β β
β [Still Down?]βββββββββ β
β β β
β [Restored!] β
β β β
β βΌ β
β βββββββββββββββ β
β β Resume β β
β β from Point β β
β βββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Wait times increase progressively to avoid hammering the network:
| Attempt | Wait Time |
|---|---|
| 1 | 5 seconds |
| 2 | 10 seconds |
| 3 | 20 seconds |
| 4 | 40 seconds |
| 5 | 80 seconds |
| 6+ | 300 seconds (max) |
Ralph automatically saves checkpoints at key moments:
iteration_started- Before each iteration beginsnetwork_disconnected- When network loss is detectednetwork_error- When a network-related error occursnetwork_restored- When connection is restoredmax_failures_reached- When too many consecutive failures occur
# Default: Network resilience ENABLED
./ralph-loop.sh run
# Disable network checking (for offline work)
./ralph-loop.sh run --no-network-check
# Customize retry timing
./ralph-loop.sh run --network-retry 10 --network-max 600
# Manual network check
./ralph-loop.sh check-network
# Resume from checkpoint
./ralph-loop.sh resume# Default: Network resilience ENABLED
.\ralph-mode.ps1 run
# Manual network check
.\ralph-mode.ps1 check-network
# Resume from checkpoint
.\ralph-mode.ps1 resumeThe on-network-wait.sh hook runs when network wait begins. Use it for notifications:
# .github/hooks/on-network-wait.sh
#!/usr/bin/env bash
echo "β οΈ Network lost at iteration $RALPH_ITERATION"
# Example: Send notification
# curl -X POST "https://ntfy.sh/my-topic" -d "Ralph waiting for network"By default, Ralph checks these hosts for connectivity:
api.github.com- GitHub API (primary for Copilot)github.com- GitHub main1.1.1.1- Cloudflare DNS (as fallback)
If 3 consecutive iterations fail (even with network available), Ralph will:
- Stop the loop to prevent infinite failure loops
- Save a checkpoint with
max_failures_reachedstatus - Allow you to resume after investigating
# After fixing the issue, resume
./ralph-loop.sh resumeRalph Mode includes multi-agent verification to ensure task completion quality. This prevents premature task completion and enforces thorough review.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Quality Gate Flow β
β β
β ββββββββββββββ βββββββββββββββ βββββββββββββ β
β β Doer ββββββΆβ Promise ββββββΆβ Gate 1 β β
β β Works β β Detected β β Min Iter? β β
β ββββββββββββββ βββββββββββββββ βββββββ¬ββββββ β
β β β
β ββββββββββββββββββββ β
β β β
β [iter < MIN] [iter >= MIN] β
β β β β
β βΌ βΌ β
β βββββββββββββ βββββββββββββββ β
β β Reject β β Gate 2 β β
β β (iterate)β β Critic β β
β βββββββββββββ ββββββββ¬βββββββ β
β β β
β βββββββββββββββββββ΄βββββββββββ β
β β β β
β [REJECTED] [APPROVED] β
β β β β
β βΌ βΌ β
β βββββββββββββ βββββββββββββββ β
β β Save β β Complete β β
β β Issues β β Task! β
β β
β βββββββ¬ββββββ βββββββββββββββ β
β β β
β βΌ β
β [Next iteration sees issues] β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Prevents premature completion claims. By default, tasks must run for at least 2 iterations before a completion promise is accepted.
# Set minimum iterations via environment variable
export RALPH_MIN_ITERATIONS=3
./ralph-loop.sh runWhen the AI claims completion too early:
π COMPLETION PROMISE DETECTED β Starting verification...
β οΈ Minimum iterations not met (1 < 2). Rejecting early completion.
π Ralph iteration: 2
After passing the minimum iterations check, a Critic Agent reviews the work:
- Checks git diff for actual code changes
- Verifies each acceptance criterion from the task
- Runs commands to confirm files exist and have correct content
- Issues verdict:
APPROVEDorREJECTED
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π VERIFICATION REVIEW (Critic Agent) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π€ Running critic review...
β
Critic APPROVED the completion
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
VERIFIED AND APPROVED BY CRITIC!
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
When the Critic rejects a completion:
- Issues are saved to
.ralph-mode/review-issues.txt - Next iteration context includes these issues prominently
- The AI is instructed to fix all listed issues before claiming completion again
## β οΈ PREVIOUS REVIEW REJECTION β FIX THESE ISSUES
Your previous completion claim was REJECTED by the critic. Address these issues:
- Missing test coverage for edge cases
- pubspec.yaml has incorrect SDK version
Fix ALL listed issues before claiming completion again.# Disable quality gates (not recommended)
export RALPH_MIN_ITERATIONS=0
# Increase minimum iterations for complex tasks
export RALPH_MIN_ITERATIONS=5- Prevents 1-iteration completions β AI can't just claim "done" without thorough work
- Multi-agent review β A separate reviewer catches issues the doer missed
- Issue persistence β Rejected issues carry forward until addressed
- Real verification β Critic runs actual commands to verify file existence and content
Ralph supports three modes of operation:
Best for straightforward, focused tasks:
# Enable with a single prompt
python3 ralph_mode.py enable "Fix all TypeScript errors in src/" \
--max-iterations 20 \
--completion-promise "DONE"
# Run the loop
./ralph-loop.sh runBest for a series of related tasks defined in one file:
# Create tasks file
cat > my-tasks.json << 'EOF'
[
{"id": "TASK-001", "title": "Setup project", "prompt": "Initialize npm project with TypeScript"},
{"id": "TASK-002", "title": "Add tests", "prompt": "Add Jest tests for all functions"},
{"id": "TASK-003", "title": "Add docs", "prompt": "Add JSDoc comments to all exports"}
]
EOF
# Initialize batch mode
python3 ralph_mode.py batch-init \
--tasks-file my-tasks.json \
--max-iterations 50 \
--completion-promise "DONE"
# Run the loop (processes all tasks sequentially)
./ralph-loop.sh runThe most precise and scalable approach. Each task lives in its own .md file and groups are defined in tasks/_groups/.
# Create tasks directory
mkdir -p tasks tasks/_groups
# Let Copilot generate task files (see Best Practices section)
# Or create manually:Example task file (tasks/HXA-001-flexbox-rtl.md):
---
id: HXA-001
title: RTL Flexbox Conversion in Header
tags: [rtl, ui]
model: gpt-5.2-codex
max_iterations: 10
completion_promise: HXA_RTL_DONE
---
# RTL Flexbox Conversion in Header
## Objective
Convert flexbox classes to RTL-safe logical properties in `src/components/Header.tsx`.
## Scope
- ONLY modify: `src/components/Header.tsx`
- DO NOT read: Any other files
- DO NOT touch: `src/api/`, `src/utils/`, `node_modules/`
## Pre-work
1. Confirm `src/components/Header.tsx` exists and is writable
2. Identify all `flex-row`, `flex-row-reverse`, `ml-*`, `mr-*` in this file
3. Confirm no other files are required
## Changes Required
1. Replace `flex-row` with `flex-row` + `rtl:flex-row-reverse`
2. Replace `ml-*` with `ms-*`
3. Replace `mr-*` with `me-*`
## Acceptance Criteria
- [ ] Changes visible in `git diff`
- [ ] No `ml-*` or `mr-*` remain in the file
- [ ] If no changes needed, task FAILS
## Verification
```bash
grep -E "ml-|mr-" src/components/Header.tsx | wc -lWhen done, output: HXA_RTL_DONE
**Group configuration (`tasks/_groups/rtl.json`):**
```json
{
"name": "RTL Support",
"description": "Complete RTL implementation",
"tasks": [
"HXA-001-flexbox-rtl.md",
"HXA-002-border-classes.md",
"HXA-003-spacing-utilities.md"
],
"max_iterations_per_task": 20
}
Run the group:
python3 ralph_mode.py run --group rtl
./ralph-loop.sh runFor debugging or step-by-step control:
# Enable Ralph mode
python3 ralph_mode.py enable "Build a REST API" --max-iterations 10
# Check status
python3 ralph_mode.py status
# Run ONE iteration at a time
./ralph-loop.sh single
# Review changes, then run another iteration
./ralph-loop.sh single
# Or start the continuous loop
./ralph-loop.sh run| Command | Description |
|---|---|
enable "prompt" |
Enable Ralph mode with a task |
batch-init |
Initialize batch mode with multiple tasks |
disable |
Disable Ralph mode |
status |
Show current status |
prompt |
Show current prompt |
iterate |
Increment iteration counter |
next-task |
Move to next task in batch mode |
complete |
Check if output contains completion promise |
history |
Show iteration history |
help |
Show help |
| Command | Description |
|---|---|
run |
Start the continuous loop |
run --group <name> |
Run a specific task group |
run --agent <name> |
Run with a specific agent |
single |
Run single iteration |
resume |
Resume previous session (with checkpoint support) |
check-network |
Manual network connectivity test |
help |
Show help |
# ralph_mode.py options
--max-iterations <n> # Max iterations (0 = unlimited)
--completion-promise <text> # Phrase that signals completion
--tasks-file <path> # Path to tasks JSON file
--group <name> # Task group to run
--auto-agents # Enable dynamic sub-agent creation
# ralph-loop.sh options
--sleep <seconds> # Sleep between iterations (default: 2)
--agent <name> # Custom agent to use (ralph, plan, etc.)
--model <model> # Model to use (e.g., gpt-5.2-codex)
--allow-all # Enable all permissions (--yolo mode)
--allow-url <domain> # Pre-approve specific URL domain
--no-allow-tools # Don't auto-allow all tools
--no-allow-paths # Don't auto-allow all paths
--dry-run # Print commands without executing
--verbose # Verbose output
# Network resilience options
--no-network-check # Disable network resilience
--network-retry <seconds> # Initial retry wait (default: 5)
--network-max <seconds> # Maximum retry wait (default: 300)By default, Ralph runs with --allow-all-tools --allow-all-paths for full automation. Customize permissions:
# Restrict to specific URLs only
./ralph-loop.sh run --allow-url github.com --allow-url api.github.com
# Disable auto-approval of tools
./ralph-loop.sh run --no-allow-tools
# Full unrestricted mode
./ralph-loop.sh run --allow-allFollow these practices to maximize Ralph Mode's effectiveness.
π See docs/EXECUTION_GUIDE.md for comprehensive documentation.
The most common issue is Ralph only reading/scanning files without making changes. Prevent this by:
- Specify exact files - Max 1-2 files per task
- Add "DO NOT read" - Prevents scanning the codebase
- Use imperative language - "Add X" not "Ensure X exists"
- Require visible diff - Task fails if no
git diffoutput
Fix all RTL issues in the codebase.## Scope
- ONLY modify: `src/components/Button.tsx`
- DO NOT read: Any other files
## Changes Required
1. Line 15: Change `ml-4` to `ms-4`
2. Line 23: Change `text-left` to `text-start`
## Acceptance Criteria
- git diff must show changes
- If no changes needed, task FAILSEach task should target ONE file with specific changes:
---
id: TASK-001
title: Add RTL margin to Button
---
## Scope
- **ONLY modify:** `src/components/Button.tsx`
- **DO NOT read:** Any other files
## Changes Required
1. **Change margin** on line 15: `ml-4` β `ms-4`
## Acceptance Criteria
- [ ] Change visible in `git diff`
- [ ] If already changed, task FAILS- Tasks align with your actual requirements
- No unintended changes will be made
- The scope boundaries are correct
- You understand what Ralph will do
Set --max-iterations based on task complexity:
- Simple change: 5-10
- Medium task: 10-20
- Complex task: 20-50
python3 ralph_mode.py enable "Fix Button margin" \
--max-iterations 10 \
--completion-promise "DONE"Critical: Execute Ralph from your project's root directory:
# β
Correct - run from project root
cd /path/to/your-project
./ralph-loop.sh run
# β Wrong - running from a subdirectory
cd /path/to/your-project/src/components
./ralph-loop.sh run # AI won't have access to full codebase!When Ralph runs from root, it has visibility into ALL files and understands the full project structure.
Instruct the AI to build a dependency graph and respect boundaries:
# Task: Implement User Authentication
## Pre-work Requirements
1. Map all files that will be affected
2. Identify dependencies between modules
3. List files that should NOT be modified
4. Create a change plan before editing
## Scope Boundaries
- ONLY modify files in: `src/auth/`, `src/api/auth.ts`
- DO NOT touch: `src/payments/`, `src/admin/`, `src/legacy/`This prevents unintended side effects and keeps changes focused.
Create reusable rule files that Ralph should follow:
# .ralph-rules/safety.mdc
## Rules for All Tasks
1. Never modify public API signatures without deprecation
2. All changes must be backwards compatible
3. Run existing tests before AND after changes
4. Never delete files without explicit instruction
5. Always add comments explaining complex logicReference rules in your tasks or tell Copilot:
"Run Ralph Mode tasks following rules in .ralph-rules/safety.mdc"
For complex, multi-file tasks, use more capable models:
./ralph-loop.sh run --model gpt-5.2-codexMore capable models:
- Better understand large codebases
- Make fewer errors requiring iterations
- Handle complex multi-step reasoning
- Produce higher quality code
For maximum precision, create a separate .md file for each task:
| Approach | Pros | Cons |
|---|---|---|
| Single JSON file | Quick setup | Less context per task |
Individual .md files |
Full context, clear scope, git-friendly | More files to manage |
Individual files are better because:
- Each task has complete context
- Easier to review and edit individually
- AI gets clearer, focused instructions
- Better version control (git diff per task)
- Can be generated by AI in VS Code Chat
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. π¬ Use VS Code Chat to generate 20-50 detailed task files β
β "Create task files for implementing [feature] completely" β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 2. π Review ALL generated tasks - ensure scope is correct β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 3. π Create custom rules (.mdc) if needed for constraints β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 4. π cd to PROJECT ROOT (critical!) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 5. π Initialize batch mode with high iteration limit β
β python3 ralph_mode.py batch-init --max-iterations 100 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 6. βΆοΈ Execute the loop with a capable model β
β ./ralph-loop.sh run --model gpt-5.2-codex β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 7. β Let Ralph iterate until completion promise is detected β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| β Don't | β Do Instead |
|---|---|
| Write tasks manually | Let AI generate tasks, you review |
Set --max-iterations 5 |
Use --max-iterations 50-100 |
| Run from subdirectory | Always run from project root |
| Skip task review | Read every task before execution |
| Vague task descriptions | Include scope boundaries in each task |
| One giant task | Break into 20-50 focused tasks |
| Put all tasks in one JSON | Create individual .md files per task |
| Use basic models for complex work | Use capable models like gpt-5.2-codex |
When Ralph mode is active, it creates:
your-project/
βββ .ralph-mode/ # Ralph state directory
β βββ state.json # Current state (iteration, limits, etc.)
β βββ prompt.md # The current task prompt
β βββ INSTRUCTIONS.md # Instructions for AI
β βββ history.jsonl # Log of all iterations
β βββ output.txt # Last Copilot CLI output
β βββ summary.md # Iteration summary report
β βββ session.json # Session info for resume
β βββ checkpoint.json # Network resilience checkpoint
β βββ tasks/ # Task files (batch mode)
β βββ 01-HXA-001.md
β βββ 02-HXA-002.md
β
βββ .ralph-mode-config/ # Ralph configuration (optional)
β βββ config.json # Default settings
β βββ mcp-config.json # MCP server configuration
β
βββ .github/ # GitHub/Copilot integration
β βββ copilot-instructions.md # Repository-wide instructions
β βββ agents/ # Custom agent profiles
β β βββ ralph.md
β β βββ plan.md
β β βββ code-review.md
β β βββ task.md
β β βββ explore.md
β β βββ agent-creator.agent.md
β βββ hooks/ # Lifecycle hooks
β β βββ pre-iteration.sh
β β βββ post-iteration.sh
β β βββ pre-tool.sh
β β βββ on-completion.sh
β β βββ on-network-wait.sh
β β βββ stop.sh # Loop continuation hook (blocks exit)
β β βββ session-start.sh # Session start status display
β βββ instructions/ # Path-specific instructions
β β βββ ralph-mode-python.instructions.md
β β βββ shell-scripts.instructions.md
β β βββ task-files.instructions.md
β β βββ tests.instructions.md
β βββ skills/ # Agent skills (each in own folder)
β βββ ralph-iteration/
β β βββ SKILL.md
β βββ test-runner/
β β βββ SKILL.md
β βββ code-analysis/
β βββ SKILL.md
β
βββ tasks/ # Your task definitions (recommended)
β βββ HXA-001-feature.md
β βββ HXA-002-tests.md
β βββ _groups/
β βββ backend.json
β βββ frontend.json
β
βββ tests/ # Test files
β βββ test_ralph_mode.py
β βββ test_network_integration.ps1
β βββ test_network_resilience.ps1
β βββ test_network_resilience.sh
β βββ demo_network_resilience.ps1
β
βββ .ralph-rules/ # Custom rules (optional)
βββ safety.mdc
βββ coding-standards.mdc
Ralph Mode supports MCP (Model Context Protocol) servers for extended functionality.
MCP servers are configured using JSON format with the mcpServers object:
Project config: .ralph-mode-config/mcp-config.json
{
"mcpServers": {
"server-name": {
"type": "local|stdio|http|sse",
"tools": ["tool1", "tool2"],
...
}
}
}| Key | Type | Description |
|---|---|---|
tools |
string[] | Tools to enable (["*"] for all) |
type |
string | "local", "stdio", "http", or "sse" |
| Key | Type | Description |
|---|---|---|
command |
string | Command to start the server |
args |
string[] | Arguments for the command |
env |
object | Environment variables (use COPILOT_MCP_ prefix) |
| Key | Type | Description |
|---|---|---|
url |
string | Server URL |
headers |
object | Request headers |
{
"mcpServers": {
"github-mcp-server": {
"type": "http",
"url": "https://api.githubcopilot.com/mcp/readonly",
"tools": ["*"],
"headers": {
"X-MCP-Toolsets": "repos,issues,users,pull_requests,code_security,actions"
}
}
}
}{
"mcpServers": {
"sentry": {
"type": "local",
"command": "npx",
"args": ["@sentry/mcp-server@latest", "--host=$SENTRY_HOST"],
"tools": ["get_issue_details", "get_issue_summary"],
"env": {
"SENTRY_HOST": "COPILOT_MCP_SENTRY_HOST",
"SENTRY_ACCESS_TOKEN": "COPILOT_MCP_SENTRY_ACCESS_TOKEN"
}
}
}
}{
"mcpServers": {
"cloudflare": {
"type": "sse",
"url": "https://docs.mcp.cloudflare.com/sse",
"tools": ["*"]
}
}
}For MCP servers requiring secrets:
- Prefix all environment variables with
COPILOT_MCP_ - Reference in config:
"API_KEY": "COPILOT_MCP_API_KEY" - Or use
$COPILOT_MCP_API_KEYin string values
| Toolset | Description |
|---|---|
repos |
Repository operations |
issues |
Issue management |
users |
User information |
pull_requests |
PR operations |
code_security |
Security scanning |
secret_protection |
Secret scanning |
actions |
GitHub Actions |
web_search |
Web search |
Recommended for all developers - eliminates "works on my machine" issues.
| Problem | Solution |
|---|---|
| Different Python versions | Container uses Python 3.11 |
| Missing dependencies | All packages pre-installed |
| Path issues (Windows vs Unix) | Consistent Linux paths |
| Shell script compatibility | Bash/Zsh always available |
| IDE configuration | VS Code extensions auto-install |
.devcontainer/
βββ devcontainer.json # VS Code Dev Container config
βββ Dockerfile # Container image definition
βββ docker-compose.yml # Services and volumes
βββ post-create.sh # One-time setup script
βββ post-start.sh # Runs on every start
| Tool | Version | Purpose |
|---|---|---|
| Python | 3.11 | Core runtime |
| Git | Latest | Version control |
| GitHub CLI | Latest | gh commands |
| pytest | 7.0+ | Testing |
| black | 23.0+ | Code formatting |
| flake8 | 6.0+ | Linting |
| mypy | 1.0+ | Type checking |
| Zsh + Oh My Zsh | Latest | Better shell |
# Ralph Mode
ralph-quick 'Build a REST API' # Enable and show status
ralph-loop # Start the loop
ralph-status # Check status
# Testing
test # Run all tests
test-fast # Quick test (stop on first fail)
test-cov # With coverage
# Code Quality
lint # Check all
format # Auto-fix formatting
typecheck # MyPy type checking
# Git
gs # git status
gc # git commit
gp # git push# From VS Code Command Palette:
Dev Containers: Rebuild Container
# Or from terminal:
docker compose -f .devcontainer/docker-compose.yml build --no-cache| Platform | State Management | Loop Runner |
|---|---|---|
| Dev Container β | ralph |
ralph-loop |
| Linux/macOS | python3 ralph_mode.py |
./ralph-loop.sh |
| Windows (WSL) | python3 ralph_mode.py |
./ralph-loop.sh |
| Windows (PowerShell) | python ralph_mode.py |
./ralph-mode.ps1 or WSL |
| Windows (CMD) | python ralph_mode.py |
ralph-mode.cmd or WSL |
Using Dev Container (Recommended):
- Docker Desktop
- VS Code with Dev Containers extension
Manual Installation:
- Python 3.7+
- GitHub CLI (
gh) with Copilot access - Bash shell (for loop runner) or PowerShell on Windows
jqfor JSON parsing (optional but recommended)
# Using Make (recommended)
make test # Run all tests
make test-cov # Run with coverage report
make lint # Run code quality checks
# Using pytest directly
pytest tests/ -v # All tests
pytest tests/test_ralph_mode.py -v # Core tests
pytest tests/test_ralph_mode_integration.py -v # Integration tests
pytest tests/test_ralph_mode_iteration_deep.py -v # Deep iteration tests
pytest tests/test_ralph_mode_stress_concurrency.py -v # Stress/concurrency tests
pytest tests/test_e2e_workflows.py -v # End-to-end workflow tests
pytest tests/test_enterprise_scenarios.py -v # Enterprise scenario tests
pytest tests/test_cross_platform.py -v # Cross-platform tests
# Using Python
python -m pytest tests/ -v --timeout=30| Suite | Tests | Description |
|---|---|---|
test_ralph_mode.py |
38 | Core functionality |
test_ralph_mode_integration.py |
120+ | Integration tests |
test_ralph_mode_iteration_deep.py |
8 | Deep iteration scenarios |
test_ralph_mode_stress_concurrency.py |
4 | Stress and concurrency |
test_ralph_mode_edge_cases.py |
50+ | Edge case coverage |
test_ralph_mode_feature_advanced.py |
30+ | Advanced features |
test_e2e_workflows.py |
100+ | End-to-end workflows |
test_enterprise_scenarios.py |
200+ | Enterprise scenarios |
test_cross_platform.py |
38 | Windows/macOS/Linux compatibility |
| Total | 799 | Full test coverage π |
GitHub Actions runs tests on every push:
- Platforms: Ubuntu, macOS, Windows
- Python versions: 3.9, 3.10, 3.11, 3.12
- Matrix: 12 combinations
- Test Count: 799 passing tests
Bug Fixes:
- β Fixed promise detection with whitespace tolerance in loop runner
- β Fixed CLI crash on final batch task completion
- β Fixed batch completion ValueError handling
- β Fixed task ID matching to prioritize exact matches
- β Fixed file handle leaks in state management
- β Fixed shell quoting bugs in loop scripts
Test Suite Enhancements:
- β Added deep iteration testing (8 tests)
- β Added stress and concurrency testing (4 tests)
- β Added comprehensive edge case coverage (50+ tests)
- β Added advanced feature tests (30+ tests)
- β Fixed all platform-specific skipped tests
- β All 799 tests passing with 0 failures, 0 skips
make lint # flake8 + black check + isort check + mypy
make format # Auto-format with black + isort- Iteration > Perfection: Don't aim for perfect on first try
- Failures Are Data: Use errors to improve
- Persistence Wins: Keep trying until success
- Trust the Loop: Let the AI learn from its mistakes
- Review > Write: Let AI generate, you review and approve
$ python3 ralph_mode.py enable "Create a Python calculator with tests" \
--max-iterations 15 --completion-promise "DONE"
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π RALPH MODE ENABLED β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Iteration: 1
Max Iterations: 15
Completion Promise: DONE
π Task:
Create a Python calculator with tests
β
Ralph mode is now active!
$ ./ralph-loop.sh run
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π RALPH LOOP STARTING β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Press Ctrl+C to stop the loop
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π Ralph Iteration 1 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Checking network connectivity...
β
Network is available
π€ Running copilot...
[AI creates calculator.py]
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π Ralph Iteration 2 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Checking network connectivity...
β
Network is available
π€ Running copilot...
[AI creates test_calculator.py]
[AI runs tests - they pass]
<promise>DONE</promise>
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
COMPLETION PROMISE DETECTED!
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Ralph loop finished after 2 iterationsββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π Ralph Iteration 5 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Checking network connectivity...
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Network connection lost - waiting for reconnection...
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[2026-02-02 15:31:49] Attempt 1: Waiting 5s for network... (total: 0s)
[2026-02-02 15:31:54] Attempt 2: Waiting 10s for network... (total: 5s)
[2026-02-02 15:32:04] Attempt 3: Waiting 20s for network... (total: 15s)
[2026-02-02 15:32:24] β
Network connection restored after 35s!
π€ Running copilot... (resuming)
[AI continues work from where it stopped]- Original technique: ghuntley.com/ralph
- Inspiration: Geoffrey Huntley's Ralph Wiggum approach
- GitHub Copilot: github.com/features/copilot
- GitHub Copilot CLI: docs.github.com/copilot-cli
MIT License - See LICENSE for details.