55 types : [opened, edited, reopened, synchronize]
66 paths :
77 - ' **.md'
8- pull_request_review_comment :
8+ issue_comment :
99 types : [created]
10- pull_request_review :
11- types : [submitted]
1210
1311jobs :
1412 claude-response :
1513 runs-on : ubuntu-latest
14+ # For issue_comment events, only run on PR comments that mention @claude
15+ if : |
16+ github.event_name == 'pull_request_target' ||
17+ (github.event_name == 'issue_comment' &&
18+ github.event.issue.pull_request &&
19+ contains(github.event.comment.body, '@claude'))
1620 permissions :
1721 contents : write
1822 pull-requests : write
1923 issues : write
2024 id-token : write
2125 actions : read
2226 steps :
27+ - name : Get PR branch for issue_comment events
28+ id : pr-info
29+ if : github.event_name == 'issue_comment'
30+ env :
31+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
32+ run : |
33+ PR_DATA=$(gh pr view ${{ github.event.issue.number }} --repo ${{ github.repository }} --json headRefName,headRefOid)
34+ echo "branch=$(echo "$PR_DATA" | jq -r '.headRefName')" >> "$GITHUB_OUTPUT"
35+
2336 - name : Checkout repository
2437 uses : actions/checkout@v4
2538 with :
26- # Use head SHA (not branch ref) to prevent TOCTOU attacks from forks
27- ref : ${{ github.event.pull_request.head.sha || github.sha }}
28- fetch-depth : 0 # Need full history to compare with base branch
39+ # For fix mode, check out the branch by name so git push works.
40+ # For review mode, check out by SHA to prevent TOCTOU attacks from forks.
41+ ref : ${{ github.event_name == 'issue_comment' && steps.pr-info.outputs.branch || github.event.pull_request.head.sha || github.sha }}
42+ fetch-depth : 0
2943
3044 - name : Get changed markdown files
3145 id : changed-files
46+ if : github.event_name == 'pull_request_target'
3247 run : |
33- # Get the base branch
3448 BASE_SHA="${{ github.event.pull_request.base.sha }}"
3549 HEAD_SHA="${{ github.event.pull_request.head.sha }}"
36-
37- # Get only changed .md files
3850 CHANGED_MD_FILES=$(git diff --name-only --diff-filter=ACMRT $BASE_SHA $HEAD_SHA | grep '\.md$' || true)
39-
4051 if [ -z "$CHANGED_MD_FILES" ]; then
4152 echo "No markdown files changed"
4253 echo "files=" >> "$GITHUB_OUTPUT"
4354 echo "count=0" >> "$GITHUB_OUTPUT"
4455 else
4556 echo "Changed markdown files:"
4657 echo "$CHANGED_MD_FILES"
47- # Create a comma-separated list for the prompt
4858 FILES_LIST=$(echo "$CHANGED_MD_FILES" | tr '\n' ',' | sed 's/,$//')
4959 echo "files=$FILES_LIST" >> "$GITHUB_OUTPUT"
5060 echo "count=$(echo "$CHANGED_MD_FILES" | wc -l | tr -d ' ')" >> "$GITHUB_OUTPUT"
@@ -71,14 +81,15 @@ jobs:
7181 echo "EOF"
7282 } >> "$GITHUB_OUTPUT"
7383
74- - uses : anthropics/claude-code-action@v1
75- if : steps.changed-files.outputs.count > 0
84+ # Review mode: auto-triggered when markdown files change in a PR
85+ - name : Run documentation review
86+ uses : anthropics/claude-code-action@v1
87+ if : github.event_name == 'pull_request_target' && steps.changed-files.outputs.count > 0
7688 with :
7789 anthropic_api_key : ${{ secrets.ANTHROPIC_API_KEY }}
7890 github_token : ${{ secrets.GITHUB_TOKEN }}
7991 show_full_output : true
8092 use_sticky_comment : true
81-
8293 prompt : |
8394 Review ONLY the following markdown files that were changed in this PR: ${{ steps.changed-files.outputs.files }}
8495
@@ -92,3 +103,16 @@ jobs:
92103 --model claude-sonnet-4-5-20250929
93104 --allowedTools "Bash(gh pr diff:*),Bash(gh pr view:*)"
94105 --append-system-prompt "${{ steps.read-prompt.outputs.prompt }}"
106+
107+ # Fix mode: triggered when someone comments @claude on a PR
108+ - name : Apply fixes on @claude request
109+ uses : anthropics/claude-code-action@v1
110+ if : github.event_name == 'issue_comment'
111+ with :
112+ anthropic_api_key : ${{ secrets.ANTHROPIC_API_KEY }}
113+ github_token : ${{ secrets.GITHUB_TOKEN }}
114+ show_full_output : true
115+ claude_args : |
116+ --model claude-sonnet-4-5-20250929
117+ --allowedTools "Bash(gh pr view:*),Bash(gh pr diff:*),Bash(gh pr comment:*),Bash(git config:*),Bash(git add:*),Bash(git commit:*),Bash(git push:*),Bash(git status:*),Bash(git diff:*)"
118+ --append-system-prompt "${{ steps.read-prompt.outputs.prompt }}"
0 commit comments