anthropics / anthropics/claude-code-action

Fork PRs fail: action fetches branch by name instead of using refs/pull/N/head

Open
#1,218 2 comments 0 reactions 0 assignees View on GitHub
bug p2
Dominant language
TypeScript
Stars
8.9k
Forks
2.1k
Avg merge
3d 9h
Merged PRs (30d)
10

Description

## Bug

When `@claude` is tagged on a PR that originates from a fork, the action fails with:

```
fatal: couldn't find remote ref
```

## Root Cause

In `src/modes/tag/index.ts` / `src/github/data/fetcher.ts`, the action runs:

```
git fetch origin --depth=20
```

For fork PRs, the branch only exists on the fork's remote, not on `origin`. GitHub exposes fork PR content at `refs/pull//head`, but the action doesn't use this ref.

## Reproduction

1. Have a repo with a PR from an external fork
2. Comment `@claude` on that PR
3. Action crashes at the `git fetch` step

## Expected Behavior

The action should detect fork PRs and fetch using `refs/pull//head` instead of the branch name. For example:

```bash
git fetch origin "pull/${PR_NUMBER}/head:${BRANCH_NAME}"
```

## Attempted Workarounds (all failed)

We tried pre-fetching the branch in a workflow step before the action runs:

```yaml
- name: Pre-fetch fork PR branch
run: |
git fetch origin "pull/$PR_NUMBER/head:$HEAD_REF"
git fetch origin "pull/$PR_NUMBER/head:refs/remotes/origin/$HEAD_REF"
```

Both the local branch and `refs/remotes/origin/` are successfully created, but the action still explicitly runs `git fetch origin --depth=20 ` which contacts the remote and fails because the branch name doesn't exist there.

## Additional Issue

When the action crashes during this setup phase, it does not update the initial comment it created to indicate the failure. The comment remains in a "working" state permanently.

## Environment

- `anthropics/claude-code-action@v1` (SHA: `1c8b699d43e9bfed42b48ef15da85d89bab70960`)
- Using Vertex AI provider
- Triggered via `issue_comment` event on a fork PR

Contributor guide

Open the contributing guide

Research direction

Start in src/modes/tag/index.ts and src/github/data/fetcher.ts, tracing the setup-phase git fetch for pull requests from forks. Verify the action uses refs/pull//head rather than a branch name, and check the failure path so the initial working comment is updated when setup fails. Reproduce with an issue_comment event on a fork PR.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, github-actions, typescript
Domain
ci-cd, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.