claude-code-action icon indicating copy to clipboard operation
claude-code-action copied to clipboard

Claude Code Action fails with "couldn't find remote ref" error for PRs from forks

Open gabrielguimaraes opened this issue 6 months ago • 4 comments

Describe the bug The Claude Code Action fails when triggered on pull requests from forked repositories. The action attempts to fetch a branch that doesn't exist on the origin remote, resulting in the error: fatal: couldn't find remote ref [branch-name]. This occurs because PRs from forks only exist as PR refs (e.g., refs/pull/22/head) and not as regular branches on the origin remote.

To Reproduce Steps to reproduce the behavior:

  1. Create a fork of a repository that uses Claude Code Action for PR reviews
  2. Create a new branch in the fork and make changes
  3. Open a pull request from the fork to the original repository
  4. The Claude Code Action workflow triggers automatically
  5. See error: fatal: couldn't find remote ref [branch-name]

Expected behavior The Claude Code Action should successfully checkout and review PRs from forked repositories, just as it does for PRs from branches within the same repository. The action should use GitHub's PR refs (refs/pull/*/head) instead of trying to fetch non-existent branch names.

Screenshots Error from GitHub Actions logs: This is an open PR, checking out PR branch... PR #22: 1 commits, using fetch depth 20 fatal: couldn't find remote ref adding_claude_code_action Error: Prepare step failed with error: Failed with exit code 128 Error: Process completed with exit code 1.

Workflow yml file

name: Claude Code Review

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  claude-review:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
      issues: write
      id-token: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Run Claude Code Review
        id: claude-review
        uses: anthropics/claude-code-action@beta
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          github_token: ${{ secrets.GITHUB_TOKEN }}

          direct_prompt: |
            Please review this pull request and provide feedback on:
            - Code quality and best practices
            - Potential bugs or issues

API Provider

[x] Anthropic First-Party API (default) [ ] AWS Bedrock [ ] GCP Vertex

Additional context

  • The issue appears to be in the branch checkout logic at https://github.com/anthropics/claude-code-action/blob/main/src/github/operations/branch.ts
  • The action tries to run git fetch origin ${branchName} which fails for fork PRs because the branch doesn't exist on origin
  • The action should use git fetch origin +refs/pull/${prNumber}/head instead of trying to fetch branch names that don't exist on the origin remote
  • This is a common issue when working with GitHub Actions and PRs from forks, and the standard solution is to use PR refs

gabrielguimaraes avatar Jul 02 '25 16:07 gabrielguimaraes