brokencode.nvim #
A Neovim client for the experimental OpenCode v2 HTTP API.
The plugin keeps one OpenCode session per project. It sends requests through
opencode2 api, which uses OpenCode service discovery and authentication.
Requirements #
- Neovim 0.10 or later
- OpenCode v2 with a configured model
Install #
Install this repository with a Neovim package manager. The plugin configures itself with defaults.
require("brokencode").setup({
command = "opencode2",
chat_width = 72,
model = { providerID = "openai", id = "gpt-5.6-sol", variant = "medium" },
})
The explicit setup call is optional. Call it to override defaults.
Without model, new sessions inherit the latest explicit model selection for
the project. Set model when the OpenCode server default is not usable.
Commands #
:Brokencode <message>sends a message.- Select code and run
:'<,'>Brokencode <instruction>to include that code. - Select code and run
:'<,'>Brokencodeto send that code as the prompt. :BrokencodeMessageopens a message dialog. PressCtrl-Sto send.:BrokencodeChatopens the current conversation in a virtual buffer.:BrokencodeClearcreates a new session and clears the conversation.:BrokencodeNewclears the project session selection.:BrokencodeSwitch [provider/model@variant]switches models. Without an argument, it opensfzf-luaor falls back tovim.ui.select.
The session remains on the OpenCode server. The plugin stores its session ID
under stdpath("state") so later Neovim processes continue the conversation.
Neovim Tool #
The optional OpenCode plugin adds the nvim_editor tool. Models can use it to
read loaded files, replace line ranges, open files, move the cursor, and inspect
diagnostics through Neovim RPC.
Install its dependencies:
cd /path/to/brokencode.nvim/opencode-plugin
bun install
Add the plugin to opencode.jsonc:
{
"$schema": "https://opencode.ai/config.json",
"plugins": ["/path/to/brokencode.nvim/opencode-plugin"]
}
Keep Neovim open while the model uses the tool. The plugin publishes its RPC
address under $XDG_RUNTIME_DIR/brokencode-nvim, or /tmp when unavailable.
Status #
This scaffold targets the OpenCode v2 experimental API. It refreshes the chat after prompt admission and after the session returns to idle. Event streaming, permission dialogs, session selection, and model selection remain future work.
API source: https://opencode.ai/v2/docs/api