Skip to content

Fix post-edit-compile hook execution by explicitly using bash#198

Merged
DiamondDagger590 merged 3 commits into
recodefrom
claude/fix-cursor-spam-issue-fAtFC
Mar 4, 2026
Merged

Fix post-edit-compile hook execution by explicitly using bash#198
DiamondDagger590 merged 3 commits into
recodefrom
claude/fix-cursor-spam-issue-fAtFC

Conversation

@DiamondDagger590
Copy link
Copy Markdown
Owner

@DiamondDagger590 DiamondDagger590 commented Mar 4, 2026

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

  • Modified .claude/settings.json to prefix the hook command with bash
    • Changed from: ".claude/hooks/post-edit-compile.sh"
    • Changed to: "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

  • Chores
    • Improved invocation for the post-edit/compile step to increase reliability.
    • Hardened CI review workflow: added detection for missing review artifacts, made artifact download and subsequent review steps conditional, added guards to skip review and comment posting when inputs or outputs are absent, and ensured conditional propagation of artifacts to avoid unnecessary runs.

…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
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8990da2e-95ac-4514-bf9d-fbce98cfb564

📥 Commits

Reviewing files that changed from the base of the PR and between ef1d0eb and 510834a.

📒 Files selected for processing (1)
  • .github/workflows/pr-review-run.yml

Walkthrough

Updated a PostToolUse hook command to invoke the script via bash, and added guarded logic in the PR review workflow to detect the presence of a pr-review-inputs artifact, download it only if present, and conditionally run subsequent setup, AI review, and posting steps.

Changes

Cohort / File(s) Summary
Hook invocation
\.claude/settings.json
Change PostToolUse command from executing the script path directly to invoking it via bash .claude/hooks/post-edit-compile.sh.
PR review workflow
.github/workflows/pr-review-run.yml
Add initial step to check for pr-review-inputs artifact; conditionally download artifact (with run-id and token) and load metadata only if present; add guards to setup, AI review, and post-comment steps so they run only when artifact exists (and when API key/comment present); propagate conditional execution and avoid posting empty comments.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly matches the main change in .claude/settings.json, which explicitly invokes bash for the hook script execution.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-cursor-spam-issue-fAtFC

Comment @coderabbitai help to get the list of available commands and usage tips.

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
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, so hashFiles() will return a non-empty string. This allows gh pr comment to 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

📥 Commits

Reviewing files that changed from the base of the PR and between bc63480 and ef1d0eb.

📒 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
@DiamondDagger590 DiamondDagger590 merged commit ea5b9c8 into recode Mar 4, 2026
3 checks passed
@DiamondDagger590 DiamondDagger590 deleted the claude/fix-cursor-spam-issue-fAtFC branch March 4, 2026 05:04
DiamondDagger590 added a commit that referenced this pull request Mar 12, 2026
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants