Skip to content

claude-code-action overwrites git remote origin when workspace checks out a different repo #967

@vasilii-bolgar-212

Description

@vasilii-bolgar-212

Describe the bug

When claude-code-action runs in a workflow that checks out a different repository than the one hosting the workflow, the action overwrites the git origin remote URL to point at the workflow's repository instead of the checked-out repository. This causes any subsequent git push steps to push to the wrong repo.

The root cause is in configureGitAuth() — it constructs the remote URL from GITHUB_REPOSITORY (the workflow's repo) rather than preserving the remote URL that actions/checkout set up.

To Reproduce

  1. Have a workflow in current-workflow-repo
  2. Use actions/checkout to check out another-repo into the workspace
  3. Run claude-code-action (e.g., in agent mode)
  4. In a subsequent step, run git push or use an action like EndBug/add-and-commit
  5. Observe: the push targets current-workflow-repo instead of another-repo

Expected behavior

After claude-code-action completes, the git remote origin should still point at another-repo (the repo that was checked out), not current-workflow-repo (the workflow's repo). Subsequent git push operations should target the checked-out repository.

Workflow yml file

Simplified structure (sensitive data removed):

jobs:
  claude:
    steps:
      # Step 1: Checkout another-repo into the workspace
      - uses: actions/checkout@v4
        with:
          repository: org/another-repo
          fetch-depth: 0
          token: ${{ steps.app-token.outputs.token }}

      # Step 2: Checkout current-workflow-repo into a subdirectory (for reference/skills)
      - uses: actions/checkout@v4
        with:
          repository: org/current-workflow-repo
          path: subdir

      # Step 3: Run Claude Code Action
      - uses: anthropics/claude-code-action@v1
        with:
          prompt: "do something"

      # Step 4: Commit and push — THIS FAILS
      # Push goes to current-workflow-repo instead of another-repo
      - uses: EndBug/add-and-commit@v9
        with:
          push: true

API Provider

  • AWS Bedrock

Additional context

  • The error on push is: failed to push some refs to 'https://github.com/org/current-workflow-repo.git' — confirming the remote was changed from another-repo to current-workflow-repo.
  • configureGitAuth() in src/github/operations/git-config.ts builds the remote URL from context.repository (derived from GITHUB_REPOSITORY env var), which is always the workflow's host repo.
  • A fix would be to read the current git remote get-url origin and inject the auth token into it, rather than constructing a new URL from context.repository. This preserves whatever repo actions/checkout set up, and falls back to the current behavior if reading the remote fails.

Workaround

Set origin and auth token back to desired.

      - name: Restore Git credentials
        run: |
          git remote set-url origin https://github.com/org/current-workflow-repo.git
          gh auth setup-git

Proposed fix
#966

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2Non-showstopper bug or popular feature requestprovider:bedrockAWS Bedrock API

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions