-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
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
- Have a workflow in current-workflow-repo
- Use
actions/checkoutto check out another-repo into the workspace - Run
claude-code-action(e.g., in agent mode) - In a subsequent step, run
git pushor use an action likeEndBug/add-and-commit - 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: trueAPI 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()insrc/github/operations/git-config.tsbuilds the remote URL fromcontext.repository(derived fromGITHUB_REPOSITORYenv var), which is always the workflow's host repo.- A fix would be to read the current
git remote get-url originand inject the auth token into it, rather than constructing a new URL fromcontext.repository. This preserves whatever repoactions/checkoutset 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-gitProposed fix
#966