Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 72 additions & 3 deletions .github/workflows/claude.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ name: Claude

# Answers `@claude` in an issue, a pull request comment, an inline review comment or a review body,
# with the Claude Code GitHub Action (https://code.claude.com/docs/en/github-actions). Its main job is
# reviewing pull requests, including ones from outside contributors' forks.
# reviewing pull requests, including ones from outside contributors' forks. It runs Claude Fable (the
# `fable` alias: the newest Fable the action's Claude Code knows). `--append-system-prompt` sets the
# tone: findings as inline review comments, and a short, casual summary comment.
#
# TWO JOBS. `route` decides whether the thread is a pull request from a fork, from GitHub's own record
# of the head repository, and nothing else; then exactly one of these runs:
#
# - `own`: an issue, or a pull request from a branch of this repository. Claude signs in to GitHub as
# the Claude GitHub App (comments are signed claude[bot]) and can push a branch and open a pull
# request. The text it reads can still be an outsider's (an issue anyone filed), so it keeps the
# guards that cost nothing here: hooks off, no `git tag`, and the `v*` tag ruleset on the repository.
# - `fork`: a pull request from a fork. The guards below.
#
# It signs in with the maintainer's Claude SUBSCRIPTION, not an API key: the repository secret
# CLAUDE_CODE_OAUTH_TOKEN holds the long-lived token `claude setup-token` prints, and every run counts
Expand All @@ -15,7 +26,7 @@ name: Claude
# pull request text, every comment on it and, on a pull request, the contributor's whole tree. Mention
# `@claude` on an outsider's thread only after reading what is there.
#
# PULL REQUESTS FROM FORKS. Only a comment in the conversation (`issue_comment`) works there: it runs
# PULL REQUESTS FROM FORKS (the `fork` job). Only a comment in the conversation (`issue_comment`) works there: it runs
# this file from the default branch with its secrets. GitHub gives a fork's review and inline review
# comment events no secrets, so `@claude` in a review on a fork's pull request fails for want of a token.
# The action checks out the pull request's HEAD and restores only `.claude/`, CLAUDE.md, AGENTS.md and a
Expand All @@ -33,6 +44,7 @@ name: Claude
# github-actions[bot], and it cannot push the `pr-N` branch the action would otherwise make of a fork.
# No `id-token: write`: with a token passed in, the action does not need OIDC, and an OIDC token from
# the default branch would satisfy this repository's Anthropic federation rule (issue-labels.yml).
# That is why forks get their own job (`fork`), with permissions no step can widen.
# - Project hooks are off (`disableAllHooks`): the SessionEnd hook runs `tools/build-gc.sh`, which on a
# fork is the contributor's copy. Every hook in `.claude/settings.json` is tooling for the maintainer's
# Mac anyway.
Expand Down Expand Up @@ -63,7 +75,7 @@ concurrency:
cancel-in-progress: false

jobs:
claude:
route:
if: |
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude') &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) ||
Expand All @@ -75,6 +87,61 @@ jobs:
(contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')) &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.issue.author_association))
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
pull-requests: read
outputs:
fork: ${{ steps.kind.outputs.fork }}
steps:
# A fork is a pull request whose head repository is not this one; a deleted fork (no head
# repository) counts as a fork. Only numbers and repository names reach the shell.
- name: Is this a pull request from a fork?
id: kind
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number || (github.event.issue.pull_request && github.event.issue.number) || '' }}
run: |
fork=false
if [ -n "$PR" ]; then
head=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq '.head.repo.full_name // ""')
[ "$head" = "$GITHUB_REPOSITORY" ] || fork=true
fi
echo "pull request: ${PR:-none}, head: ${head:-n/a}, fork: $fork"
echo "fork=$fork" >> "$GITHUB_OUTPUT"

own:
needs: route
if: needs.route.outputs.fork == 'false'
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: write # push a branch for an issue, or to this repository's pull request branch
pull-requests: write # open a pull request, inline review comments
issues: write # the progress comment
id-token: write # the action exchanges it for the Claude GitHub App's token
actions: read # lets Claude read a pull request's CI results
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 1
persist-credentials: false

- name: Run Claude Code
uses: anthropics/claude-code-action@f431adaf77e0fecf918431e75a2b5b45b85af002 # v1.0.283
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
claude_args: >-
--model fable
--append-system-prompt "Write like a teammate on GitHub: short, casual, plain words. Put each finding on the line it is about as an inline review comment, one or two sentences, with a suggestion block when the fix is small. Keep the summary comment to a few lines: a one-line verdict, then at most a few bullets for what is not tied to a line. No headings, no restating the PR, no list of files you read, no praise. If nothing needs changing, say so in one line."
--settings '{"disableAllHooks":true}'
--disallowedTools "Bash(git tag:*)" "Bash(git push --tags:*)"
--allowedTools "mcp__github_inline_comment__create_inline_comment"

fork:
needs: route
if: needs.route.outputs.fork == 'true'
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: read
Expand Down Expand Up @@ -109,6 +176,8 @@ jobs:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
claude_args: >-
--model fable
--append-system-prompt "Write like a teammate on GitHub: short, casual, plain words. Put each finding on the line it is about as an inline review comment, one or two sentences, with a suggestion block when the fix is small. Keep the summary comment to a few lines: a one-line verdict, then at most a few bullets for what is not tied to a line. No headings, no restating the PR, no list of files you read, no praise. If nothing needs changing, say so in one line."
--settings '{"disableAllHooks":true,"disableSkillShellExecution":true}'
--disallowedTools "Skill" "Agent" "Task" "Bash(curl:*)" "Bash(wget:*)" "Bash(gh:*)"
"Bash(git push:*)" "Bash(git tag:*)" "Bash(tools/:*)" "Bash(./tools/:*)" "Read(//proc/**)"
Expand Down
Loading