Repository navigation
Conversation
Claude Code reads a PostToolUse matcher made of plain characters as a list of exact tool names, so `Bash|mcp__graft__|mcp__trail__|…` never fired for a real `mcp__<server>__trail_find_code` (or graft) call, and graftReads/savedTokens stayed flat after MCP-only sessions. The handler already classifies MCP names across every host prefix, so only the matcher moved: anchored regex — exact for the native tools, MCP matched by tool-name suffix so any server key fires (plugin-scoped included). The upgrade test proves a 0.23-era install re-wires to the new matcher on the next init. Users with a repo-level `mcp__<server>__.*` workaround entry should drop it after upgrading, or each MCP call will count twice. Fixes trailhq#834
🌱 graft blast radius1 area changed → 1 area can be affected. 1 dependent symbol, depth 2. flowchart TB
A0(("Trail Initialization<br/>1 symbol"))
classDef reached fill:#D9EDF3,stroke:#3AA7C9,stroke-width:1.5px,color:#0E313C;
class A0 reached;
Who knows this code — 3 people across 2 areas
Ownership is git history over each area's own files, weighted towards recent work (120-day half-life). Merge commits and bots are dropped, and you are dropped from your own PR. A name with no All 1 dependent symbol, grouped by areaTrail Initialization — 1 symbol in 1 file
Test signal per changed area — 1 ✗Reached = a node under a test path has a resolved edge into the changed symbol. It undercounts anything called indirectly — through a CLI, a spawned process or a dynamic import — so read a low ratio as “look here”, never as a coverage gate.
3 test suites also reference this code3 symbols, kept out of the diagram and the table so they cannot crowd out the areas a reviewer has to look at.
Open the interactive graph → — click an area to see the code that changed, and the line that reaches it. |
|
cc @anirudhkumar-nanonets @shhdwi — no rush on any of these; whenever review slots free up. Thirteen small drafts are up, each tied to its open issue with tests and the full-suite baseline documented in the PR body: #850 (834, this one), #851 (817), #852 (762), #853 (624), #854 (832), #855 (827), #856 (816), #857 (438), #858 (433), #859 (833), #860 (829), #861 (635), #862 (425). Happy to rework anything or fold them together if you would rather review fewer. |
Fixes #834 (part 1).
Problem
Sessions driven through MCP tools never move
graftReads/savedTokens: thetool-savingsPostToolUse matcher written tosettings.jsonis a plain-character value,and Claude Code compares such a matcher as a list of exact tool names (hooks docs, "Match MCP tools").
mcp__trail__can only match a tool literally named that — never a realmcp__<server>__trail_find_code— so the hook never fires for MCP calls under any server key.Fix
The handler side already classifies MCP names across every host prefix (
isGraftMcpToolstripsmcp__<server>__/MCP:and checksGRAFT_MCP_TOOL_NAMES), so only the matcher string moves, insrc/claude/settings-merge.ts:Bashno longer leaks ontoBashOutput)..+matches any server key, including plugin-scoped servers (mcp__plugin_<name>_<server>__…).isGraftEntrymarks by the shim command, not the matcher, so a 0.23-era install is rewritten in place on the next init (covered by the upgrade test).Tests
mcp__trail__trail_find_code,mcp__graft__graft_find_code, a hyphenated server key (mcp__trail-map__…), and a plugin-scoped name, whileBashOutput/ baremcp__trail__/ unrelated MCP tools stay quiet.main(49d36b7) are unchanged and pre-date this branch.Note for the changelog
Once this matcher ships, users who worked around the bug with a repo-level
mcp__<server>__.*PostToolUse entry should drop it, or each MCP call will count twice.Validated against the built dist (tsc clean) and the full
node scripts/run-tests.mjssuite on Node 26; the reproduction follows the report in #834 on a repo registered under a non-trailserver key.