OpenCode plugin that recreates Claude-style generative UI widgets with two custom tools:
visualize_read_meshow_widget
The plugin renders HTML fragments and raw SVG in a native macOS window using Glimpse.
This project is an OpenCode-focused extraction and adaptation of the original Michaelliv/pi-generative-ui work for pi. The original repo did the reverse-engineering work and established the shape of the widget tools and guideline set.
The runtime now uses the same morphdom shell-update approach as the pi implementation: Glimpse loads a stable shell document, widget content is injected via win.send(), and DOM updates are diffed into place instead of replacing the whole page.
When OpenCode decides a response should be visual, the plugin can:
- Load Claude-style widget design guidance with
visualize_read_me - Render the resulting widget with
show_widget - Return any
window.glimpse.send(data)interaction payload back to the model
Typical use cases:
- interactive explainers
- charts and dashboards
- SVG diagrams
- mockups
- calculators
Widget windows include built-in viewport controls:
- pinch or
Cmd/Ctrl + wheelto zoom - middle-mouse drag to pan
Space + dragto pan with a regular mouse or trackpad- keyboard shortcuts:
+,-,0,F, and arrow keys
OpenCode does not auto-discover this repo or install it just because it exists on GitHub.
For npm installation, all of the following must be true:
- This package has been published to npm
- The package name is listed in your OpenCode config
- OpenCode is restarted so it can install the plugin
After publishing, add the package name to your OpenCode config:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-generative-ui"]
}OpenCode installs npm plugins listed in opencode.json automatically with Bun on startup.
You do not need to run npm install or bun install inside the repo where you want to use the plugin. Just add the plugin name to your OpenCode config and restart OpenCode.
You can add it either:
- Globally in
~/.config/opencode/opencode.json - Per project in
opencode.json
Example global config:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-generative-ui"]
}You can verify that OpenCode resolved the plugin with:
opencode debug configIf the package is installed correctly, you should see opencode-generative-ui in the resolved plugin list.
- macOS
- Bun
- OpenCode
- a working Swift/Xcode toolchain for
glimpseui
This plugin opens widget windows through Glimpse, which builds a small native Swift binary during install.
If glimpseui fails to build, update your Xcode Command Line Tools or full Xcode install, then rerun:
bun pm trust glimpseuiDepending on how OpenCode installed the plugin, you may need to run that in the OpenCode cache/config directory rather than inside your app repo.
If you are developing this plugin itself, install dependencies in this plugin repo:
bun installIf Bun blocks the native build:
bun pm trust glimpseuiClone this repo, then copy the plugin entry file into your OpenCode plugin directory if you want to run it before publishing to npm.
For project-local use today:
- Copy
src/index.tsto.opencode/plugins/generative-ui.ts - Copy
src/lib/into.opencode/plugins/lib/ - Copy
glimpseui.d.tsinto.opencode/ - Copy this
package.jsoninto.opencode/package.jsonor merge the dependencies into your existing one - Run
bun install - If Bun blocks lifecycle scripts, run
bun pm trust glimpseui
Install dependencies in this repo:
bun installTypecheck:
bun run typecheckBuild publishable output:
bun run buildThis plugin now uses morphdom for in-window DOM updates, but it still does not reproduce pi's token-by-token widget streaming. OpenCode does not currently expose the same tool-argument delta hooks, so widgets still render when the tool executes rather than progressively during argument streaming.
- Original reverse-engineering and
piimplementation:Michaelliv/pi-generative-ui - Native widget window runtime: Glimpse
MIT