|
| 1 | +name: Claude Code Review |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [opened, synchronize, ready_for_review, reopened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + claude-review: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + contents: read |
| 12 | + pull-requests: write |
| 13 | + issues: read |
| 14 | + actions: read |
| 15 | + id-token: write |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout PR head (fork) |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + ref: ${{ github.event.pull_request.head.sha }} |
| 22 | + fetch-depth: 1 |
| 23 | + |
| 24 | + - name: Remove prior Claude review comment (so review runs again) |
| 25 | + env: |
| 26 | + GH_TOKEN: ${{ github.token }} |
| 27 | + run: | |
| 28 | + pr=${{ github.event.pull_request.number }} |
| 29 | + repo=${{ github.repository }} |
| 30 | + |
| 31 | + # Find first issue comment whose body starts with "## Claude Code Review" |
| 32 | + comment_id=$(gh api repos/$repo/issues/$pr/comments \ |
| 33 | + --jq '.[] | select(.body | startswith("## Claude Code Review")) | .id' | head -n 1) |
| 34 | + |
| 35 | + if [ -n "$comment_id" ]; then |
| 36 | + echo "Deleting prior Claude review comment id=$comment_id" |
| 37 | + gh api -X DELETE repos/$repo/issues/comments/$comment_id |
| 38 | + else |
| 39 | + echo "No prior Claude review comment found." |
| 40 | + fi |
| 41 | + |
| 42 | + - name: Run Claude Code Review |
| 43 | + id: claude-review |
| 44 | + uses: anthropics/claude-code-action@v1 |
| 45 | + with: |
| 46 | + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} |
| 47 | + github_token: ${{ github.token }} |
| 48 | + |
| 49 | + plugin_marketplaces: 'https://github.com/anthropics/claude-code.git' |
| 50 | + plugins: 'code-review@claude-code-plugins' |
| 51 | + |
| 52 | + claude_args: > |
| 53 | + --allowedTools |
| 54 | + "Bash(gh pr view:*)" |
| 55 | + "Bash(gh pr diff:*)" |
| 56 | + "Bash(gh pr comment:*)" |
| 57 | + "Bash(gh api:*)" |
| 58 | + "Bash(gh search code:*)" |
| 59 | + "Bash(cat:*)" |
| 60 | + "Bash(ls:*)" |
| 61 | + "Bash(grep:*)" |
| 62 | + "Bash(python3:*)" |
| 63 | + "Bash(git:*)" |
| 64 | +
|
| 65 | + prompt: | |
| 66 | + /code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }} |
| 67 | +
|
| 68 | + Post the results as ONE top-level PR comment titled "Claude Code Review". |
| 69 | +
|
| 70 | + Output requirements (even if no issues): |
| 71 | + - Start with: files changed count + list up to 15 changed file paths |
| 72 | + - Then: a short summary of what the PR changes (3–6 bullets) |
| 73 | + - Then: findings: |
| 74 | + - If issues: list them with file path + line numbers when possible |
| 75 | + - If no issues: list at least 3 concrete "improvement opportunities" with file paths |
| 76 | +
|
| 77 | + If you cannot access the diff/files, say exactly what is blocked. |
| 78 | + If posting a PR comment is blocked, write the full review to the GitHub Actions job summary instead. |
| 79 | +
|
| 80 | + IMPORTANT: |
| 81 | + - Do NOT stop just because a previous "Claude Code Review" comment exists. |
| 82 | + - If a prior Claude review exists, post a NEW comment titled "Claude Code Review (updated)" that includes: |
| 83 | + - current head SHA: ${{ github.event.pull_request.head.sha }} |
| 84 | + - files changed count + up to 15 file paths |
| 85 | + - 3–6 bullet summary of changes |
| 86 | + - findings or at least 3 improvement opportunities with file paths |
| 87 | + Post as ONE top-level PR comment. |
| 88 | +
|
| 89 | + additional_permissions: | |
| 90 | + actions: read |
0 commit comments