Skip to content

Comments

fix: use word-boundary lookaround for trigger phrase regex#961

Open
bledden wants to merge 1 commit intoanthropics:mainfrom
bledden:fix/trigger-phrase-word-boundary
Open

fix: use word-boundary lookaround for trigger phrase regex#961
bledden wants to merge 1 commit intoanthropics:mainfrom
bledden:fix/trigger-phrase-word-boundary

Conversation

@bledden
Copy link

@bledden bledden commented Feb 22, 2026

Summary

  • Replaces the (^|\s)...([\s.,!?;:]|$) trigger phrase regex with (?<!\w)...(?!\w) negative lookaround
  • Patterns like (@claude), "@claude", >@claude, and cc:@claude now correctly trigger instead of being silently rejected
  • Keeps existing protections against false positives inside words (e.g. email@claude.com still rejected)

Problem

The leading boundary (^|\s) only matched start-of-string or whitespace. Common patterns where the trigger phrase follows punctuation like (, ", >, or : were silently rejected — the GitHub workflow ran (because contains() is looser) but the action logged "No trigger was met" and exited with code 0.

The trailing boundary ([\s.,!?;:]|$) had the same issue — (@claude) failed on both sides since neither ( nor ) were in the allowed character sets.

Fix

Replaced both boundary groups with negative lookaround for word characters (\w = [a-zA-Z0-9_]):

// Before:
`(^|\\s)${escapeRegExp(triggerPhrase)}([\\s.,!?;:]|$)`

// After:
`(?<!\\w)${escapeRegExp(triggerPhrase)}(?!\\w)`

This matches the trigger phrase as long as it isn't embedded inside a word. Any non-word character (or start/end of string) is a valid boundary.

Test plan

Fixes #941

Replace the overly restrictive `(^|\s)...([\s.,!?;:]|$)` pattern with
`(?<!\w)...(?!\w)` lookaround so the trigger phrase is recognized after
any non-word character — not just whitespace.

Patterns like `(@claude)`, `"@claude"`, `>@claude`, and `cc:@claude`
were silently rejected because `(` `"` `>` `:` are not `\s`.
The workflow ran (GitHub `contains()` is looser) but the action logged
"No trigger was met" and exited, which was confusing.

The negative lookaround still prevents false positives inside words
(e.g. `email@claude.com` is correctly rejected because `l` is `\w`).

Fixes anthropics#941
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.

trigger_phrase regex rejects valid mentions preceded by non-whitespace chars like ( or "

1 participant