opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(plugin commands): allows for code execution on plugin registered slash commands

Open spoons-and-mirrors opened this issue 2 months ago • 9 comments

This PR adds a powerful new plugin hook to opencode making it possible to run plugins through custom /commands registered by the plugin itself allowing for code execution

needs sdk rebuild to test

cd packages/sdk/js
bun run script/build.ts

As a proof of concept, this PR allowed me to create a plugin with a "/prune" command that prunes all tool outputs from the session

This could also allow to turn a plugin on/off, create composable workflows and many more things i'm sure

spoons-and-mirrors avatar Nov 17 '25 13:11 spoons-and-mirrors

YES! I was just about to do this feature request. I reaaaaally hope this get merged!

einarpersson avatar Nov 20 '25 08:11 einarpersson

Added support for command drop-in in command/ folder as suggested by https://github.com/sst/opencode/issues/5305

spoons-and-mirrors avatar Dec 19 '25 00:12 spoons-and-mirrors

Hi @spoons-and-mirrors Thanks for making that happen, seems that a few cleanups still needed to pass tests and solve merge conflicts. While it is really powerful to run commands directly from the TUI (I know that I suggested that myself) but the more I think about it a better approach could be to run these server side. This way these slash commands can be triggered from any client (including the new desktop client) what are you thoughts here? Could need more work to make that happen

malhashemi avatar Dec 20 '25 18:12 malhashemi

hey @malhashemi, this implementation does run server side. The TUI just wraps around it calling sdk.client.session.command().

as for the merge conflicts, they happen quite alot in this repo heh, I will get to it at some point.

spoons-and-mirrors avatar Dec 21 '25 00:12 spoons-and-mirrors

@spoons-and-mirrors a question that just came to mind, would this work with desktop or any custom WebUI like CodeNomad, not that I use any of these, but was just thinking about how would this register. Could be already working there but would be nice to verify if you are doing any manual testing. additionally does it support sending arguments? something like /command "arg1" "arg2" etc. Finally how far away are we from a merge-able state haha

malhashemi avatar Dec 24 '25 01:12 malhashemi

Yes to both. Can work with other clients, passes args

spoons-and-mirrors avatar Dec 24 '25 10:12 spoons-and-mirrors

Yes to both. Can work with other clients, passes args

spoons-and-mirrors avatar Dec 24 '25 10:12 spoons-and-mirrors