GeezerVison is showing github.com — feat(plugin): add chat.model hook for dynamic model routing for token savings by rjmorales13 · Pull Request #18826 · anomalyco/opencode
Conversation
rjmorales13
commented
Mar 23, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Adds a new 'chat.model' plugin hook that allows plugins to dynamically route messages to different models based on content/complexity. When a plugin sets output.model, the routed model is persisted in session state so future turns and subagents (via Task tool) inherit it.
Changes:
- packages/plugin/src/index.ts: Add chat.model hook type definition
- packages/opencode/src/session/prompt.ts: Fire chat.model hook before model resolution, persist routed model for subagent inheritance
- packages/opencode/src/tool/task.ts: Check for routed model when resolving subagent model (fixes subagent model inheritance)
Related: #18644, #17870, #6928
Issue for this PR
Closes #
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Please provide a description of the issue, the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the PR.
If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!
How did you verify your code works?
I used my fork to conduct testing locally
Screenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
If you do not follow this template your PR will be automatically rejected.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
butaji reacted with thumbs up emoji
… savings
Adds a new 'chat.model' plugin hook that allows plugins to dynamically
route messages to different models based on content/complexity. When a
plugin sets output.model, the routed model is persisted in session state
so future turns and subagents (via Task tool) inherit it.
Changes:
- packages/plugin/src/index.ts: Add chat.model hook type definition
- packages/opencode/src/session/prompt.ts: Fire chat.model hook before
model resolution, persist routed model for subagent inheritance
- packages/opencode/src/tool/task.ts: Check for routed model when
resolving subagent model (fixes subagent model inheritance)
Related: anomalyco#18644, anomalyco#17870, anomalyco#6928
|
This PR doesn't fully meet our contributing guidelines and PR template.
What needs to be fixed:
- Not all checklist items are checked. Please confirm you have tested locally and have not included unrelated changes.
Please edit this PR description to address the above within 2 hours, or it will be automatically closed.
If you believe this was flagged incorrectly, please let a maintainer know.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Convert plain strings from plugin hook to branded types using
ProviderID.make() and ModelID.make(). Cast branded types to plain
strings when sending to the hook interface. Fixes TS2345/TS2322
typecheck errors.
|
Failed check: test / e2e (windows) (pull_request)
test / e2e (windows) (pull_request)
This is NOT caused changes. The failing test is a pre-existing flaky E2E test:
- Error: Timeout 60000ms exceeded while waiting on the predicate — the diff endpoint returned 0 results when expecting 1
- The changes from this PR: plugin/src/index.ts, opencode/src/session/prompt.ts, opencode/src/tool/task.ts; none of these changes touch the review UI, diff system, or the app package
The test also failed on retry feat: compact and other improvements #1 and retry Roadmap & Existing Issues #2 (it's marked as flaky). A second test (session-review.spec.ts:285) also flaked but eventually passed on retry.
From the looks of it, it has falied 3 consecutive times
- It failed 3 consecutive times with the same timeout
- The app package E2E tests don't touch anything your code modifies
- 116 out of 123 tests passed, 5 skipped, 1 failed, 1 flaky
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
rjmorales13
changed the title
feat(plugin): add chat.model hook for dynamic model routing for token…
feat(plugin): add chat.model hook for dynamic model routing for token savings
Mar 23, 2026
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.
Feel free to open a new pull request that follows our guidelines.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|