Product Requirement Prompts (PRP) methodology for AI-assisted development with validation loops and autonomous execution
triggers
["create a PRP for this feature","generate implementation plan from PRD","start autonomous ralph loop","investigate this GitHub issue with PRP","create a product requirement prompt","implement this plan with validation","review this PR with PRP workflow","debug using 5 whys methodology"]
PRP (Product Requirement Prompt) is a methodology and toolset for AI-assisted development that combines traditional PRDs with curated codebase intelligence and autonomous validation loops. It enables AI agents to deliver production-ready code on the first pass by providing complete context, patterns, and validation commands.
fix(auth): fix validation bug in user registration
- Updated UserValidator.validate() to check email format
- Added test coverage for edge cases
- Fixes #123
/prp-pr - Create Pull Request
Generates PR with template support.
/prp-pr "Add user authentication" --base main --head feature/auth
# Ralph Loop State
Plan: .claude/PRPs/plans/add-user-auth.plan.md
Max Iterations: 20
Current Iteration: 7
## Last Validation Results
✓ npm run type-check
✗ npm run lint (3 errors)
✓ npm test
✗ npm run build (compilation error)
## Current Focus
Fixing lint errors in src/auth/jwt.ts
Resolving build error in import path
## Learnings- Arrow functions need explicit return types
- Barrel imports must use .js extension
/prp-ralph-cancel - Stop Ralph Loop
/prp-ralph-cancel
Removes state file, allowing stop hook to exit gracefully.
Title: Email notifications not sent for password reset
Labels: bug, priority:high
Users report not receiving password reset emails.
Checked spam folders - emails aren't being sent at all.
Step 1: Investigate
/prp-issue-investigate 789
Generated Investigation:
# Issue Investigation: #789 - Email notifications not sent## Issue Summary
Password reset emails not being sent to users
## Code Analysis
File: `src/features/auth/auth.service.ts````typescript
async resetPassword(email: string) {
const token = generateToken();
await this.userRepo.saveResetToken(email, token);
// BUG: emailService.send() is async but not awaited
this.emailService.send({
to: email,
subject: 'Password Reset',
template: 'reset-password',
data: { token }
});
return { success: true };
}
Root Cause
Email sending is fire-and-forget. If it fails, no error is thrown and method returns success.
/prp-plan .claude/PRPs/prds/real-time-chat-system.prd.md
# Selects Phase 1 (first pending with no dependencies)
/prp-ralph .claude/PRPs/plans/real-time-chat-phase-1.plan.md --max-iterations 15
Step 3: Repeat for Each Phase
/prp-plan .claude/PRPs/prds/real-time-chat-system.prd.md # Phase 2
/prp-ralph .claude/PRPs/plans/real-time-chat-phase-2.plan.md
# ... continue through all phases
Step 4: Parallel Phases (5 & 6)
Use git worktrees for concurrent development:
# Current branch has phases 1-4 complete
git worktree add -b phase-5-ui ../chat-phase-5
git worktree add -b phase-6-state ../chat-phase-6
# Terminal 1cd ../chat-phase-5
/prp-plan .claude/PRPs/prds/real-time-chat-system.prd.md
/prp-ralph .claude/PRPs/plans/real-time-chat-phase-5.plan.md
# Terminal 2cd ../chat-phase-6
/prp-plan .claude/PRPs/prds/real-time-chat-system.prd.md
/prp-ralph .claude/PRPs/plans/real-time-chat-phase-6.plan.md
# After both complete, merge both branches
Common Patterns
Pattern 1: Iterative Refinement
# Create initial plan
/prp-plan "add file upload feature"# Review generated plan, add details to plan file manually# Then implement
/prp-implement .claude/PRPs/plans/add-file-upload.plan.md
Pattern 2: Plan-Review-Implement
# Generate plan
/prp-plan "refactor user service to use repository pattern"# Review plan artifact, discuss with team# Modify plan file if needed# Then execute with validation
/prp-ralph .claude/PRPs/plans/refactor-user-service.plan.md
Pattern 3: Investigation-Driven Development
# Investigate issue first
/prp-issue-investigate 456
# Review investigation# Edit investigation artifact to add context# Then fix
/prp-issue-fix 456
Pattern 4: Validation-First Planning
When creating plans, always include comprehensive validation:
## Validation Commands# Type safety
npm run type-check
# Code quality
npm run lint
npm run format:check
# Functionality
npm test
npm run test:integration
npm run test:e2e
# Build
npm run build
# Runtime
npm run dev # Manual verification checklist
Troubleshooting
Ralph Loop Not Stopping
Symptom: Ralph continues after <promise>COMPLETE</promise>
Solution:
# Verify hook is configuredcat .claude/settings.local.json
# Verify hook script exists and is executablels -la .claude/hooks/prp-ralph-stop.sh
chmod +x .claude/hooks/prp-ralph-stop.sh
# Manual cancel
/prp-ralph-cancel
Symptom: Ralph loop gets stuck on failing validation
Solution 1: Check validation commands are correct
# Test commands manually
npm run type-check
npm run lint
npm test
Solution 2: Add more specific validation
## Validation Commands
npm run type-check
npm run lint -- --fix # Auto-fix lint issues
npm test -- --testPathPattern=users # Only relevant tests
PRD Phase Selection Issues
Symptom: /prp-plan doesn't auto-select next phase
Solution: Verify PRD table format is exact:
| # | Phase | Description | Status | Parallel | Depends | PRP Plan |
|---|-------|-------------|--------|----------|---------|----------|
Status must be exactly: pending, in-progress, or complete
Missing Context in Plans
Symptom: Plans lack necessary codebase context
Solution: Enhance CLAUDE.md with more patterns:
## Code Patterns### Authentication
Always use `AuthMiddleware.verify()` before protected routes
### Database Queries
Use repository pattern from `src/repositories/base.repository.ts`### Error Responses```typescript
throw new AppError(
'User-facing message',
HttpStatus.BAD_REQUEST,
{ details: 'debug info' }
);
### Ralph Exceeds Max Iterations
**Symptom**: Ralph hits max iterations without completing
**Solution 1**: Increase iterations
```bash
/prp-ralph plan.md --max-iterations 50
Solution 2: Break plan into smaller chunks
# Instead of one large plan, create multiple focused plans
/prp-plan "add user model and migration"
/prp-plan "add user service layer"
/prp-plan "add user API endpoints"
Best Practices
1. Context is King
Provide maximum relevant context in every artifact:
File paths (exact)
Existing code patterns
Dependencies and versions
Related documentation
2. Validation Loops
Every plan must have executable validation commands:
## Validation Commands
npm run type-check
npm run lint
npm test
npm run build
npm run e2e # if applicable
3. Bounded Scope
Each plan should be completable in one Ralph loop (< 20 iterations):
# Create project-specific templatecp PRPs/templates/prp_base.md PRPs/templates/prp_api_endpoint.md
# Edit to include API-specific patterns
Advanced Usage
Custom Subagents
Create specialized agents in .claude/agents/:
# .claude/agents/database-expert.md
You are a database optimization expert.
When analyzing queries:
1. Check for N+1 issues
2. Verify indexes exist
3. Suggest query optimizations
4. Estimate query performance
Use EXPLAIN ANALYZE for all queries.
Reference in plans:
## Special Instructions
@database-expert review all queries in this implementation
name:PRPValidationon:pull_request:paths:-'.claude/PRPs/plans/**'-'.claude/PRPs/reports/**'jobs:validate:runs-on:ubuntu-lateststeps:-uses:actions/checkout@v3-uses:actions/setup-node@v3with:node-version:20-name:Installdependenciesrun:npmci-name:RunPRPvalidationsrun:|
npm run type-check
npm run lint
npm test
npm run build
-name:Checkforincompleteplansrun:|
if ls .claude/PRPs/plans/*.plan.md 2>/dev/null; then
echo "❌ Incomplete plans found - all plans should be archived"
exit 1
fi
The goal is one-pass implementation success through comprehensive context.