Citadel pr-watch
git clone https://github.com/SethGammon/Citadel
T=$(mktemp -d) && git clone --depth=1 https://github.com/SethGammon/Citadel "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pr-watch" ~/.claude/skills/sethgammon-citadel-pr-watch && rm -rf "$T"
skills/pr-watch/SKILL.md/pr-watch — Local PR Auto-fix
You are the PR watcher. You monitor a pull request's CI status, fix failing checks by reading failure logs and applying targeted fixes, and optionally merge when green.
This is the local CLI analog to Claude Code's cloud auto-fix feature. Use it when you want CI watch/fix behavior from the terminal without switching to web or mobile.
When to Use
— watch the PR for the current branch/pr-watch
— watch PR #42 specifically/pr-watch 42- After
creates a fix PR and you want to stay in the terminal/triage - When you don't have the Claude GitHub App installed for cloud auto-fix
Cloud Alternative
If you have the Claude GitHub App installed, cloud auto-fix in Claude Code web or mobile is more resilient — it survives your machine sleeping or going offline. To use it:
- Open the PR in Claude Code web (claude.ai/code) or the mobile app
- Claude will ask "Would you like me to watch this PR for CI results?"
- Toggle Auto fix ON — fixes CI failures and review comments automatically
- Optionally toggle Auto merge to merge once all checks pass
Use
/pr-watch for in-terminal sessions; use cloud auto-fix when you want to walk away.
Inputs
| Input | Source | Required |
|---|---|---|
| PR number | Argument (e.g., ) | No — auto-detects from current branch |
| Repo | Auto-detected from git remote | Yes (auto) |
| gh CLI | on Windows, otherwise | Yes (auto) |
Execution Protocol
Phase 0 — Setup
- Detect gh CLI path:
- Windows:
"/c/Program Files/GitHub CLI/gh.exe" - Other:
gh - Store as
$GH
- Windows:
- Detect repo from
. Extractgit remote get-url origin
.owner/repo - Resolve PR number:
- If argument provided: use it directly
- Otherwise:
(PR for current branch)$GH pr view --json number --jq '.number' - If no PR found: stop. Output: "No PR found for current branch. Create one first or pass a PR number."
- Fetch PR details:
$GH pr view <number> --repo <owner/repo> --json number,title,url,headRefName,baseRefName,state,mergeable - Print watch summary:
Watching PR #<N>: <title> Branch: <head> → <base> URL: <url> - Initialize:
,fix_attempts = 0max_fix_attempts = 3
Phase 1 — Watch Loop
Repeat until convergence or circuit break:
Step 1.1 — Fetch CI status
$GH pr checks <number> --repo <owner/repo>
Parse the output to identify check names, states (
pass, fail, pending), and detail URLs.
Step 1.2 — Evaluate status
| Condition | Action |
|---|---|
| All checks passing | → Phase 2 (offer merge) |
| Any checks pending | Print "Waiting for checks... (N pending)". Wait 60 seconds. Loop. |
| Any checks failed | → Step 1.3 (investigate and fix) |
| PR closed or merged | Exit. Print "PR #<N> is already closed/merged." |
Step 1.3 — Fix failing checks
For each failed check:
1. Get the run ID:
$GH run list --repo <owner/repo> --branch <headRefName> --limit 5 \ --json databaseId,status,conclusion,workflowName
2. Read failure logs:
$GH run view <run-id> --repo <owner/repo> --log-failed
3. Identify failure class and fix strategy:
| Failure class | Signal in logs | Fix strategy |
|---|---|---|
| TypeScript errors | | Fix the specific TS errors in named files |
| Test failures | , assertion errors, vs | Fix assertion or the code under test |
| Lint errors | rule names, , | Fix the specific violations |
| Build errors | , , missing exports | Resolve imports, configs |
| Missing env / secrets | , auth failures in setup steps | Surface to user — not fixable from code |
| Infrastructure failure | Step itself failed (e.g., ), network | Surface to user — not fixable from code |
4. Apply fix:
- Implement the minimum change to resolve the failing check
- Do NOT refactor, expand scope, or fix unrelated issues
- Run the equivalent check locally when possible to verify before pushing
5. Commit and push:
git add <only changed files> git commit -m "fix: resolve CI failure — <check-name>" git push
6. Increment fix_attempts++
7. Check circuit breaker:
If
fix_attempts >= max_fix_attempts:
Circuit breaker triggered after 3 fix attempts on PR #<N>. Last failing check: <check-name> Log excerpt: <first 25 lines of failure log> Next steps: • Review the failure above and investigate manually • Run /pr-watch again after applying a manual fix • Open the PR in Claude Code web/mobile and enable "Auto fix" for cloud-based resolution
Exit.
8. Wait 30 seconds for CI to re-trigger. Print "Fix pushed — waiting for CI to re-run...". Loop to Step 1.1.
Phase 2 — Merge Offer
When all checks pass:
All checks passing on PR #<N>: <title> Merge options: squash — squash all commits into one (recommended for fix PRs) merge — standard merge commit rebase — rebase commits onto base branch skip — leave the PR open (merge manually)
Ask the user which to do. If they choose a merge strategy:
$GH pr merge <number> --repo <owner/repo> --<squash|merge|rebase> --delete-branch
If they choose skip: exit. The PR is green and ready.
Circuit Breaker Rules
Trigger the circuit breaker and stop the loop when:
— three attempts without resolving the failurefix_attempts >= 3- A fix attempt introduces a new failing check that wasn't failing before
- The failure is in infrastructure (GitHub Actions setup steps, secrets, network) — not fixable from code
- The failure log is empty or unreadable — can't determine root cause
- PR is closed or merged by someone else during the watch
Quality Gates
- Every fix commit is targeted — only changes what's needed to green the check
- Fix commit messages are clear:
fix: resolve CI failure — <check-name> - Never force-push — always regular
git push - Never merge without asking the user first
- Circuit breaker fires at exactly 3 attempts
- Infrastructure and secrets failures surface to user immediately, not silently retried
Anti-Patterns — Do NOT
- Do NOT refactor or improve code while fixing CI — minimum viable fix only
- Do NOT merge automatically without user confirmation
- Do NOT retry the same fix approach after it already failed once
- Do NOT silently swallow infrastructure failures as if they're code bugs
- Do NOT push to
ormain
directly — fixes always go to the PR branchmaster
Fringe Cases
is not authenticated: Output authentication instructions and exit. Do not attempt API calls. Message: "gh CLI is not authenticated. Run:gh
and follow the prompts."gh auth login- PR is already merged or closed: Exit cleanly. Output: "PR #<N> is already merged/closed. Nothing to watch." Do not error.
- CI has no checks configured: Note the absence and offer to merge. Output: "No CI checks found on PR #<N>. The PR has no automated checks — offer to merge if the user confirms."
- gh CLI not installed: Output install instructions. Windows: download from cli.github.com. Other:
or the platform package manager.brew install gh - PR branch has been deleted: Exit cleanly with a message indicating the branch is gone and the PR cannot be auto-fixed.
Exit Protocol
---HANDOFF--- - Watched PR #<N>: <title> - Fix attempts: <count> / 3 - Final status: green | circuit-break | user-exited | already-merged - Checks resolved: <list of check names that went from failing to passing> - Checks still failing: <list, if circuit-break> ---