Uh oh!
There was an error while loading. Please reload this page.
feat: allow tool.execute.after hooks to inject AI-visible messages - #19519
feat: allow tool.execute.after hooks to inject AI-visible messages#19519doomsday616 wants to merge 3 commits into
Conversation
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
rekram1-node
commented
May 15, 2026
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes#17412
Type of change
What does this PR do?
Adds an optional
injectfield to thetool.execute.afterhook output. When a plugin setsoutput.inject, the messages are persisted as synthetic user messages that the AI sees on the next loop iteration.Why this matters — and why we wrote it ourselves:
We filed #17412 two weeks ago, tagged @thdxr, @adamdotdevin, @nexxeln, @Hona, @jayair, @fwang, and @kujtimiihoxha. Zero response. The broader #12472 (Claude Code hooks compat) has 10 👍, 11 comments from the community, and also zero team response. So here we are — writing it ourselves.
This isn't a nice-to-have. Without hook message injection, any skill requiring behavioral enforcement is non-viable on OpenCode. The planning-with-files benchmark tells the story:
That's a 15x degradation. It means OpenCode cannot reliably handle complex, multi-step projects that need structured planning — the AI forgets its workflow after ~5 tool calls and completely loses it after compaction. Users in #12472 have explicitly said they recommend Cline over OpenCode for serious work because of this gap.
If this PR also gets ignored, frankly, it's hard to see how OpenCode's skill ecosystem will ever be competitive.
The actual change:
A
flushInjectedMessages()helper creates synthetic user messages using the sameSession.updateMessage()+Session.updatePart()pattern already used by subtask summary messages in prompt.ts. It's called after all threetool.execute.afterhook sites (registry tools, MCP tools, subtask tools). System-role injections get wrapped in<system-reminder>tags.~57 lines across 2 files. Fully backward compatible —
injectis optional.Usage:
How did you verify your code works?
The implementation reuses the exact synthetic user message pattern from prompt.ts (lines 524-542, subtask summary injection) — same
Session.updateMessage()+Session.updatePart()path, samesynthetic: trueflag. TypeCheck passes. Relying on CI for full validation as this was authored remotely via GitHub API.Screenshots / recordings
N/A — no UI changes.
Checklist