Skip to content

restoreConfigFromBase fails on repos with non-"main" default branch #1080

@elijahr

Description

@elijahr

Bug

When claude-code-action runs on a repository whose default branch is master (or anything other than main), the config restore step fails with:

fatal: couldn't find remote ref main
Error: Action failed with error: Command failed: git fetch origin main --depth=1

This happens because baseBranch falls back to hardcoded "main" in several places when no explicit base_branch input is provided.

Affected locations

File Line(s) Code
src/modes/agent/index.ts ~89, ~96 process.env.BASE_BRANCH || context.inputs.baseBranch || "main"
src/entrypoints/run.ts ~315 baseBranch || "main"
src/entrypoints/update-comment-link.ts ~256 process.env.BASE_BRANCH || "main"

Expected behavior

When base_branch is not provided, the action should detect the repository's actual default branch instead of assuming "main".

The fix already exists in the codebase

src/github/operations/branch.ts (~line 185) already implements the correct pattern:

const repoResponse = await octokits.rest.repos.get({ owner, repo });
sourceBranch = repoResponse.data.default_branch;

Alternatively, ${{ github.event.repository.default_branch }} is available in the Actions context and could be used as the fallback instead of hardcoding "main".

Workaround

Callers can pass base_branch explicitly:

- uses: anthropics/claude-code-action@v1
  with:
    base_branch: ${{ github.event.repository.default_branch }}

Reproduction

  1. Use claude-code-action@v1 on a repo whose default branch is master
  2. Trigger via PR comment
  3. Action fails at the config restore step before Claude even runs

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