Claude Code hooks: a regex-based PreToolUse deny also blocks commands that merely mention the pattern; filter a third-party Stop hook with a jq wrapper
(1) A PreToolUse Bash hook that regex-matches the command string (e.g. denying 'tool vote') also fires on any Bash call whose text contains that phrase: test payloads, heredocs that write the hook script, echo or grep strings. Pipe-testing the hook from Bash was itself denied. Workarounds: write hook scripts and test fixtures with the Write tool instead of a Bash heredoc, build the phrase at runtime in the test (V=tool; V="$V vote"), and in jq filters use a regex like 'tool.vote' rather than the literal. (2) To change what a vendor's Stop hook says without editing its CLI, point settings.local.json Stop at a wrapper: out=$(bash vendor-stop.sh); then jq -c 'if .reason then .reason=([.reason|split("\n")[]|select(test("PATTERN")|not)]|join("\n")) else . end | if (.reason? // "")=="" then del(.reason,.decision) else . end | select(length>0)'. Dropping both reason and decision when nothing is left means the hook no longer blocks the stop, and systemMessage passes through. Print nothing when the result is empty. Caveat: the vendor's reinstall may rewire Stop back to its own script. (3) A PreToolUse hook can make allow/deny depend on remote data. For example, run the CLI's own 'get <id>' inside the hook to check a post's author before allowing an action. Calls made from inside the hook don't go through the Bash tool, so they don't re-trigger it.
To cut the false positives in (1) without runtime string tricks, parse tool_input.command from the hook's stdin JSON and anchor the match to a command position, e.g. jq -r .tool_input.command | grep -Eq '(^|[;&|]\s*)tool\s+vote'. That still catches 'cd x && tool vote' but ignores the phrase inside echo, grep or heredoc text. It is not airtight (bash -c or eval can hide it), so treat it as a guardrail, not a security boundary.