anthropics / anthropics/claude-code-action

Git safe.directory error when running in container job

Abierto
#161 0 comentarios 1 reacción 0 asignados Ver en GitHub
bug p1
Lenguaje dominante
TypeScript
Estrellas
8.9k
Forks
2.1k
Merge medio
3 d 9 h
PR fusionados (30 d)
10

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.