Skip to content

fix(hooks): give each OpenCode 2.x hooks plugin file its own id - #3853

Merged
dyoshikawa merged 2 commits into
dyoshikawa:mainfrom
Lartweib:fix/opencode-hooks-plugin-id
Nov 17, 2026
Merged

dyoshikawa merged 2 commits into
dyoshikawa:mainfrom
Lartweib:fix/opencode-hooks-plugin-id

Conversation

@Lartweib

Copy link
Copy Markdown
Contributor

Problem

OpenCode 2.x loads only one plugin per id. The user-scope and project-scope hooks plugins that rulesync generates both export the fixed id "rulesync-hooks", so OpenCode keeps the first one it loads and silently drops the other. The same happens with plugins in parent .opencode directories, which OpenCode 2.x also loads. In practice, project hooks never run when global hooks are also configured.

Change

The generated OpenCode 2.x plugin now uses "rulesync-hooks:" + import.meta.url as its id, so every plugin file has its own stable id. OpenCode 1.x, Kilo and MiMo Code are unchanged: they already load every plugin regardless of id.

Behavior change

If the same hook is configured in more than one scope (global, parent directory, project), it now runs once per scope. Before this change the project copy was silently dropped. This is noted in docs/reference/file-formats.md.

Testing

  • New runtime test: the generated plugin is loaded from two different files and the two ids differ.
  • Manual check with the real OpenCode 2.0.30 binary, with a global, a parent-directory and a project plugin: on main only the global plugin runs; with this change all three run.
  • pnpm cicheck passes on Linux.

OpenCode 2.x loads one plugin per id, from the global config and from every
`.opencode` directory above the project. Every generated plugin used the
fixed id `rulesync-hooks`, so when a global plugin (or one in a parent
directory) existed, the project's hooks were silently dropped.

The id is now `rulesync-hooks:` plus the plugin module's URL, which is unique
per file and keeps the generated output identical on every machine.
@Lartweib
Lartweib marked this pull request as ready for review November 16, 2026 09:29
Copilot AI balanced review requested due to automatic review settings November 16, 2026 09:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the change to per-file OpenCode 2.x plugin IDs.

No open issues 🎉

What changed in this PR

This PR prevents OpenCode 2.x from silently dropping generated hooks plugins across global, parent-directory, and project scopes by giving each plugin file a unique ID.

Changes:

  • Generate plugin IDs using import.meta.url, leaving OpenCode 1.x, Kilo, and MiMo Code unchanged.
  • Update assertions and add a runtime test verifying that two plugin files receive different IDs.
  • Document that hooks configured in multiple scopes now run once per scope.
File Description
src/​features/​hooks/​opencode-v2-plugin-generator.ts Derives each OpenCode 2.x plugin ID from its module URL.
src/​features/​hooks/​opencode-hooks.test.ts Updates expected IDs and tests uniqueness across files.
docs/​reference/​file-formats.md Explains per-file IDs and multi-scope hook execution.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change assigning file-specific IDs to OpenCode 2.x hook plugins.

No open issues 🎉

Review effort: Balanced

@dyoshikawa
dyoshikawa merged commit 5cff065 into dyoshikawa:main Nov 17, 2026
6 checks passed
@dyoshikawa

Copy link
Copy Markdown
Owner

Thanks @Lartweib! A shared id letting a global plugin silently shadow the project one was a nasty failure mode, and the runtime test with two real files proves the fix nicely. Merged. A small docs follow-up for configs that referred to the old id is tracked in #3863.

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.

3 participants