Hook `matcher` regexes never fire — only literal matcher strings work (2.3.2)
Summary
The hooks docs define matcher as "a regular expression to filter event targets". On 2.3.2 a regex matcher such as (?i)(read|write|edit) never fires (zero invocations across a full day of Read/Edit tool calls, both interactive TUI and kimi -p), while a literal matcher ("Bash", "Edit") fires reliably, and hooks without a matcher fire for all targets. Either regex support is broken, or matcher is actually a literal-string match and the docs are wrong.
Environment
- kimi 2.3.2 (
/opt/homebrew/bin/kimi, macOS, Apple Silicon)
Repro
~/.kimi-code/config.toml:
[[hooks]]
event = "PreToolUse"
matcher = "(?i)(read|write|edit)"
command = "python3 /Users/you/hooks/tap.py" # appends the stdin payload to a log
timeout = 5
- In any session, perform
Read/Edittool calls.
Expected (per docs): the hook fires for each Read/Edit call. Actual: the hook never runs (log stays empty).
- Change only the matcher to a literal:
matcher = "Edit"
- Repeat an Edit call → the hook fires and receives the payload.
Verified
- In the same sessions, a literal
matcher = "Bash"hook fired for every Bash call (17 payloads logged in one day). - Hooks without
matcher(UserPromptSubmit) fire for all prompts. - Live enforcement asymmetry caused by this bug: a blocking policy hook guarded canon files from
Edit— with the regex matcher the guard never ran (edits went through silently); after switching tomatcher = "Edit"(and later to no matcher), the same edit is blocked as designed. Probe session:eecdc6ea(blocked), earlier same-day sessions (silent pass). - Config valid per
kimi doctor.
Impact
Any hook using a non-literal matcher is silently dead — including security hooks that follow the documented regex semantics. Because hooks fail open, the failure is invisible.
Workaround
Omit matcher (match all targets) and filter inside the script.
Source: Context OS v6.1/track-U verification, 2026-10-26.
Hi @artemmonakhov ! We investigated this and traced down the root cause: JavaScript V8's
ew RegExp()\ does not natively support PCRE-style inline modifiers like (?i), throwing an unhandled \SyntaxError: Invalid group\ which \matchHooks.ts\ catches silently and defaults to \alse.
A fix has been submitted in #4499 with regex prefix extraction and full test coverage.