sudo-tee/opencode.nvim

neovim frontend for opencode - a terminal-based AI coding agent

🤖 opencode.nvim – Neovim front‑end for the Opencode AI coding agent

What it is

  • A Neovim plugin that talks to the opencode CLI (a terminal‑based AI coding assistant). It opens a chat‑style UI inside the editor, automatically feeding the AI the current file, selection, diagnostics, etc., so you can ask for code suggestions, edits, or whole‑file generation without leaving Neovim.

Key capabilities

Feature What you get
Chat panel Persistent conversation window that shows the dialogue history and lets you submit prompts while keeping the editor focused on your code.
Quick buffer chat (<leader>o/) In visual mode the selected text becomes context; in normal mode the current line is used. The AI replies with edits that are applied directly to the buffer.
Session management Sessions are tied to a workspace and stored on disk ($XDG_DATA_HOME/opencode/snapshot/...). You can switch, rename, fork, or undo sessions via keymaps.
Context capture Optional automatic inclusion of current file, selected text, diagnostics, cursor neighbourhood, and even git diffs.
Model / provider switching One‑click commands to change the underlying LLM model or provider (e.g., OpenAI, Anthropic) and to pick a model variant.
Diff & restore tools View a diff of changes made since the last prompt, revert individual files or the whole session, and restore snapshots.
Rich UI Configurable split position (right/left/current), markdown rendering (via Treesitter), cost & token counters, and optional icons (nerdfonts or plain text).
Extensible hooks Callbacks (on_file_edited, on_session_loaded, etc.) let you run custom Lua code at key moments.
External server support Can point to a remote Opencode server, with optional spawning, auth, and path‑mapping logic.

Installation (example with lazy.nvim)

{ "sudo-tee/opencode.nvim",
  config = function()
    require("opencode").setup({})
  end,
  dependencies = {
    { "MeanderingProgrammer/render-markdown.nvim", opts = { anti_conceal = {enabled = false}, file_types = {'markdown','opencode_output'} }, ft = {'markdown','Avante','copilot-chat','opencode_output'} },
    "saghen/blink.cmp",          -- optional completion source
    "folke/snacks.nvim",        -- optional picker UI
  },
}

You must also have the Opencode CLI (opencode ≥ v0.6.3) installed and on your $PATH.

Typical workflow

  1. Open Neovim in a project directory.
  2. Press <leader>og (or the key you configure) to open the Opencode UI.
  3. Type a prompt in the input pane – the plugin automatically adds the current file, selection, and diagnostics as context.
  4. The AI replies in the output pane; you can click file links (gf) to jump to the referenced code.
  5. Use the diff shortcuts (<leader>od, <leader>orA, etc.) to review or revert changes.
  6. Switch sessions (<leader>os), rename them (<leader>oR), or fork a new branch from a historic message (<leader>oT).

Configuration highlights

  • preferred_picker / preferred_completion let you pick the best UI for file‑mentions and completions.
  • ui.position (right/left/current) and ui.input_position (bottom/top) control where the panels appear.
  • context.enabled toggles automatic context capture; fine‑tune sub‑options like diagnostics.warning or selection.enabled.
  • server table lets you run a remote Opencode server (custom URL, auth, auto‑kill, path mapping).
  • prompt_guard can be a Lua function that blocks prompts that don’t meet your criteria.

Who it’s for

  • Neovim power users who want an AI‑assisted coding loop without leaving the editor.
  • Teams using the Opencode CLI (or a compatible self‑hosted server) and looking for a tighter IDE‑like experience.
  • Anyone comfortable configuring Lua plugins and who wants fine‑grained control over context, model selection, and session history.

Caveats

  • The plugin is early‑stage; the README warns of possible bugs and breaking changes.
  • It depends on the external opencode binary, which itself is still under active development.
  • Some features (e.g., quick buffer chat) are marked experimental.

All details above are taken directly from the repository’s README; no additional features have been inferred.

Related

  • Project
  • Project
  • Project
  • Project
  • Project