anthropics / anthropics/claude-code-action
Git safe.directory error when running in container job
- Langage dominant
- TypeScript
- Étoiles
- 8.9k
- Forks
- 2.1k
- Merge moyen
- 3 j 9 h
- PR mergées (30 j)
- 10
Description
**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.
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.