Skip to content

restoreConfigFromBase fails on issue_comment events when default branch is not main #1085

@msmx-mnakagawa

Description

@msmx-mnakagawa

Summary

When claude-code-action is triggered by an issue_comment event on a PR, restoreConfigFromBase() attempts to fetch origin/main regardless of the repository's actual default branch, causing the action to fail for repositories that use master (or any non-main branch) as their default.

Steps to Reproduce

  1. Use a repository where the default branch is master
  2. Configure claude-code-action on issue_comment events
  3. Post a comment that triggers the action on an open PR

Expected Behavior

The action fetches config from the repository's actual default branch (or the PR's base branch).

Actual Behavior

Restoring .claude, .mcp.json, .claude.json, .gitmodules, .ripgreprc from origin/main (PR head is untrusted)
fatal: couldn't find remote ref main
Action failed with error: Command failed: git fetch origin main --depth=1

Root Cause

In src/entrypoints/run.ts (around line 238), the issue_comment event does not match any of isPullRequestEvent, isPullRequestReviewEvent, or isPullRequestReviewCommentEvent, so restoreBase falls back to baseBranch provided by agent mode — which defaults to "main".

The existing comment in the code acknowledges this:

agent mode's branchInfo.baseBranch defaults to "main" rather than the PR's actual target (agent/index.ts). For issue_comment on a PR the payload lacks base.ref, so we fall back to the mode-provided value — tag mode fetches it from GraphQL; agent mode on issue_comment is an edge case that at worst restores from the wrong trusted branch (still secure).

However, the "at worst restores from the wrong trusted branch" assumption does not hold when the fallback branch (main) does not exist at all — the action fails entirely instead.

Possible Fix

For the issue_comment + isPR case, fetch the PR's base branch via the GitHub API (the PR number is already known from context.entityNumber) rather than relying on the mode-provided default.

Alternatively, fall back to the repository's default_branch from GET /repos/{owner}/{repo} instead of hardcoding "main".

Workaround

Setting base_branch: master in the action inputs appears to work around the issue, though it should not be necessary.

Environment

  • claude-code-action@v1
  • Repository default branch: master
  • Trigger event: issue_comment (on a PR)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2Non-showstopper bug or popular feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions