anthropics / anthropics/claude-code-action

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

Open
#967 0 comments 0 reactions 0 assignees View on GitHub
bug p2 provider:bedrock
Dominant language
TypeScript
Stars
8.9k
Forks
2.1k
Avg merge
3d 9h
Merged PRs (30d)
10

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**

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):

```yaml
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**

- [x] 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.

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

**Proposed fix**
https://github.com/anthropics/claude-code-action/pull/966

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.