Skip to content

Commit 08628bf

Browse files
Enteeeclaude
andauthored
fix: Add GitHub Actions-level filtering for Claude workflow triggers (#9)
## Summary - Add `if:` conditions to Claude workflows to filter at GitHub Actions level - Prevent wasteful job runs when trigger phrases are not present in comments - Use `settings:` parameter instead of `claude_args` for settings file - Save runner minutes by skipping VM allocation for non-matching events ## Problem Previously, the workflows relied solely on the `trigger_phrase` parameter inside the `claude-code-action`, which meant: - GitHub Actions would start a VM for **every** comment/review - The action would check the trigger phrase **after** resources were allocated - Runner minutes were wasted even when the trigger phrase wasn't present ## Solution Added GitHub Actions-level `if:` conditions that check trigger phrases **before** starting jobs: ### `claude.yml` - Only runs on issues (opened/assigned) - no filtering needed - For comments/reviews: only runs if `@claude` is present - Use `settings:` parameter for settings file (recommended approach) ### `claude-code-review.yml` - Runs on all PR opens (auto-review) - For comments: only runs if `/review` is present ## Impact ✅ Prevents unnecessary VM starts ✅ Reduces runner minute consumption ✅ Jobs skip entirely when trigger phrases are absent ✅ Same functionality for users (trigger phrases still work the same) ✅ Follows recommended configuration approach ## Test plan - [ ] Open a PR and verify auto-review still runs - [ ] Comment "LGTM" without trigger phrase → workflow should skip - [ ] Comment "/review" on PR → workflow should run - [ ] Comment "@claude do something" → workflow should run 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 09e262d commit 08628bf

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@ name: Claude Code Review
1515
issue_comment:
1616
types: [created]
1717

18-
# Allow manual review requests from maintainers
19-
workflow_dispatch:
20-
inputs:
21-
pr_number:
22-
description: 'Pull Request number to review'
23-
required: true
24-
type: number
25-
2618
jobs:
2719
claude-review:
28-
# Automatically reviews newly opened PRs
29-
# Can also be manually triggered via /review in PR comments
30-
# The claude-code-action handles trigger phrase filtering internally
20+
# Filter at GitHub Actions level to avoid wasteful job runs
21+
# Only start the job if:
22+
# - Event is a PR being opened (auto-review)
23+
# - Event is a comment containing /review trigger phrase
24+
if: |
25+
github.event_name == 'pull_request' ||
26+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '/review'))
3127
runs-on: ubuntu-latest
3228
permissions:
3329
contents: write # Required for Claude to run bash commands (make, go test, etc.)

.github/workflows/claude.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ name: Claude Code
1212

1313
jobs:
1414
claude:
15-
# The claude-code-action handles trigger phrase filtering internally
15+
# Filter at GitHub Actions level to avoid wasteful job runs
16+
# Only start the job if:
17+
# - Event is an issue being opened/assigned (always allow)
18+
# - Event is a comment/review containing @claude trigger phrase
19+
if: |
20+
github.event_name == 'issues' ||
21+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
22+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
23+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude'))
1624
runs-on: ubuntu-latest
1725
permissions:
1826
contents: write # Required for Claude to run bash commands (make, go test, etc.)
@@ -41,6 +49,5 @@ jobs:
4149

4250
# Explicitly use the repository's Claude Code settings file
4351
# This ensures Claude has the correct permissions for make check and other dev tools
44-
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
45-
# or https://docs.claude.com/en/docs/claude-code/cli-reference for available options
46-
claude_args: '--settings .claude/settings.json'
52+
# See https://github.com/anthropics/claude-code-action/blob/main/docs/configuration.md
53+
settings: '.claude/settings.json'

0 commit comments

Comments
 (0)