Skip to content

Comments

fix: handle fork PRs by fetching via refs/pull/N/head#963

Open
stakeswky wants to merge 1 commit intoanthropics:mainfrom
stakeswky:fix/fork-pr-checkout
Open

fix: handle fork PRs by fetching via refs/pull/N/head#963
stakeswky wants to merge 1 commit intoanthropics:mainfrom
stakeswky:fix/fork-pr-checkout

Conversation

@stakeswky
Copy link

Summary

Fixes #962.

When claude-code-action is triggered via @claude on a pull request from a fork, the action fails with:

fatal: couldn't find remote ref feat/add-archive-timestamp

This happens because git fetch origin <branch> is used, but the branch only exists on the fork's remote.

Fix

Detect cross-repository PRs using the isCrossRepository GraphQL field and fetch via pull/<number>/head:<branch> refspec — the standard GitHub mechanism for accessing fork PR branches.

Changes

  • GraphQL query: Add isCrossRepository and headRepository fields to PR_QUERY
  • Types: Add corresponding fields to GitHubPullRequest
  • Branch checkout: Use pull/N/head refspec for fork PRs, keeping the existing fetch origin <branch> path for same-repo PRs
  • Tests: Update all PR test fixtures with the new fields

Testing

  • All 652 existing tests pass
  • TypeScript typecheck passes
  • The fix is minimal and only changes the fetch strategy for cross-repo PRs

When a PR originates from a fork, `git fetch origin <branch>` fails
because the branch only exists on the fork's remote.

Fix: detect cross-repository PRs via the `isCrossRepository` GraphQL
field and fetch using `pull/<number>/head:<branch>` refspec instead,
which is the standard GitHub mechanism for accessing fork PR branches.

Changes:
- Add `isCrossRepository` and `headRepository` to PR GraphQL query
- Add corresponding fields to GitHubPullRequest type
- Branch checkout uses pull ref for fork PRs
- Update test fixtures with new fields
@arr2036
Copy link

arr2036 commented Feb 23, 2026

Please merge this. The claude GH action is pretty much useless for external contributions without this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude-code-action fails to checkout fork PRs

2 participants