anthropics / anthropics/claude-code-action

Git safe.directory error when running in container job

Aperta
#161 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
bug p1
Lingua principale
TypeScript
Stelle
8.9k
Fork
2.1k
Merge medio
3g 9h
PR unite (30g)
10

Descrizione

**Describe the bug**
When claude-code-action is run in a [container job](https://docs.github.com/en/actions/writing-workflows/choosing-where-your-workflow-runs/running-jobs-in-a-container), it throws the following error:

```console
Run bun run ${GITHUB_ACTION_PATH}/src/entrypoints/prepare.ts
...
Successfully fetched PR #115633 data
This is an open PR, checking out PR branch...
fatal: detected dubious ownership in repository at '/__w/example/example'
To add an exception for this directory, call:

git config --global --add safe.directory /__w/example/example
Error: Prepare step failed with error: Failed with exit code 128
Error: Process completed with exit code 1.
```

**To Reproduce**
Here is a snippet of the workflow to reproduce this issue.

```yaml
jobs:
claude-code-action:
runs-on: ubuntu-latest
container:
image: # Our custom image
options: --user root
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@beta
with:
# Omit...
```

**Expected behavior**
The git command successfully finish.

For a workaround, just setting `safe.directory` config resolves this issue.

```yaml
steps:
- run: git config --global --add safe.directory /__w/example/example # <-- Set your repository name
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@beta
```

**API Provider**
Not related to this issue.

**Additional context**
For actions/checkout, it sets `safe.directory` config temporarily to avoid this issue.
https://github.com/actions/checkout/blob/09d2acae674a48949e3602304ab46fd20ae0c42f/src/git-source-provider.ts#L46-L60

I'm not sure about the security concern of `safe.directory` config, but let me share a workaround.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.