Repository navigation
fix(hooks): give each OpenCode 2.x hooks plugin file its own id - #3853
Merged
dyoshikawa merged 2 commits intoNov 17, 2026
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
🟢 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
Closed
2 tasks
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.opencodedirectories, 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.urlas 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
mainonly the global plugin runs; with this change all three run.pnpm cicheckpasses on Linux.