| name | pr-shepherd |
| description | Analyze and fix failing GitHub PRs. Check .branchdeck/analysis.json to determine current state. If no analysis exists, analyze the PR. If analysis is approved, execute the fix plan.
|
PR Shepherd Workflow
You are shepherding a GitHub PR to get it ready to merge.
Get PR context
Read .branchdeck/pr-context.json for the PR you're working on:
repo: the GitHub repo (e.g., "owner/repo")
number: the PR number
branch: the PR branch name
base_branch: the target branch (e.g., "main")
Use these values in all gh commands below.
Determine your phase
Check if .branchdeck/analysis.json exists in the current worktree.
If it does NOT exist → Analyze
- Read PR status:
gh pr checks <number> --repo <repo>
- Read review comments:
gh pr view <number> --repo <repo> --comments
- Read inline review comments:
gh api repos/<owner>/<repo>/pulls/<number>/comments
- Search codebase for relevant patterns
- Check recent git history:
git log --oneline -20
- Classify confidence:
- HIGH: lint/format, unused imports, single-file assertion, known pattern
- MEDIUM: test logic, small refactor, dependency version bump
- LOW: architecture, multi-file rewrite, security, unknown pattern
- Write
.branchdeck/analysis.json with your findings:
{
"pr": { "repo": "<repo>", "number": <number>, "branch": "<branch>" },
"confidence": "HIGH|MEDIUM|LOW",
"failures": [
{
"check_name": "<CI check name>",
"error_summary": "<one-line summary>",
"root_cause": "<what actually went wrong>",
"fix_approach": "<how to fix it>"
}
],
"reviews": [
{
"reviewer": "<username>",
"comment": "<review comment>",
"proposed_response": "<how you'd address it>"
}
],
"plan_steps": [
{
"description": "<what to do>",
"file": "<file path>",
"change_type": "modify|create|delete"
}
],
"affected_files": ["<file1>", "<file2>"],
"reasoning": "<brief explanation of your analysis>",
"approved": false,
"approved_plan": null,
"resolved": false
}
- End your session. A human will review your analysis.
If it exists with approved: true → Fix
- Read
approved_plan from .branchdeck/analysis.json
(the human may have edited the plan)
- Execute each plan step in order
- Follow the project's code standards (see CLAUDE.md)
- Run the project's check suite (see CLAUDE.md for commands)
- Stage, commit, push:
git add <affected files>
git commit -m "fix: <concise summary>"
git push
- Verify CI:
gh pr checks <number> --repo <repo> --watch
- If CI still fails, analyze the new failure and fix it (up to 3 attempts)
- When done, update analysis.json: set
resolved: true
If it exists with approved: false → Wait
Do nothing. End your session. The human hasn't reviewed yet.
Troubleshooting
If gh commands fail with 403/404, verify authentication: gh auth status