From 6a23a57b264a30464593f0fb6c7719b54431ef1a Mon Sep 17 00:00:00 2001 From: Rasmus Widing Date: Tue, 19 Aug 2025 11:02:47 +0300 Subject: [PATCH] Override event context to prevent PR checkout - Set GITHUB_EVENT_NAME to workflow_dispatch to avoid PR detection - Use override_prompt instead of direct_prompt for better control - Create wrapper script for debugging - Explicitly tell Claude not to checkout code --- .github/workflows/claude-review-fork.yml | 47 ++++++++++++++++++------ 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/.github/workflows/claude-review-fork.yml b/.github/workflows/claude-review-fork.yml index 31f42277..89d585fd 100644 --- a/.github/workflows/claude-review-fork.yml +++ b/.github/workflows/claude-review-fork.yml @@ -137,28 +137,53 @@ jobs: echo "Created diff for PR #$PR_NUMBER" echo "Diff size: $(wc -l < pr-diff.patch) lines" - - name: Run Claude Code Review + # Create a simple wrapper script to run Claude without PR context + - name: Create Claude Execution Script + if: steps.should-continue.outputs.should_continue == 'true' + run: | + cat > run-claude.sh << 'EOF' + #!/bin/bash + echo "Running Claude Code Review on pr-diff.patch" + + # Read the diff file + if [ ! -f pr-diff.patch ]; then + echo "Error: pr-diff.patch not found" + exit 1 + fi + + # Create a review summary + echo "## Claude Code Review for PR #$PR_NUMBER" + echo "Diff file contains $(wc -l < pr-diff.patch) lines of changes" + echo "Review will be posted as a comment on the PR" + EOF + + chmod +x run-claude.sh + + - name: Run Claude Code Review (Alternative) if: steps.should-continue.outputs.should_continue == 'true' id: claude uses: anthropics/claude-code-action@beta timeout-minutes: 15 env: - # Override to prevent checkout of PR branch - GITHUB_REF: refs/heads/${{ github.event.repository.default_branch }} - GITHUB_SHA: ${{ github.event.pull_request.base.sha || github.sha }} + # Make it look like we're not in a PR context + GITHUB_EVENT_NAME: 'workflow_dispatch' + GITHUB_EVENT_PATH: '/dev/null' with: claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} # Explicitly provide GitHub token github_token: ${{ secrets.GITHUB_TOKEN }} - # Trigger phrase for manual reviews - trigger_phrase: "@claude-review-fork" - - # Tell Claude to analyze the diff file instead of checking out code - direct_prompt: | - IMPORTANT: Analyze the pr-diff.patch file that has already been created in the current directory. - Do NOT attempt to checkout any code. The diff file contains all the changes you need to review. + # Override prompt to skip PR detection and review the diff + override_prompt: | + You are performing a code review for PR #${{ env.PR_NUMBER }} from a fork. + + First, read the pr-diff.patch file that contains all the changes. + Then provide a detailed code review following the format below. + Finally, post your review as a comment on issue #${{ env.PR_NUMBER }}. + + DO NOT attempt to checkout any code or fetch from git. + The diff file has everything you need. # Custom instructions for fork review custom_instructions: |