Skip to content

fix(agent-config): route Claude Code's PowerShell tool to gate-bash - #1110

Merged
sandstream merged 3 commits into
mainfrom
claude/web-kit-status-sync-p6fg9a-protected-pwsh-matcher
Nov 27, 2026
Merged

sandstream merged 3 commits into
mainfrom
claude/web-kit-status-sync-p6fg9a-protected-pwsh-matcher

Conversation

@sandstream

@sandstream sandstream commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Protected change (src/agent-config.ts): the owner's to merge. macOS is unverified (no CI job runs macOS), and nobody has run this against a live Claude Code on Windows.

Problem

kit installed Claude Code's PreToolUse hook for kit gate-bash with the matcher Bash. Claude Code also has a PowerShell tool, so a command run through it never reached the gate. npm install <untriaged> and irm … | iex sent through PowerShell ran unchecked.

Evidence for the tool name and matcher

kit-research clickfix-vs-kit-install-gate listed this as not verified. The Claude Code hooks reference (https://code.claude.com/docs/en/hooks) says:

  • PowerShell tool input: "The fields match the Bash tool, with the command string in command", and "Match Bash|PowerShell in hooks that inspect shell commands, so they cover both tools: … On Windows without Git Bash, the tool is enabled automatically and Claude Code doesn't register the Bash tool at all. A hook that matches only Bash never fires there."
  • Matcher patterns: a matcher made only of letters, digits, _, -, spaces, , and | is a list of exact names. Bash|PowerShell is read as two exact names, not as a regular expression.

The gate does not depend on the tool name: it reads tool_input.command. src/install-gate-pipe-interp.test.ts already shows gate-bash exiting 2 for tool_name: "PowerShell".

Change

  • src/gate-bash-matcher.ts (new) holds GATE_BASH_MATCHER = "Bash|PowerShell", matcherSelects (Claude Code's documented matcher rules), staleGateBashMatchers and widenGateBashMatchers.
  • installInstallGate writes Bash|PowerShell. When the gate is already installed, it widens a stale matcher in place:
    • a group that holds only kit's gate gets the new matcher;
    • a gate that shares a group with other hooks moves to its own group, so those hooks keep their matcher;
    • a stale gate that another group already covers is dropped, so there is never a second gate-bash entry.
  • staleGateBashMatchersFor reads stale matchers in the project's .claude/settings*.json and in ~/.claude/settings.json. GateLiveness is unchanged. kit check (enforcement gate liveness) fails with matcher "Bash" does not select both of Claude Code's shell tools (Bash, PowerShell) … Run: kit agent-config. The kit hooks gates SessionStart path treats a stale matcher as not wired, so it repairs it.
  • The repair runs through kit agent-config, the remediation this check already names. kit fix does not touch PreToolUse gates today, and this PR does not change that.
  • Docs: docs/ENFORCEMENT_AND_AUDIT.md, the kit gate-bash row in docs/COMMANDS.md, and changes/pwsh-matcher.md.

Tests

src/gate-bash-matcher.test.ts:

  • A fresh install's matcher selects PowerShell. This test fails on main with matcher Bash must select PowerShell.
  • kit check fails on an old Bash-only entry. installInstallGate widens it to exactly one Bash|PowerShell group with one hook, a second run is unchanged, and the check then passes.
  • matcherSelects follows the documented rules.
  • Widening covers the shared-group, duplicate and untouched cases.

Fixtures that stand for a current install were updated to the new matcher.

Other harnesses, not changed

kit's harness fixtures (kit-research caniuse-agent-gates) document no separate PowerShell tool for any other harness, so none was changed. These are unverified on Windows:

  • Copilot CLI runs .claude/settings.json hooks, so it gets the new matcher, but its Windows shell tool name is not documented in the fixtures.
  • Codex (^Bash$), Amazon Q and Kiro (execute_bash), Droid (Execute), Augment (bash|launch-process), Antigravity (run_command) and Cline (execute_command) name one shell tool each. Nothing in kit says whether they have a separate PowerShell tool.
  • Gemini (matcher "") and Cursor (beforeShellExecution) are not tied to a tool name.
  • OpenCode checks the tools bash and shell.

Not in this PR

  • gate-egress (exec-broker, opt-in) is also installed with the matcher Bash and has the same gap.
  • Downloading a file and then running it as a second step passes gate-bash in both shells: iwr URL -OutFile x.exe; & .\x.exe and curl -o x URL; ./x both exit 0. Only a download piped or wrapped into iex/a shell is refused.

Generated by Claude Code

kit wired the Claude Code install gate with the matcher `Bash`, so a
command Claude Code ran through its `PowerShell` tool never reached
`kit gate-bash`. The Claude Code hooks reference says to "Match
`Bash|PowerShell` in hooks that inspect shell commands" and that "A hook
that matches only `Bash` never fires there" (Windows without Git Bash).

- New installs write `Bash|PowerShell` (src/gate-bash-matcher.ts).
- gateLiveness reports `Bash`-only gate-bash matchers (project and user
  settings); `kit check` fails enforcement gate liveness on one.
- `kit agent-config` (installInstallGate) and `kit hooks gates` widen a
  stale matcher in place, moving kit's gate out of a shared group and
  never leaving two gate-bash entries.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the already-installed branch (command refresh plus matcher widening)
into refreshInstallGate, and stop exporting SHELL_TOOLS (self-audit:
unreferenced export).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

CI standards failed: src/agent-config.ts grew past its frozen size
(1780 lines) and the gateLiveness describe block in agent-config.test.ts
changed hash while over 80 lines. Keep GateLiveness as it was and read
stale gate-bash matchers in gate-bash-matcher.ts
(staleGateBashMatchersFor: project and user settings). The command
refresh takes an optional widen step instead of a new helper.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Docker image built, scanned, and smoke-tested in CI. The PR image is local to this run and is not published.

@sandstream-kit-reviewer sandstream-kit-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kit review gate at 059ea7ef5662: not approved.

  • touches protected paths (permissions), which the owner approves: src/agent-config.ts
  • changes modules many others import, which the owner approves: src/check-security.ts (97 importers)

@sandstream
sandstream merged commit ce9c953 into main Nov 27, 2026
34 checks passed
@sandstream
sandstream deleted the claude/web-kit-status-sync-p6fg9a-protected-pwsh-matcher branch November 27, 2026 11:27
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.

2 participants