| name | pr-monitor |
| description | Monitor GitHub pull requests and automatically resume when new commits are detected |
| version | 1.0.0 |
PR Monitoring Skill
Objective
Set up automated monitoring of GitHub pull requests that triggers Claude Code to auto-resume and
review changes when new commits are detected.
Prerequisites
Before starting, ensure:
- GitHub CLI (
gh) is installed and authenticated
- You have read access to the target repository
- The pr-monitor plugin is installed (includes Stop hook)
When to Use
Use this skill when:
- You want to continuously monitor a PR for updates
- You need to provide automated feedback on new commits
- You're waiting for someone to push changes to a PR
- You want Claude to automatically review PR updates
Step-by-Step Workflow
Phase 1: Identify PR to Monitor
Get PR information:
-
If user provides PR URL, extract repo and PR number:
-
If user provides repo and PR number, verify PR exists:
gh pr view PR_NUMBER --repo OWNER/REPO --json number,title,state,headRefOid
-
If in a git repository, list open PRs:
gh pr list --json number,title,headRefOid --limit 20
Phase 2: Setup Monitoring State
Create state file for the Stop hook to monitor:
-
Get repository path:
REPO_PATH=$(pwd)
gh repo clone OWNER/REPO
cd REPO
REPO_PATH=$(pwd)
-
Get current commit SHA:
CURRENT_SHA=$(gh pr view PR_NUMBER --json headRefOid --jq '.headRefOid')
-
Create monitoring state file:
REPO_NAME=$(basename "$REPO_PATH")
STATE_DIR="$HOME/.claude/pr-monitor"
mkdir -p -m 700 "$STATE_DIR"
STATE_FILE="$STATE_DIR/claude_monitor_pr_${REPO_NAME}_${PR_NUMBER}"
cat > "$STATE_FILE" <<EOF
$REPO_PATH
$PR_NUMBER
$CURRENT_SHA
EOF
-
Confirm monitoring active:
echo "✓ Monitoring enabled for PR #$PR_NUMBER"
echo "✓ State file: $STATE_FILE"
echo "✓ Current commit: ${CURRENT_SHA:0:8}"
cat "$STATE_FILE"
Phase 3: Initial Review (Optional)
If requested, perform initial review of current PR state:
-
Get PR details:
gh pr view PR_NUMBER --json title,body,commits,files
-
View recent changes:
gh pr diff PR_NUMBER
-
Provide initial feedback:
- Analyze the current state
- Comment on PR if appropriate
- Document baseline for future comparisons
Phase 4: Wait for Updates
The Stop hook will now automatically monitor the PR:
When Claude Code would normally stop:
- Stop hook checks state file
- Queries GitHub for PR status
- Compares current SHA with last_sha
- If different, auto-resumes with new commit notification
You can continue working on other tasks - monitoring happens automatically in the background.
Phase 5: Auto-Resume on New Commits
When new commits are detected, Claude will automatically:
-
Resume with notification:
- Message: "New commits detected in PR #X. Current commit: abcd1234. There are now Y total
commits. Please review the new changes and provide feedback."
-
Review new changes:
gh pr view PR_NUMBER --json commits,headRefOid,files
gh pr diff PR_NUMBER
git diff OLD_SHA NEW_SHA
-
Provide feedback:
gh pr comment PR_NUMBER --body "FEEDBACK_TEXT"
gh pr review PR_NUMBER --comment --body "REVIEW_TEXT"
-
Update monitoring state:
- State file is automatically updated by Stop hook
- Monitoring continues for next update
Phase 6: Stop Monitoring
When monitoring is no longer needed:
-
Remove state file:
rm ~/.claude/pr-monitor/claude_monitor_pr_${REPO_NAME}_${PR_NUMBER}
-
Confirm stopped:
echo "✓ Monitoring stopped for PR #$PR_NUMBER"
Monitoring will also auto-stop if:
- PR is merged or closed (Stop hook detects and cleans up)
- Repository is deleted
- User manually removes state file
Error Handling
Common issues and solutions:
-
Hook not triggering:
- Verify plugin is installed: Check hooks are registered
- Verify state file exists:
ls -la ~/.claude/pr-monitor/claude_monitor_pr_*
- Test hook manually:
echo '{"stop_hook_active": false}' | bash /path/to/Stop.sh
-
PR not accessible:
- Verify
gh is authenticated: gh auth status
- Check repository permissions:
gh pr view PR_NUMBER --repo OWNER/REPO
- Ensure repository path is correct in state file
-
Multiple PRs monitored:
- List all monitors:
ls -la ~/.claude/pr-monitor/claude_monitor_pr_*
- View specific monitor:
cat ~/.claude/pr-monitor/claude_monitor_pr_REPO_PR
- Stop specific monitor:
rm ~/.claude/pr-monitor/claude_monitor_pr_REPO_PR
Limitations
-
Polling-based, not real-time:
- Checks happen when Claude Code would naturally stop
- Not true push notifications
- May have delays between commit and detection
-
Requires Claude Code running:
- Monitoring only active when Claude Code session is running
- Stops when you quit Claude Code
-
Persistent state files:
- State files persist in
~/.claude/pr-monitor across reboots
- Remove them manually to stop monitoring
-
GitHub API rate limits:
- Stop hook queries GitHub each time it runs
- Multiple PRs = more API calls
- Stay within rate limits (5,000 requests/hour)
Best Practices
-
Monitor selectively:
- Only monitor PRs you're actively working with
- Stop monitoring when done
- Clean up old state files
-
Provide context in feedback:
- Reference specific commits
- Link to relevant code sections
- Suggest concrete improvements
-
Use with other tools:
- Combine with PR review workflows
- Integrate with project management
- Coordinate with team notifications
Example Usage
Scenario: Monitor a PR from Copilot
cd /path/to/claude-skills
gh pr view 2 --json headRefOid,title,commits
REPO_PATH=$(pwd)
PR_NUMBER=2
CURRENT_SHA=$(gh pr view 2 --json headRefOid --jq '.headRefOid')
REPO_NAME=$(basename "$REPO_PATH")
cat > ~/.claude/pr-monitor/claude_monitor_pr_${REPO_NAME}_${PR_NUMBER} <<EOF
$REPO_PATH
$PR_NUMBER
$CURRENT_SHA
EOF
echo "✓ Now monitoring PR #2 in claude-skills"
echo "✓ Current commit: ${CURRENT_SHA:0:8}"
Verification
After enabling monitoring, verify:
-
State file created:
ls -la ~/.claude/pr-monitor/claude_monitor_pr_*
-
State file format correct:
cat ~/.claude/pr-monitor/claude_monitor_pr_REPO_PR
-
PR accessible:
gh pr view PR_NUMBER --repo OWNER/REPO
Related Skills
- GitHub issue grooming
- Code review automation
- CI/CD monitoring
- Project management