claude.yml 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. name: Claude Code
  2. on:
  3. issue_comment:
  4. types: [created]
  5. pull_request_review_comment:
  6. types: [created]
  7. issues:
  8. types: [opened, assigned]
  9. pull_request_review:
  10. types: [submitted]
  11. jobs:
  12. claude:
  13. if: |
  14. (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
  15. (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
  16. (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
  17. (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
  18. runs-on: ubuntu-latest
  19. permissions:
  20. contents: read
  21. pull-requests: read
  22. issues: read
  23. id-token: write
  24. actions: read # Required for Claude to read CI results on PRs
  25. steps:
  26. - name: Checkout repository
  27. uses: actions/checkout@v4
  28. with:
  29. fetch-depth: 1
  30. # Workaround for claude-code-action bug with fork PRs: The action tries to fetch by branch name, which doesn't
  31. # exist on origin for forks. Pre-fetch the PR ref so it's available as a local ref.
  32. - name: Fetch fork PR ref (if applicable)
  33. if: github.event.issue.pull_request != '' && github.event.issue.pull_request != null
  34. env:
  35. GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  36. run: |
  37. PR_NUMBER=$(gh pr view ${{ github.event.issue.number }} --json number -q .number 2>/dev/null || echo "")
  38. if [ -n "$PR_NUMBER" ]; then
  39. git fetch origin refs/pull/${PR_NUMBER}/head:refs/remotes/pull/${PR_NUMBER}/head || true
  40. fi
  41. - name: Run Claude Code
  42. id: claude
  43. uses: anthropics/claude-code-action@e763fe78de2db7389e04818a00b5ff8ba13d1360 # v1
  44. with:
  45. claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
  46. # This is an optional setting that allows Claude to read CI results on PRs
  47. additional_permissions: |
  48. actions: read
  49. # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
  50. # prompt: 'Update the pull request description to include a summary of changes.'
  51. # Optional: Add claude_args to customize behavior and configuration
  52. # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
  53. # or https://code.claude.com/docs/en/cli-reference for available options
  54. # claude_args: '--allowed-tools Bash(gh pr:*)'