anthropics / anthropics/claude-code-action
Title: [BUG] Action fails with "git hash-object" error when PR deletes files
- 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
The claude-code-action@v1 fails during the prepare step when a PR deletes or renames files. The action attempts to compute SHA hashes for all files in the PR diff using git hash-object, but this fails for deleted/renamed files because they don't exist on the PR branch.
To Reproduce
Create a PR that deletes or renames files
Trigger the claude-code-action via @claude mention or automatic PR review
Action fails with fatal: could not open '' for reading: No such file or directory
Error Log
fatal: could not open 'approval_service/backend/approval_django/approval/api/views/receive_task.py' for reading: No such file or directory
Failed to compute SHA for approval_service/backend/approval_django/approval/api/views/receive_task.py: warn: Command failed: git hash-object approval_service/backend/approval_django/approval/api/views/receive_task.py
fatal: could not open 'approval_service/backend/approval_django/approval/api/views/receive_task.py' for reading: No such file or directory
signal: null,
status: 128,
output: [
null, "", "fatal: could not open '...' for reading: No such file or directory\n"
],
at genericNodeError (node:child_process:941:13)
at checkExecSyncError (node:child_process:449:27)
at execFileSync (node:child_process:268:31)
at (/home/runner/work/_actions/anthropics/claude-code-action/v1/src/github/data/fetcher.ts:251:21)
at map (1:11)
at fetchGitHubData (/home/runner/work/_actions/anthropics/claude-code-action/v1/src/github/data/fetcher.ts:240:40)
This error repeats for each deleted file in the PR (12+ times in PR #31). The action then fails with:
This is an open PR, checking out PR branch...
PR #31: 3 commits, using fetch depth 20
fatal: not a git repository (or any of the parent directories): .git
Error: Prepare step failed with error: Failed with exit code 128
Error: Process completed with exit code 1.
Expected behavior
The action should handle deleted/renamed files gracefully by:
Skipping SHA computation for files that were deleted in the PR
Checking the file's diff status before attempting git hash-object
Or wrapping the git hash-object call in a try-catch that handles missing files
Root Cause Analysis
The issue is in src/github/data/fetcher.ts around line 240-251. The code iterates over all files in the PR diff and runs git hash-object on each one, but doesn't account for files with status removed or renamed.
Suggested Fix
typescript// In fetcher.ts around line 240-251
// Check file status before computing SHA
if (file.status === 'removed') {
// Skip deleted files - they don't exist on the PR branch
continue;
}
// For renamed files, use the new filename
const filename = file.status === 'renamed' ? file.filename : file.filename;
// Wrap in try-catch as safety net
try {
const sha = execFileSync('git', ['hash-object', filename]);
} catch (err) {
// File doesn't exist, skip SHA computation
console.warn(`Skipping SHA for missing file: ${filename}`);
}
Environment
Action version: anthropics/claude-code-action@v1
Runner: ubuntu-latest
Event: issue_comment (triggered by @claude mention on PR)
Bun version: 1.2.11
Workaround
Currently none known. PRs that delete files cannot use claude-code-action until this is fixed.
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.