Skip to content

Commit 9dcc02c

Browse files
authored
Fix Slack notify prompt to use literal values, not $VAR (#999)
Claude Code's permission matcher denies any Bash command containing an unexpanded shell variable (e.g. "$PR_NUMBER"), regardless of whether the rest of the command matches an allowedTools wildcard like Bash(gh:*). The prompt told Claude to build its gh command from env vars using shell expansion, so every attempt was denied no matter how it was quoted, and Claude burned all 30 turns retrying variations before timing out. Interpolate the PR number, repo, URL, and workspace path directly into the prompt text via GitHub Actions expressions instead, so the Bash command Claude runs contains literal values with no expansion. None of these are PR-content-controlled (they come from trusted event/repository context), so embedding them is safe. Verified locally: ran the rendered prompt through the claude CLI with the same allowedTools/model/max-turns and got num_turns=3, permission_denials=0, and a correct output file. Co-authored-by: Dan Barr <6922515+danbarr@users.noreply.github.com>
1 parent 9b7f0db commit 9dcc02c

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

.github/workflows/autogen-docs-notify.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ jobs:
102102
# nor make arbitrary network calls (no curl/Bash beyond gh).
103103
- name: Compose reviewer summary
104104
uses: anthropics/claude-code-action@51705da45eecce209d4700538bf8377d5b5fc695 # v1.0.152
105-
env:
106-
PR_NUMBER: ${{ github.event.pull_request.number }}
107-
GH_REPO: ${{ github.repository }}
108-
PR_URL: ${{ github.event.pull_request.html_url }}
109105
with:
110106
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
111107
# Skips claude-code-action's OIDC -> GitHub App token exchange
@@ -140,16 +136,11 @@ jobs:
140136
the `gh` CLI. A later, separate, deterministic step does the
141137
actual Slack posting.
142138
143-
Context (available to you as environment variables):
144-
PR_NUMBER - the PR number
145-
GH_REPO - owner/repo of this repository
146-
PR_URL - the PR's html_url
147-
MESSAGE_FILE - the path to write the JSON output file to
148-
GH_TOKEN - auth for the `gh` CLI
149-
150139
STEP 1 — Read the PR.
151-
Run:
152-
gh pr view "$PR_NUMBER" --repo "$GH_REPO" --json title,body,reviewRequests,files,url
140+
Run this exact command (the values below are already
141+
filled in -- do not substitute shell variables, and do
142+
not quote the numbers or the repo name):
143+
gh pr view ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --json title,body,reviewRequests,files,url
153144
From the JSON, extract:
154145
- the PR title
155146
- the PR body. The body contains a marker-delimited
@@ -164,16 +155,16 @@ jobs:
164155
are GitHub logins).
165156
166157
STEP 2 — Write the message content as JSON.
167-
Use the **Write** tool to write a file at the path given by
168-
the env var MESSAGE_FILE. The file MUST be valid JSON with
169-
EXACTLY this shape:
158+
Use the **Write** tool to write a file at exactly this path:
159+
${{ github.workspace }}/.autogen-docs-slack-message.json
160+
The file MUST be valid JSON with EXACTLY this shape:
170161
{
171162
"headline": "<one line naming the upstream project/version, plain text>",
172163
"summary_bullets": ["...", "..."],
173164
"reviewers": [
174165
{"login": "<github login>", "note": "<what THIS reviewer should check>"}
175166
],
176-
"pr_url": "<the PR url>"
167+
"pr_url": "${{ github.event.pull_request.html_url }}"
177168
}
178169
Rules:
179170
- "headline" is plain text only (NO Slack/markdown link
@@ -191,7 +182,7 @@ jobs:
191182
have produced any user- or docs-facing changes, which is
192183
expected and fine, and in that case their approval simply
193184
confirms nothing was missed in the generated docs.
194-
- "pr_url" is the value of the PR_URL env var.
185+
- "pr_url" must be copied exactly as filled in above.
195186
Do NOT include any Slack ids, Slack mrkdwn, `<@...>` tags, or
196187
`<url|text>` links — only the plain content above. Do NOT
197188
post anything. Do NOT call curl. After writing the file,

0 commit comments

Comments
 (0)