Skip to content

feat(guardrails): block foreground until loops and --watch waits - #15955

Merged
kyle-sexton merged 4 commits into
mainfrom
work-resolve-issue/issue-15941-43424069395-1
Nov 13, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
work-resolve-issue/issue-15941-43424069395-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #15941

Summary

Opened by the work-resolve-issue lane. The run's own summary:

Adds the guardrails PreToolUse guard block-foreground-wait. It denies a foreground Bash call that waits with an until loop or a --watch flag, with a reason that names the fix: set run_in_background to true or watch the command with the Monitor tool. The hooks reference (https: //code.claude.com/docs/en/hooks, section "PreToolUse input" > "Bash") lists run_in_background (boolean) in the Bash tool input, so a hook can tell a background call from a foreground one; a call whose run_in_background is true passes. Design choices and their basis: the guard runs on the existing Bash|PowerShell dispatcher row beside its nearest neighbor, block-cd-prefix, and copies its fail-open posture and kill-switch shape. --watch is found as an unquoted argument word through the shared shfmt segment parser, stopping at -- and skipping echo/printf. until is a shell keyword the segment parser does not hand to a callback, so it is matched where a command starts, on the command text with heredoc bodies (from the parser's byte offsets), quoted spans, escapes and comments cut out. run_in_background is read only after the text could match, so other commands pay no extra jq process. Configurability: like its sibling guards and per the plugin's kill-switch convention, a userConfig boolean block_foreground_wait_enabled, on by default, documented in plugin.json and in the README's kill-switch and options tables. Dogfooding step: this repository's .claude/settings.json enables guardrailsmelodic-software, so once this release is published and the marketplace copy updates, sessions in this repository run the new guard with no settings change, since it is on by default.

Not verified

  • block-foreground-wait.test.sh and run-guards.test.sh were not executed: this lane runs no test scripts, so the suites are left to the PR's CI.
  • Tidy not run: the change spans two areas (plugins/guardrails with .changes/guardrails, and docs/catalog.md), over the one-area tidy cutoff.
  • The issue's decision that rung and proof come from /corrections:codify was not applied: that skill is not loaded in this lane. The guard follows the existing guardrails kill-switch and contract-test pattern instead.
  • Known gaps, documented in the guard header and README: a wait inside bash -c, a double-quoted "$(...)" or a heredoc a shell reads; -w short flags and the watch command. Known false positives: until as an argument right after ), } or a word such as do.
  • Changes are left uncommitted in the working tree, as the runner's instructions direct, rather than committed as ci-mode step 3 describes.

Fix

  • plugins/guardrails/hooks/block-foreground-wait.sh: new guard; denies a foreground until loop or --watch on the Bash tool, passes run_in_background true, quoted/comment/heredoc text, --watch=<value>, --watch-path, echo/printf and the PowerShell tool; kill switch…
  • plugins/guardrails/hooks/block-foreground-wait.test.sh: new contract test; 14 blocked and 17 allowed forms run directly and under run-guards.sh, the kill switch, and the hooks.json and plugin.json registration.
  • plugins/guardrails/hooks/hooks.json: dispatches block-foreground-wait.sh on the Bash|PowerShell row; description and status message name it.
  • plugins/guardrails/hooks/guard-requires.sh: declares the guard's primed fields (.tool_input.command, .tool_name) and its unprimed .tool_input.run_in_background read.
  • plugins/guardrails/hooks/run-guards.test.sh: adds the guard to the list hooks.json must dispatch.
  • plugins/guardrails/.claude-plugin/plugin.json: adds the block_foreground_wait_enabled userConfig option (default true); description counts 17 guards and names foreground waits, shortened to stay within the 500-character limit.
  • plugins/guardrails/README.md: guard count, a block-foreground-wait row in the guard table, the kill-switch table row and the options reference row.
  • docs/catalog.md: regenerated guardrails catalog line to match the new plugin.json description.
  • .changes/guardrails/work-resolve-issue-issue-15941-43424069395-1-d5007980.md: minor changelog fragment for the new guard.

Verification

The runner ran each check from the base copy against dd70d3f:

  • scripts/check-changelog-fragments.sh --check: passed
  • scripts/check-changed-skills.sh --merge-base: passed

The run reports:

  • read https: //code.claude.com/docs/en/hooks: section "PreToolUse input" > "Bash" lists tool_input fields command, description, timeout and run_in_background (boolean, "Whether to run the command in background"); "Exit code 2" says a PreToolUse hook blocks the tool call with exit 2 and its stderr…
  • check-changelog-fragments: all 37 fragments valid.
  • check-changed-skills: no changed skills, nothing to gate.
  • check-affected: 13 passed, 6 skipped (ruff, typos, changed-skills and three validate-plugins sub-checks that run tree code) over 9 changed files; earlier runs caught a shellcheck SC1003 in the guard, a 511-character plugin description and a stale docs/catalog.md line, each fixed.
  • fresh-context review subagent over the whole diff: traced every test case by hand both direct and dispatched and found none failing; reported a stripper that dropped the last character, an ANSI-C $'...\'' false block, missing if/while/elif/time keyword positions and an undocumented…
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/43424069395

Left out: the items under Not verified.

Related

#15941

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 6a511348062281d73d708d896a8c751e26da2adc: read 9 of 9 changed file(s); 1 finding(s), 1 as inline comments.

Security review: PR #15955 (head 6a511348)

critical-findings: 0

I read every hunk of all 9 changed files. An earlier head was already reviewed, so this review reports blocking findings only.

Result: no exploitable security issue. The one finding is a manifest flag that the default-deny rule requires for a newly added userConfig key. It counts as a finding and holds nothing.

Manifest (plugins/guardrails/.claude-plugin/plugin.json)

  • manifest description: pass. The field is in the inert set.
  • manifest userConfig.block_foreground_wait_enabled: pass, advisory. It is a boolean kill switch, default true (protective). The hook only compares it to "true" to decide whether the guard runs, at block-foreground-wait.sh:44.
  • manifest userConfig.block_foreground_wait_script_runners: flag, a string key with no options list that a hook reads. That makes it neither a selector nor an inert key, so default deny flags it. Details are in the inline comment. No exploit path was found.

What I checked

  • New guard block-foreground-wait.sh:
    • It only adds denies (exit 2) and never allows a command another guard denied.
    • Command text never reaches eval, a command substitution or an unquoted expansion.
    • The heredoc offsets used in ${FWG_COMMAND:at:s-at} and ((s < at)) come from shfmt's parse tree, as byte offsets (hook-utils.sh:4440-4449). They are not command text, so arithmetic evaluation cannot inject anything. block-unresolved-pr-merge.sh already uses the same pattern.
    • The runner list is compared with a quoted right-hand side (== "$cmd"), so a value in it cannot act as a glob or run code.
    • It fails open on bad payloads; the PR states this as a choice for an advisory guard. That is safe: the guard is new, and the fail-closed guards on the same row are unchanged.
  • Dispatcher row (hooks.json), guard-requires.sh, run-guards.test.sh: the guard is added to the existing Bash|PowerShell row. onFailure: "block" and the 60-second timeout are unchanged, and no existing guard is removed or reordered.
  • Trust controls: none touched. No trusted-actor list, token request, kill-switch action, merge hold or workflow is changed.
  • Instruction surfaces: no standing instruction is deleted or softened. The README, catalog and changelog changes are descriptions only.
  • Settled thread: the npm test -- --watch thread is resolved by the owner with no lines changed since, so it is not raised again.
  • PR context: the pull request text holds no instructions aimed at this review.
  • Spend: none. The change adds a local hook and has no billing surface.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude-review: 1 inline finding(s) on dd70d3f2ffcc1cb3db84dc4ab37fdfac984b1283; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 6a511348062281d73d708d896a8c751e26da2adc: read 9 of 9 changed file(s); 1 finding(s), 0 as inline comments.

Code review (blocking only): 6a51134

Scope. I read the whole diff: all 9 files in .claude-lane/files.txt. This lane has already reviewed earlier heads, so this review is blocking only. Advisory findings are left out.

The earlier inline finding is resolved and settled. It was the --watch after -- thread on block-foreground-wait.sh. The owner fixed it in 62996ca. The thread is marked lines changed since resolution: no, so I did not raise it again. I traced the new script-runner path by hand against the head and did not run it:

  • fwg::segment (block-foreground-wait.sh:91-116) keeps scanning past -- only when the command word's basename is in FWG_RUNNERS.
  • npm test -- --watch hits --watch and is denied.
  • grep -- --watch README.md returns at -- and is allowed.
  • When the option is set but empty, the array is empty and every scan stops at --. The ${FWG_RUNNERS[@]+…} guard keeps set -u safe.

The test file covers all three cases. The author reports PASS=112 FAIL=0; I did not run it, so that is author-claimed and unverified.

Restated summary finding (blocking, closing issue #15941).

  1. Closing-issue decision not applied. The issue's Decisions section says: "Rung and proof come from /corrections:codify." The PR body says this was not applied because that skill is not loaded in the lane. Instead, the guard follows the guardrails kill-switch and contract-test pattern. The change still does not meet that decision. A person needs to decide whether the substitute is acceptable or whether /corrections:codify should still be run.

Closing-issue "Done when" items. These are met in the diff:

  • The hooks reference section is cited in the PR body.
  • Foreground until and --watch are blocked, and the background and unrelated forms are allowed. Tests cover both the denied and the allowed forms.
  • The block message names the fix.
  • The behavior is a documented setting: the block_foreground_wait_enabled and block_foreground_wait_script_runners options.
  • The PR body names the dogfooding step.

Manifest (plugins/guardrails/.claude-plugin/plugin.json):

  • manifest userConfig block_foreground_wait_enabled (new): pass. It defaults to true, and block-foreground-wait.sh:44 reads CLAUDE_PLUGIN_OPTION_BLOCK_FOREGROUND_WAIT_ENABLED.
  • manifest userConfig block_foreground_wait_script_runners (new): pass. It defaults to npm,pnpm,yarn,bun,npx, and block-foreground-wait.sh:82 reads it.
  • manifest version: pass. The changelog fragment's bump: minor matches an added guard.
  • manifest description: pass. It now says 17 guards and names "foreground waits". docs/catalog.md and the hooks.json description match it.

Other notes

  • Embedded instructions: none in the PR context, settled-threads or prior-findings files.
  • Cost: none. The new guard costs one extra jq process, only on Bash calls whose text could match.

Verifier dropped 0 of 0 candidates. There were no new blocking candidates, so I dispatched no verifier.

@melodic-automation-lanes melodic-automation-lanes Bot added the needs-session A pr-unblock stop a session builder takes: a change the lane cannot make. Not an owner stop. label Nov 13, 2026
@melodic-automation-lanes

melodic-automation-lanes Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

The pr-unblock lane stopped address-feedback on this pull request: a disputed review finding on a thread a person opened or directed, or a disputed CRITICAL code-review finding, is one no lane decides, so a session builder takes it. The lane labels it needs-session for a session builder, who makes the change this lane cannot, and the run ends in a failing pr-unblock/address-feedback status on the head the lane gated.

When a retry on this head can change the outcome, the lane runs one on its own, up to its per-head cap, and edits this comment if it stops again; a run that does not stop clears the status. When no retry can (a review thread the lane does not take or settle, or a failing check after the retries are spent), a person resolves the threads or gets the checks green, then dispatches the workflow below: that run finds the cause gone and clears the status. On a pull request the lanes App opened, the dispatchers start that run once per stop; on any other, a person does. A new commit to the branch starts clean.

To run it again on this head now, dispatch the pr-unblock workflow:

gh workflow run pr-unblock.yml -R melodic-software/claude-code-plugins -f pr-number=15955 -f activity=address-feedback

@melodic-automation-lanes

melodic-automation-lanes Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Unattended merge: native auto-merge leaves this pull request unarmed at head 6a511348062281d73d708d896a8c751e26da2adc. No person needs to act: a lane clears this reason, and the next scheduled run judges it again.

a pr-unblock lane stopped its head (pr-unblock/address-feedback is failure), which clears when the
  lane runs again

kyle-sexton and others added 2 commits November 13, 2026 08:29
…wait

The --watch scan stopped at the first unquoted --, so npm test -- --watch,
npm run test -- --watch and pnpm vitest -- --watch, which hand --watch to a
watch-mode test runner, ran in the foreground unblocked. A command word in
the new block_foreground_wait_script_runners option (default
npm,pnpm,yarn,bun,npx; empty stops every scan at --) keeps the scan going
past --. grep -- --watch stays allowed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton kyle-sexton removed the needs-session A pr-unblock stop a session builder takes: a change the lane cannot make. Not an owner stop. label Nov 13, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

claude-security-review: 1 inline finding(s) on 6a511348062281d73d708d896a8c751e26da2adc; the summary is in this lane's pull request comment.

claude-lane: claude-security-review

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 1 of max 4 on 6a51134.

@melodic-automation-lanes melodic-automation-lanes Bot added the needs-session A pr-unblock stop a session builder takes: a change the lane cannot make. Not an owner stop. label Nov 13, 2026
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 2 of max 4 on 6a51134.

@kyle-sexton kyle-sexton removed the needs-session A pr-unblock stop a session builder takes: a change the lane cannot make. Not an owner stop. label Nov 13, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit 7131451 Nov 13, 2026
140 of 141 checks passed
@kyle-sexton
kyle-sexton deleted the work-resolve-issue/issue-15941-43424069395-1 branch November 13, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block foreground until and --watch waits with a plugin hook

1 participant