← Back to Blog

Safe Pull Request Now Handles PRs Opened from Claude Code

2025-12-15by Andrew Weiner

Safe Pull Request Now Handles PRs Opened from Claude Code

Safe Pull Request has always been about one thing: making sure your pull requests go to the right place. But there was a blind spot I hadn't considered until a community member pointed it out.

The Scenario

If you use Claude Code (or another AI coding assistant) with a forked repository, here's what can happen:

  1. You wire up Claude Code to your repo
  2. You ask it to make some changes
  3. Claude commits to a branch and offers a "Create PR" button
  4. You click it

And the PR opens against the upstream repository. Not your fork.

This is the exact problem Safe Pull Request solves for normal GitHub navigation — but the extension wasn't catching this case. When Claude Code opens a compare page, it constructs the URL directly, bypassing the compare links that the extension was already modifying.

Credit Where It's Due

Shoutout to @klondikemarlen, who flagged this in a GitHub Community Discussion. He'd built his own Tamper Monkey script to handle the wrong-repo PR problem, but noticed it didn't cover the case where Claude Code opens the PR. That was the nudge I needed to add this feature.

How It Works

When you click "Create PR" in Claude Code, it opens a GitHub compare page with a URL like:

github.com/upstream-owner/upstream-repo/compare/main...you:your-fork:claude/your-branch

The extension now detects that this page was opened from Claude Code (by checking the referrer), and redirects to:

github.com/you/your-fork/compare/main...you:claude/your-branch

It also fetches your fork's actual default branch — so if your fork uses develop instead of main, the redirect respects that.

The Decision Logic

The extension only redirects when all of these are true:

  • You're on a GitHub /compare/ page
  • The URL is comparing against a different repo (upstream)
  • The page was opened from claude.ai
  • The extension hasn't already redirected (to prevent loops)

If any of those conditions aren't met, the extension stays out of the way. And if you do want to create a PR against upstream after the redirect, you can still click "Compare across forks" and select it manually — the extension won't interfere a second time.

What About Other AI Tools?

Right now the extension checks specifically for claude.ai as the referrer. If other AI coding tools start opening GitHub compare pages the same way, I can add support for those too. If you run into this with a different tool, let me know.

Try It Out

This feature works automatically — no configuration needed. Just make sure you have the latest version of Safe Pull Request installed, and the next time Claude Code tries to open a PR against upstream, the extension will catch it.

I've been using Claude Code on a forked repo for several months, using the "Create PR" feature, and it's been working great for me: opening the PRs against my repo, not the upstream repo. Let me know if it works for you.


Safe Pull Request: Install the extension and stop accidental PRs to upstream repos — whether they come from you or your AI assistant.