ci: auto-apply Claude PR review suggestions #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Claude Auto-Apply Review Suggestions | |
| on: | |
| pull_request_review: | |
| types: [submitted] | |
| concurrency: | |
| group: claude-autofix-${{ github.event.pull_request.number }} | |
| cancel-in-progress: true | |
| jobs: | |
| autofix: | |
| # Only run when claude[bot] submits a review on a non-fork PR | |
| if: github.event.review.user.login == 'claude[bot]' && github.event.pull_request.head.repo.full_name == github.repository | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| permissions: | |
| contents: write | |
| pull-requests: read | |
| steps: | |
| - name: Checkout PR branch | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.pull_request.head.ref }} | |
| fetch-depth: 1 | |
| - name: Apply review suggestions | |
| # Pinned to SDK 0.2.25 (last working version) due to AJV validation crash in 0.2.27+ | |
| # Tracking: https://github.com/anthropics/claude-code-action/issues/892 | |
| # Remove pin when issue is resolved and @v1 is stable again | |
| uses: anthropics/claude-code-action@01e756b34ef7a1447e9508f674143b07d20c2631 | |
| with: | |
| anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} | |
| github_token: ${{ github.token }} | |
| allowed_bots: "claude" | |
| claude_args: '--max-turns 20 --allowedTools "Read,Edit,Write,Bash(gh api:*),Bash(gh pr view:*),Bash(git add:*),Bash(git commit:*),Bash(git push:*),Bash(git diff:*)"' | |
| prompt: | | |
| Apply the code suggestions from Claude's PR review on PR #${{ github.event.pull_request.number }} in repo ${{ github.repository }}. | |
| Steps: | |
| 1. Fetch Claude's inline review comments: | |
| gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/comments \ | |
| --jq '[.[] | select(.user.login == "claude[bot]")]' | |
| 2. For each comment, check if it contains a concrete code suggestion (e.g. a code block showing a proposed change, a specific line replacement, etc.) | |
| 3. Apply each concrete suggestion to the corresponding file and location | |
| 4. Skip any comment that is purely informational, raises an architectural concern, asks a question, or requires a product decision | |
| 5. If any changes were made: | |
| git add -A | |
| git commit -m "chore: apply Claude review suggestions" | |
| git push | |
| 6. If no actionable code suggestions exist, do nothing - no commit needed | |
| IMPORTANT: Only apply clear, unambiguous code-level changes. Do not implement new features, refactor beyond what is explicitly suggested, or make any judgment calls. |