fix: use word-boundary lookbehind/lookahead for trigger phrase matching#991
Open
yoheidemachi wants to merge 4 commits intoanthropics:mainfrom
Open
fix: use word-boundary lookbehind/lookahead for trigger phrase matching#991yoheidemachi wants to merge 4 commits intoanthropics:mainfrom
yoheidemachi wants to merge 4 commits intoanthropics:mainfrom
Conversation
…ed mentions The trigger phrase regex previously required mentions to be preceded by whitespace or start-of-string, causing valid mentions like (@claude), "@claude", and >@claude to silently fail. Expand the leading boundary to include common punctuation chars (parentheses, quotes, angle brackets, slashes) and add the case-insensitive flag so @claude also matches. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The FAQ previously stated @claude! wouldn't trigger, which is incorrect after the regex boundary expansion. Updated to accurately describe supported punctuation patterns and case-insensitive matching. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ry matching Replace the explicit character allowlist with `(?<!\w)` and `(?!\w)` word boundary assertions. This categorically handles any non-word character (colons, backticks, brackets, Markdown formatting, etc.) without needing future allowlist expansions. Also extract the duplicated regex construction into a shared `buildTriggerRegex()` helper and add test cases for `cc:@claude`, backtick-wrapped mentions, Markdown links, bold formatting, and multiline text. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Treat hyphens as word-like characters in the lookbehind/lookahead boundary so that hyphenated usernames like @claude-bot and @claude-mention do not falsely trigger the action. This preserves the existing behavior where only standalone trigger phrases match. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #941
Also addresses #910 (case-insensitive matching)
The previous regex used an explicit character allowlist for boundaries (e.g.
(^|\s)/([\s.,!?;:]|$)), which silently rejected common patterns like(@claude),"@claude",>@claude, andcc:@claude. Each new punctuation character required a manual allowlist update.This PR replaces the allowlist approach with negative lookbehind/lookahead using
(?<![\w-])and(?![\w-]):@claude-botcorrectly do NOT trigger (preserves existing behavior)email@claude.comcorrectly does NOT trigger (word characterlblocks the match)"i"flag (fixes trigger_phrase matching is case-sensitive, should be case-insensitive #910)Additionally:
buildTriggerRegex()helper to eliminate 4× duplicated regex constructiondocs/faq.mdto accurately reflect the expanded matching behaviorBefore
(@claude) can you check?"@claude can you check?">@claude can you check?cc:@claude check this`@claude` can you check?@Claude helpAfter
All of the above now trigger correctly.
Still correctly rejected:
email@claude.com(word character before@)@claude-bot(hyphen continues the token)claudette(word character aftere)Test plan
bun test) — 27 tests, 67 assertionsbun run typecheck)bun run format:check)(,",>,',/,:,`,[,**@Claude,@CLAUDE,@cLaUdE@claude-bot,@claude-mentionemail@claude.comanduser@claude.comdo NOT trigger🤖 Generated with Claude Code