Skip to content

Commit 3390e22

Browse files
authored
fix: enable gh CLI for Claude to create PRs directly (#13)
- Added Bash(gh:*) to allowedTools so Claude can use gh CLI - Added author_association security check (only OWNER/COLLABORATOR) - Changed permissions to write for contents, pull-requests, issues - Added allowed_bots: "claude" to code review workflow - Added --system-prompt to inform Claude of its gh CLI capabilities Stu Mason + AI <me@stumason.dev>
1 parent a63dc54 commit 3390e22

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

.github/workflows/claude-code-review.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
uses: anthropics/claude-code-action@v1
2727
with:
2828
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
29+
allowed_bots: "claude"
2930
use_sticky_comment: true
3031
claude_args: |
3132
--allowedTools "Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Read,Glob,Grep"

.github/workflows/claude.yml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,38 @@ on:
1212

1313
jobs:
1414
claude:
15+
# Only owners and collaborators can trigger Claude (security: prevents unauthorized use)
1516
if: |
16-
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
17-
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
18-
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
19-
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
17+
(
18+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude') &&
19+
(github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'COLLABORATOR')) ||
20+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude') &&
21+
(github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'COLLABORATOR')) ||
22+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude') &&
23+
(github.event.review.author_association == 'OWNER' || github.event.review.author_association == 'COLLABORATOR')) ||
24+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')) &&
25+
(github.event.issue.author_association == 'OWNER' || github.event.issue.author_association == 'COLLABORATOR'))
26+
)
2027
runs-on: ubuntu-latest
2128
permissions:
22-
contents: read
23-
pull-requests: read
24-
issues: read
29+
contents: write
30+
pull-requests: write
31+
issues: write
2532
id-token: write
26-
actions: read # Required for Claude to read CI results on PRs
33+
actions: read
34+
2735
steps:
2836
- name: Checkout repository
2937
uses: actions/checkout@v6
3038
with:
31-
fetch-depth: 1
39+
fetch-depth: 0
3240

3341
- name: Run Claude Code
3442
id: claude
3543
uses: anthropics/claude-code-action@v1
3644
with:
3745
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
38-
39-
# This is an optional setting that allows Claude to read CI results on PRs
40-
additional_permissions: |
41-
actions: read
42-
43-
# Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
44-
# prompt: 'Update the pull request description to include a summary of changes.'
45-
46-
# Optional: Add claude_args to customize behavior and configuration
47-
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
48-
# or https://code.claude.com/docs/en/cli-reference for available options
49-
# claude_args: '--allowed-tools Bash(gh pr:*)'
50-
46+
claude_args: |
47+
--model claude-opus-4-5
48+
--allowedTools "Bash(gh:*),Bash(npm:*),Bash(composer:*)"
49+
--system-prompt "You can create PRs with 'gh pr create', merge with 'gh pr merge', and comment with 'gh issue comment'. Use gh CLI for all GitHub operations."

0 commit comments

Comments
 (0)