fix: correct Claude PR review to use BASE_SHA for accurate diff comparison #5654
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
$BASE_SHA
instead oforigin/$BASE_BRANCH
Problem
As identified in #5651 (comment #5651 (comment)), the Claude automated review was incorrectly analyzing changes that weren't part of the PR being reviewed. The review was mentioning Turkish language removal, linkRenderer changes, and other modifications that weren't in the actual PR diff.
Root Cause Analysis
The Issue Explained (from Discord discussion)
When Christian Byrne noticed Claude was referencing things from previous reviews on other PRs, we investigated and found:
The backport branch was created from origin/main BEFORE Turkish language support was merged
main.A
main.A.Backport
Turkish language support was then merged into origin/main
main.A.Turkish
Claude review workflow checked out
main.A.Backport
and ran git diff againstorigin/main
main.A.Backport <> main.A.Turkish
+++Backport
changes and---Turkish
removalmain.A
Why This Happens
When using
origin/$BASE_BRANCH
, git resolves to the latest commit on that branch. The diff includes:This causes Claude to review changes that appear as "removals" of code from other merged PRs, leading to confusing comments about unrelated code.
Solution
Changed the git diff commands to use
$BASE_SHA
directly, which GitHub Actions provides as the exact commit SHA that represents the merge base. This ensures Claude only reviews the actual changes introduced by the PR.Before (incorrect):
After (correct):
Technical Details
GitHub Actions Environment Variables
BASE_SHA
: The commit SHA of the merge base (where PR branched from main)BASE_BRANCH
: Not provided by GitHub Actions (this was the bug)origin/$BASE_BRANCH
was falling back to comparing against the latest main commitAlternative Approaches Considered
Testing
The BASE_SHA environment variable is already correctly set in the claude-pr-review.yml workflow (line 88), so this change will work immediately once merged.
Impact
Verification
You can verify this fix by:
Credits
Thanks to @christian-byrne for reporting the issue and @snomiao for the root cause analysis.
🤖 Generated with Claude Code