Skip to content

fix(opencode): translate canonical hook matchers to OpenCode tool names - #3950

Merged
dyoshikawa merged 4 commits into
mainfrom
resolve-issue-3944-opencode-matchers
Nov 24, 2026
Merged

dyoshikawa merged 4 commits into
mainfrom
resolve-issue-3944-opencode-matchers

Conversation

@dyoshikawa

@dyoshikawa dyoshikawa commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Closes #3944

Summary

OpenCode reports lowercase tool ids and the generated plugins test matchers case-sensitively, so canonical matchers such as Read|Edit|Write were copied as-is into rulesync-hooks.js and never fired.

Following the Antigravity / Cortex Code pattern, both plugin generators now rewrite whole canonical names in tool matchers via replaceMatcherNames, through a shared createOpencodeMatcherTranslator in opencode-style-generator.ts:

  • opencode (V2 plugin): Read -> read, Write -> write, Edit -> edit, Bash -> shell (the V2 name; the existing { shell: "bash", subagent: "task" } alias still lets a V1-style bash matcher fire)
  • opencodev1, Kilo and MiMo Code (V1 plugin): the same, with Bash -> bash, the id the V1 shell events already gate on (input.tool === "bash"). Nothing in the code suggests Kilo or MiMo Code use different tool ids, so none of them is excluded.

The plugins test matchers unanchored, so a translated plain-name matcher (only [A-Za-z0-9_] names joined by |) is anchored as ^(?:...)$, keeping Claude Code's exact-name semantics: Write becomes ^(?:write)$ and no longer also matches todowrite (which a blocking file guard would otherwise abort). Regex-style and untranslated matchers are written as-is.

Only matchers tested against the tool id are translated; the userPromptExpansion matcher (tested against the slash command name) is left as written. Each distinct matcher of an event is translated once, and any capitalized name left over (e.g. MultiEdit, Glob) gets one capitalizedMatcherNames warning saying it is not translated by rulesync and will likely never match. Partial names (ReadFile, mcp__srv__Read) and lowercase names are untouched. No other name mappings are added.

docs/reference/file-formats.md documents the translation, the anchoring, and that translated Edit/Write guards do not cover OpenCode's patch/apply_patch tools.

OpenCode hooks have no import path (toRulesyncHooks throws), so there is no reverse mapping to add.

Tests

  • opencode-hooks.test.ts (V2) and opencodev1-hooks.test.ts (V1): the compiled matchers of a generated plugin show Write matches write but not todowrite, Read|Edit|Write matches read/edit/write but not todoread/todowrite/multiedit, and a regex matcher (^Wr) is unchanged.
  • Also covered: ^Bash$ -> ^shell$ / ^bash$, \bRead\b translated but ReadFile / mcp__srv__Read untouched, override (opencode.hooks / opencodev1.hooks) matchers, slash-command matcher untouched, one warning per distinct matcher.
  • kilo-hooks.test.ts and mimocode-hooks.test.ts: the V1 translation path and warning; existing expectations updated to the anchored lowercase output.
  • pnpm cicheck passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

OpenCode 2.x reports lowercase tool names (read, write, edit, shell) and tests hook matchers case-sensitively, so canonical matchers such as Read|Edit|Write never fired. Translate Read, Write, Edit and Bash to their OpenCode names in the generated V2 plugin and warn about capitalized names with no OpenCode equivalent.

Closes #3944

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
… per matcher

Apply the canonical tool name translation to the V1 plugin generator shared by opencodev1, Kilo and MiMo Code (Read/Write/Edit/Bash to read/write/edit/bash), leaving the slash-command matcher of userPromptExpansion as written. Translate and warn once per distinct matcher of an event, and reword the warning to say the name is not translated by rulesync.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
The plugins test matchers unanchored, so a translated Write also matched OpenCode's todowrite and Read matched todoread. Anchor a translated plain-name matcher as ^(?:...)$ to keep Claude Code's exact-name semantics, leaving regex-style and untranslated matchers as written. Quote the event name in the untranslated-name warning, add a MiMo Code test, and document the anchoring and that Edit/Write guards do not cover patch/apply_patch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…encode-matchers

# Conflicts:
#	src/generated/docs-content.ts
@dyoshikawa
dyoshikawa merged commit 1e0f7ac into main Nov 24, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-3944-opencode-matchers branch November 24, 2026 11:08
@dyoshikawa

Copy link
Copy Markdown
Owner Author

@dyoshikawa Thank you!

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.

Hooks: opencode target copies canonical matchers untranslated, so Read|Edit|Write hooks never fire (OpenCode reports read/write/edit/shell)

1 participant