From ceefba4146f64978ec919755f14e5b0cf44c6a89 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Thu, 19 Nov 2026 05:03:33 +0300 Subject: [PATCH 1/5] CI: answer @claude mentions with the Claude Code Action on the owner's subscription Adds .github/workflows/claude.yml: issue, PR comment, inline review comment and review-body mentions of @claude run anthropics/claude-code-action (pinned to v1.0.283), signed in with the CLAUDE_CODE_OAUTH_TOKEN secret from `claude setup-token`. Only owners, members and collaborators start a runner. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/claude.yml | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/claude.yml diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml new file mode 100644 index 0000000000..ce6160814b --- /dev/null +++ b/.github/workflows/claude.yml @@ -0,0 +1,64 @@ +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). +# +# 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 +# against that subscription's usage. To rotate it, run `claude setup-token` again and +# `gh secret set CLAUDE_CODE_OAUTH_TOKEN`; deleting the secret turns this workflow off (the job fails). +# +# Who can start it: the `if:` below lets only an owner, member or collaborator through, so a stranger's +# `@claude` on this public repository does not even start a runner; the action then checks again that +# the commenter has write access, and refuses bot actors. A comment on a pull request from a fork +# works: `issue_comment` and the review events run this file from the default branch with its +# secrets, never the fork's copy of it. +# +# Claude reads CLAUDE.md / AGENTS.md from the checkout like any session, so the repository's rules +# apply to what it writes. It can push a branch and open a pull request for an issue; it cannot push +# to a fork's branch, and `main` stays protected by the same rules as for anyone else. + +on: + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] + pull_request_review: + types: [submitted] + issues: + types: [opened, assigned] + +concurrency: + group: claude-${{ github.event.issue.number || github.event.pull_request.number }} + cancel-in-progress: false + +jobs: + claude: + if: | + (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude') && + contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) || + (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude') && + contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) || + (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude') && + contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.review.author_association)) || + (github.event_name == 'issues' && + (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: 60 + permissions: + contents: write + pull-requests: write + issues: write + id-token: write # the action's GitHub App token exchange + 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 + + - name: Run Claude Code + uses: anthropics/claude-code-action@f431adaf77e0fecf918431e75a2b5b45b85af002 # v1.0.283 + with: + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} From 4f77ae670e2966c5536ebf2ce357c3a4561abe61 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Thu, 19 Nov 2026 05:06:05 +0300 Subject: [PATCH 2/5] CI: turn project hooks off in the Claude job, and say which fork events work A fork PR's head is checked out with only .claude/ and the instruction files restored from the base, so the SessionEnd hook would run the fork's tools/build-gc.sh with the token in its environment. Also scrub subprocess credentials, drop the no-op `assigned` trigger, and correct the header: on a fork PR only conversation comments get secrets. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/claude.yml | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index ce6160814b..c0e7aa3e29 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -10,13 +10,22 @@ name: Claude # # Who can start it: the `if:` below lets only an owner, member or collaborator through, so a stranger's # `@claude` on this public repository does not even start a runner; the action then checks again that -# the commenter has write access, and refuses bot actors. A comment on a pull request from a fork -# works: `issue_comment` and the review events run this file from the default branch with its -# secrets, never the fork's copy of it. +# the commenter has write access, and refuses bot actors. # -# Claude reads CLAUDE.md / AGENTS.md from the checkout like any session, so the repository's rules -# apply to what it writes. It can push a branch and open a pull request for an issue; it cannot push -# to a fork's branch, and `main` stays protected by the same rules as for anyone else. +# Pull requests from forks: 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. +# +# Project hooks are OFF in this job (`disableAllHooks` below). On a pull request the action checks out +# the pull request's head and restores only `.claude/`, CLAUDE.md, AGENTS.md and a few config files from +# the base, so a hook that calls a repository script (the SessionEnd hook runs `tools/build-gc.sh`) +# would run a fork's copy of that script with the subscription token in its environment. Every hook in +# `.claude/settings.json` is tooling for the maintainer's Mac anyway. `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB` +# also keeps the credentials out of the commands Claude runs. +# +# Claude reads CLAUDE.md / AGENTS.md from the base like any session, so the repository's rules apply to +# what it writes. It can push a branch and open a pull request for an issue; it cannot push to a fork's +# branch, and `main` stays protected by the same rules as for anyone else. on: issue_comment: @@ -26,7 +35,7 @@ on: pull_request_review: types: [submitted] issues: - types: [opened, assigned] + types: [opened] concurrency: group: claude-${{ github.event.issue.number || github.event.pull_request.number }} @@ -59,6 +68,9 @@ jobs: fetch-depth: 1 - name: Run Claude Code + env: + CLAUDE_CODE_SUBPROCESS_ENV_SCRUB: "1" uses: anthropics/claude-code-action@f431adaf77e0fecf918431e75a2b5b45b85af002 # v1.0.283 with: claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} + claude_args: --settings '{"disableAllHooks":true}' From ed8967611b5a3f4250a7860090ccd174da6cca73 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Thu, 19 Nov 2026 05:20:59 +0300 Subject: [PATCH 3/5] CI: make the Claude job safe on outside contributors' fork PRs Use the job's read-only GITHUB_TOKEN instead of the org-wide App token (no push, no tag, no OIDC), turn off skills and subagents (on a fork they are the contributor's, through the .claude -> .agents links), disallow network and publishing commands, and sandbox Claude's commands with bubblewrap. Header rewritten to say what comes from the fork and what each guard is for. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/claude.yml | 75 ++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index c0e7aa3e29..e55045c3bf 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -1,31 +1,47 @@ 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). +# 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. # # 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 # against that subscription's usage. To rotate it, run `claude setup-token` again and # `gh secret set CLAUDE_CODE_OAUTH_TOKEN`; deleting the secret turns this workflow off (the job fails). # -# Who can start it: the `if:` below lets only an owner, member or collaborator through, so a stranger's -# `@claude` on this public repository does not even start a runner; the action then checks again that -# the commenter has write access, and refuses bot actors. +# WHO CAN START IT. The `if:` lets only an owner, member or collaborator through, so a stranger's +# `@claude` on this public repository does not start a runner; the action then checks again that the +# commenter has write access, and refuses bot actors. What Claude READS is another matter: the issue or +# 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. 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 +# few config files from the default branch. `.claude/skills` and `.claude/agents/*.md` are links into +# `.agents/`, and the nested module guides are not restored, so on a fork those come from the +# contributor. The job is therefore built so that nothing in the checkout runs and nothing Claude is +# talked into can publish: # -# Project hooks are OFF in this job (`disableAllHooks` below). On a pull request the action checks out -# the pull request's head and restores only `.claude/`, CLAUDE.md, AGENTS.md and a few config files from -# the base, so a hook that calls a repository script (the SessionEnd hook runs `tools/build-gc.sh`) -# would run a fork's copy of that script with the subscription token in its environment. Every hook in -# `.claude/settings.json` is tooling for the maintainer's Mac anyway. `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB` -# also keeps the credentials out of the commands Claude runs. -# -# Claude reads CLAUDE.md / AGENTS.md from the base like any session, so the repository's rules apply to -# what it writes. It can push a branch and open a pull request for an issue; it cannot push to a fork's -# branch, and `main` stays protected by the same rules as for anyone else. +# - The GitHub token is the job's own GITHUB_TOKEN (`github_token:` below), bounded by `permissions:`: +# it can comment on issues and pull requests and read CI, and it cannot push a commit, a branch or a +# tag. (The Claude GitHub App's token, the action's default, can write every repository in the +# organization, and release.yml publishes whatever `v*` tag is pushed.) Its comments are signed +# 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). +# - 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. +# - Skills and subagents are off (`Skill`, `Agent`, `Task` disallowed, `disableSkillShellExecution`): on +# a fork they are the contributor's, and a skill can grant itself tools. +# - Commands that reach the network or publish are disallowed (`curl`, `wget`, `gh`, `git push`, +# `git tag`); Claude comments through the action's own tools. For an author without write access the +# action also denies interpreters, shells, package managers and build tools, and turns git hooks off. +# - `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB` strips the Anthropic credentials from the commands Claude runs, and +# the sandbox step installs bubblewrap so those commands run in their own PID namespace and cannot read +# Claude's environment from /proc. GH_TOKEN stays in the environment; it is the short-lived job token. on: issue_comment: @@ -56,16 +72,29 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 60 permissions: - contents: write - pull-requests: write - issues: write - id-token: write # the action's GitHub App token exchange - actions: read # lets Claude read a pull request's CI results + contents: read + pull-requests: write # review comments and the progress comment + issues: write # comments on issues and on a pull request's conversation + 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 + + # The same setup the action runs for `allowed_non_write_users`: bubblewrap gives the scrubbed + # commands their own PID namespace, and Ubuntu 24.04 needs unprivileged user namespaces allowed. + - name: Sandbox for Claude's commands + run: | + for i in 1 2 3; do + sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends bubblewrap socat && break + echo "apt-get attempt $i failed, retrying..." + sleep 5 + done + if [ -f /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]; then + sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 + fi - name: Run Claude Code env: @@ -73,4 +102,8 @@ jobs: uses: anthropics/claude-code-action@f431adaf77e0fecf918431e75a2b5b45b85af002 # v1.0.283 with: claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} - claude_args: --settings '{"disableAllHooks":true}' + github_token: ${{ secrets.GITHUB_TOKEN }} + claude_args: >- + --settings '{"disableAllHooks":true,"disableSkillShellExecution":true}' + --disallowedTools "Skill" "Agent" "Task" "Bash(curl:*)" "Bash(wget:*)" "Bash(gh:*)" + "Bash(git push:*)" "Bash(git tag:*)" From 93b8a4eeaf766c447a5b4afd7bb5911233d8d351 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Thu, 19 Nov 2026 05:21:27 +0300 Subject: [PATCH 4/5] CI: install the Claude job's sandbox through the shared bounded apt-install ci/test_ci_timeouts.py requires every apt-get update under `timeout`. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/claude.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index e55045c3bf..6cdb9cd23e 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -85,13 +85,13 @@ jobs: # The same setup the action runs for `allowed_non_write_users`: bubblewrap gives the scrubbed # commands their own PID namespace, and Ubuntu 24.04 needs unprivileged user namespaces allowed. - - name: Sandbox for Claude's commands + # This runs from the default branch's checkout: the action checks the pull request out later. + - name: Install the sandbox for Claude's commands + uses: ./.github/actions/apt-install + with: + packages: bubblewrap socat + - name: Allow unprivileged user namespaces for the sandbox run: | - for i in 1 2 3; do - sudo apt-get update -qq && sudo apt-get install -y --no-install-recommends bubblewrap socat && break - echo "apt-get attempt $i failed, retrying..." - sleep 5 - done if [ -f /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]; then sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 fi From 09c4fd6aced307f91a8c580e91f23d29a8555ffd Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Thu, 19 Nov 2026 05:27:13 +0300 Subject: [PATCH 5/5] CI: deny the fork's tools/ scripts and /proc to the Claude job, post inline review comments Second security review: .claude/settings.json allows tools/ scripts that on a fork are the contributor's, and Read could open /proc/self/environ. Also turn on the inline-comment tool, and say plainly that the command rules are prefix rules and the token scope and scrub are the real limits. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/claude.yml | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 6cdb9cd23e..f0853a82d8 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -21,8 +21,10 @@ name: Claude # The action checks out the pull request's HEAD and restores only `.claude/`, CLAUDE.md, AGENTS.md and a # few config files from the default branch. `.claude/skills` and `.claude/agents/*.md` are links into # `.agents/`, and the nested module guides are not restored, so on a fork those come from the -# contributor. The job is therefore built so that nothing in the checkout runs and nothing Claude is -# talked into can publish: +# contributor. The job is therefore built so that the checkout's tooling does not run on its own, and +# whatever Claude is talked into, the token it holds cannot publish. The command rules below are +# prefix rules, not a boundary (an absolute path or another program gets past them); the real limits +# are the token's scope and the credential scrub: # # - The GitHub token is the job's own GITHUB_TOKEN (`github_token:` below), bounded by `permissions:`: # it can comment on issues and pull requests and read CI, and it cannot push a commit, a branch or a @@ -36,9 +38,12 @@ name: Claude # Mac anyway. # - Skills and subagents are off (`Skill`, `Agent`, `Task` disallowed, `disableSkillShellExecution`): on # a fork they are the contributor's, and a skill can grant itself tools. -# - Commands that reach the network or publish are disallowed (`curl`, `wget`, `gh`, `git push`, -# `git tag`); Claude comments through the action's own tools. For an author without write access the -# action also denies interpreters, shells, package managers and build tools, and turns git hooks off. +# - The obvious network and publishing commands are disallowed (`curl`, `wget`, `gh`, `git push`, +# `git tag`), and so are the repository's `tools/` scripts, which `.claude/settings.json` allows and +# which on a fork are the contributor's. Claude comments through the action's own tools, inline +# review comments included. For an author without write access the action also denies interpreters, +# shells, package managers and build tools, and turns git hooks off. +# - `Read` may not open /proc, where Claude's own environment (the subscription token) is readable. # - `CLAUDE_CODE_SUBPROCESS_ENV_SCRUB` strips the Anthropic credentials from the commands Claude runs, and # the sandbox step installs bubblewrap so those commands run in their own PID namespace and cannot read # Claude's environment from /proc. GH_TOKEN stays in the environment; it is the short-lived job token. @@ -73,8 +78,8 @@ jobs: timeout-minutes: 60 permissions: contents: read - pull-requests: write # review comments and the progress comment - issues: write # comments on issues and on a pull request's conversation + pull-requests: write # inline review comments + issues: write # the progress comment, on an issue or a pull request's conversation actions: read # lets Claude read a pull request's CI results steps: - name: Checkout repository @@ -106,4 +111,5 @@ jobs: claude_args: >- --settings '{"disableAllHooks":true,"disableSkillShellExecution":true}' --disallowedTools "Skill" "Agent" "Task" "Bash(curl:*)" "Bash(wget:*)" "Bash(gh:*)" - "Bash(git push:*)" "Bash(git tag:*)" + "Bash(git push:*)" "Bash(git tag:*)" "Bash(tools/:*)" "Bash(./tools/:*)" "Read(//proc/**)" + --allowedTools "mcp__github_inline_comment__create_inline_comment"