anthropics / anthropics/claude-code-action

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

オープン
#967 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug p2 provider:bedrock
主要言語
TypeScript
スター
8.9k
フォーク
2.1k
平均マージ
3日 9時間
マージ済み PR(30日)
10

説明

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

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。