Claude Code: bare `mcp__` hook matchers match nothing since CC v2.1.195 (exact-match semantics)
Summary
Since v2.1.195, Claude Code compares hook matchers made only of letters, digits and _ as exact strings, not substrings. The bare mcp__ matchers in hooks/hooks.json therefore match no Model Context Protocol (MCP) tool, and the external-MCP routing added for #529 silently does nothing on current Claude Code.
The Claude Code changelog for 2.1.195 says:
Fixed hook matchers with hyphenated identifiers (e.g.
code-reviewer,mcp__brave-search) accidentally substring-matching — they now exact-match. Usemcp__brave-search__.*to match all tools from a hyphenated MCP server.
Claude Code writes this warning to its debug log twice at every session start:
[WARN] Hook matcher `mcp__` matches no tool (it is compared as an exact string). To match all tools from this server, use `mcp____.*`. See CHANGELOG v2.1.195.Affected matchers in v1.0.169
In hooks/hooks.json, the PreToolUse entry on line 100 is "matcher": "mcp__". It matches nothing, so pretooluse.mjs never runs for external MCP tools.
The PostToolUse entry on line 6 is "Bash|Read|...|EnterWorktree|mcp__". The pattern contains only [A-Za-z0-9_|], so Claude Code reads it as a list of exact names. The other names still work; the mcp__ entry matches nothing.
The context-mode ctx_* tools have their own exact matchers and still work.
Why ctx doctor misses it
Doctor checks that the hook scripts exist and that the plugin is registered, and both pass. It never checks whether each matcher can match a real tool, so it reports PASS while the MCP hooks are dead.
Suggested fix
Give both matchers a regex character so Claude Code switches to regex matching:
// PreToolUse
"matcher": "mcp__.*"
// PostToolUse
"matcher": "Bash|Read|Write|Edit|NotebookEdit|Glob|Grep|TodoWrite|TaskCreate|TaskUpdate|EnterPlanMode|ExitPlanMode|Skill|Agent|AskUserQuestion|EnterWorktree|mcp__.*"#529 suggested excluding context-mode's own tools with mcp__(?!plugin_context-mode_).*. #547 found that Codex rejects look-ahead regex, so a guard inside pretooluse.mjs is the more portable way to do that.
The same change applies to EXTERNAL_MCP_MATCHER_PATTERN in src/adapters/claude-code/hooks.ts, and to the tests that assert toBe("mcp__") in tests/adapters/claude-code.test.ts:799 and tests/adapters/codex-external-mcp-routing.test.ts:39. The Codex adapter defines the same constant, but Codex may match differently, so it needs checking on its own.
Related
- #529 introduced the external-MCP matcher, which worked under the old substring matching.
- #960 asks to narrow the
mcp__matcher to cut overhead. On current Claude Code the matcher never fires, so it needs fixing first.
Environment
context-mode 1.0.169, which ctx upgrade reports as the latest release; Claude Code 2.1.272; macOS (Darwin 27.0.0).
Source: mksglu/context-mode