# 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. ```lua 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 ` sends a message. - Select code and run `:'<,'>Brokencode ` to include that code. - Select code and run `:'<,'>Brokencode` to send that code as the prompt. - `:BrokencodeMessage` opens a message dialog. Press `Ctrl-S` to send. - `:BrokencodeChat` opens the current conversation in a virtual buffer. - `:BrokencodeClear` creates a new session and clears the conversation. - `:BrokencodeNew` clears the project session selection. - `:BrokencodeSwitch [provider/model@variant]` switches models. Without an argument, it opens `fzf-lua` or falls back to `vim.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: ```sh cd /path/to/brokencode.nvim/opencode-plugin bun install ``` Add the plugin to `opencode.jsonc`: ```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: