Fix post-edit-compile hook execution by explicitly using bash#198
Conversation
…ile.sh Changed the PostToolUse hook command from a bare script path to `bash .claude/hooks/post-edit-compile.sh`. When the command was just the script path, Cursor's file watcher treated the hook execution as a file-open event and kept opening the script in the editor on every Edit/Write tool use. Using `bash` as the executable prevents that behaviour. https://claude.ai/code/session_01Q8UzY4htCB81sf2sahAKju
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoRun configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughUpdated a PostToolUse hook command to invoke the script via Changes
Sequence Diagram(s)sequenceDiagram
participant Workflow as GitHub Actions Workflow
participant Artifact as Artifact Storage
participant Runner as Actions Runner
participant AI as External AI Service
participant GH as GitHub API
Workflow->>Artifact: Check for `pr-review-inputs` artifact
alt artifact exists
Workflow->>Artifact: Download artifact (with run-id, github-token)
Artifact-->>Runner: Provide artifact files
Runner->>Runner: Load review metadata
Runner->>Runner: Conditional Setup (Python, env) if metadata present
Runner->>AI: Run AI persona reviews (requires API key)
AI-->>Runner: Return review outputs (e.g., review_comment.txt)
alt review_comment.txt non-empty
Runner->>GH: Post review comment
else
Runner-->>GH: Skip posting (empty comment)
end
else no artifact
Workflow-->>Runner: Skip download and review steps
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
When prepare-review is skipped (no review-relevant files changed), the AI PR Review workflow still concludes 'success', causing pr-review-run.yml to trigger and then fail trying to download a non-existent artifact. Added a 'Check for review artifact' step that queries the GitHub API for the pr-review-inputs artifact before attempting to download it. All subsequent steps are conditioned on exists == 'true', so the job exits cleanly with a descriptive message when there is nothing to review. https://claude.ai/code/session_01Q8UzY4htCB81sf2sahAKju
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/workflows/pr-review-run.yml (1)
101-109:⚠️ Potential issue | 🟠 Major
hashFiles()returns a hash even for empty files—add a content check before posting.The condition at line 101 (
hashFiles('review_comment.txt') != '') only verifies that the file exists. An empty file will still produce a valid SHA-256 hash, sohashFiles()will return a non-empty string. This allowsgh pr commentto run with an empty body file, which should be prevented.Add the proposed file-size check:
Suggested fix
if: steps.check-artifact.outputs.exists == 'true' && steps.check-key.outputs.available == 'true' && hashFiles('review_comment.txt') != '' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | + if [[ ! -s review_comment.txt ]]; then + echo "No review content — skipping comment." + exit 0 + fi if [[ "$(head -c 4 review_comment.txt)" == "<!--" ]]; then echo "Suppressed comment — not posting." exit 0 fi gh pr comment ${{ steps.meta.outputs.pr_number }} --body-file review_comment.txt🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/pr-review-run.yml around lines 101 - 109, The current workflow only checks hashFiles('review_comment.txt') which can be non-empty for an empty file; update the job so it refuses to post when review_comment.txt has zero bytes by adding an explicit file-size check before running gh pr comment — for example, keep the existing if condition but add a shell check in the run block such as testing review_comment.txt with -s (or an equivalent non-zero-length check) and exit 0 with a clear message if the file is empty; ensure this guards the gh pr comment invocation that uses review_comment.txt.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In @.github/workflows/pr-review-run.yml:
- Around line 101-109: The current workflow only checks
hashFiles('review_comment.txt') which can be non-empty for an empty file; update
the job so it refuses to post when review_comment.txt has zero bytes by adding
an explicit file-size check before running gh pr comment — for example, keep the
existing if condition but add a shell check in the run block such as testing
review_comment.txt with -s (or an equivalent non-zero-length check) and exit 0
with a clear message if the file is empty; ensure this guards the gh pr comment
invocation that uses review_comment.txt.
ℹ️ Review info
Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: e3cee009-5cd8-4141-8c8d-401947d2a65a
📒 Files selected for processing (1)
.github/workflows/pr-review-run.yml
hashFiles() returns a non-empty hash even for a zero-byte file, so the existing if-condition alone could pass and post an empty comment. Added an explicit -s check at the top of the run block that exits 0 with a clear message when the file has no content. https://claude.ai/code/session_01Q8UzY4htCB81sf2sahAKju
* fix: invoke hook via bash to stop Cursor spamming open post-edit-compile.sh Changed the PostToolUse hook command from a bare script path to `bash .claude/hooks/post-edit-compile.sh`. When the command was just the script path, Cursor's file watcher treated the hook execution as a file-open event and kept opening the script in the editor on every Edit/Write tool use. Using `bash` as the executable prevents that behaviour. https://claude.ai/code/session_01Q8UzY4htCB81sf2sahAKju * fix: skip review gracefully when prepare-review artifact is missing When prepare-review is skipped (no review-relevant files changed), the AI PR Review workflow still concludes 'success', causing pr-review-run.yml to trigger and then fail trying to download a non-existent artifact. Added a 'Check for review artifact' step that queries the GitHub API for the pr-review-inputs artifact before attempting to download it. All subsequent steps are conditioned on exists == 'true', so the job exits cleanly with a descriptive message when there is nothing to review. https://claude.ai/code/session_01Q8UzY4htCB81sf2sahAKju * fix: guard against empty review_comment.txt before posting PR comment hashFiles() returns a non-empty hash even for a zero-byte file, so the existing if-condition alone could pass and post an empty comment. Added an explicit -s check at the top of the run block that exits 0 with a clear message when the file has no content. https://claude.ai/code/session_01Q8UzY4htCB81sf2sahAKju --------- Co-authored-by: Claude <noreply@anthropic.com>
Summary
Updated the post-edit-compile hook command to explicitly invoke bash, ensuring the script executes properly regardless of the system's default shell.
Changes
.claude/settings.jsonto prefix the hook command withbash".claude/hooks/post-edit-compile.sh""bash .claude/hooks/post-edit-compile.sh"Details
This change ensures the hook script runs with bash explicitly, rather than relying on the shebang line or system default shell. This improves reliability across different environments and shell configurations.
https://claude.ai/code/session_01Q8UzY4htCB81sf2sahAKju
Summary by CodeRabbit