← Articles

// FIELD NOTE

Keep Your PRs Green: Never Have a Failing Pull Request Again

Cory LaNou

Cory LaNou

Keep Your PRs Green: Never Have a Failing Pull Request Again

Keep Your PRs Green: Never Have a Failing Pull Request Again

Overview

I figured out a simple trick using gh pr checks --watch to ensure I never leave a PR in a failing state. By adding a few lines to my CLAUDE.md, I've automated the entire CI feedback loop.

The Problem

We've all been there. You push a PR, move on to the next task, and hours later realize your PR has been sitting in a failing state. Maybe a linter caught something. Maybe a test failed. Simple fixes, but now you have to context switch back, figure out what broke, fix it, and push again.

With AI-assisted development, this becomes even more frustrating. You're moving fast, pushing multiple PRs, and those red checks pile up.

The Discovery

I was watching Claude work one day and noticed it ran a command I'd never seen before:

gh pr checks --watch

This command watches the PR checks and waits for them to complete. It doesn't just show you the current state - it actively monitors until all checks finish.

That's when it clicked. What if Claude automatically watched every PR it pushed, and fixed any failures before moving on?

The Solution

I added these instructions to my global CLAUDE.md (in ~/.claude/CLAUDE.md), so they apply to every project:

### CI Watch After Push

After pushing to a PR, always watch CI and fix failures:

1. Run: `gh pr checks --watch` (or `gh pr checks <PR_NUMBER> --watch`)
2. If checks fail:
   - Get failure details: `gh pr checks --json name,state,description`
   - Analyze and fix the failing check (test, lint, build)
   - Commit and push the fix
   - Return to step 1
3. Only mark work complete when all CI checks pass

**Do not consider a PR ready or task complete until CI is green.**

That's it. A few lines of instructions that create a powerful feedback loop.

How It Works

The workflow now looks like this:

  1. Push - Claude pushes the changes to the PR
  2. Watch - It runs gh pr checks --watch and waits
  3. Analyze - If checks fail, it examines what went wrong
  4. Fix - It makes the necessary fixes (linting, tests, etc.)
  5. Push Again - Commits and pushes the fix
  6. Repeat - Goes back to step 2 until everything is green

This creates an automatic feedback cycle. Claude doesn't consider the task complete until all CI checks pass. No more orphaned red PRs.

The Results

Since adding these instructions, I haven't had a single PR left in a failing state. When I come back to my PRs, they've already addressed:

  • Linting failures
  • Test failures
  • Build errors
  • Any other CI check issues

Things I would have had to fix anyway, but now they're handled automatically before I even see them.

Key Takeaways

  1. gh pr checks --watch is the key - It waits for checks to complete instead of showing a snapshot
  2. Put it in your global CLAUDE.md - Apply these instructions to every project automatically
  3. Create a feedback loop - The instructions tell Claude to keep pushing until green
  4. Never mark complete until green - This is the critical instruction that makes it work

It's simple. It took me way too long to figure this out. But now that I have it, I can't imagine going back. My PRs are always green, and I never have to context switch back to fix trivial CI failures.

Try it. Add those few lines to your CLAUDE.md. You'll never have a failing PR again.

Want more AI development insights?

Subscribe to the newsletter for weekly tips on using AI in professional development.

Subscribe to Newsletter

// KEEP READING

More articles