A Neovim plugin that integrates the opencode AI coding assistant with git-worktree.nvim. It automatically manages a dedicated opencode terminal per git worktree, including session persistence and a prompt buffer.
- Per-worktree terminals — Each git worktree gets its own opencode terminal; switching worktrees automatically closes the old terminal and opens the new one.
- Session persistence — opencode session IDs are saved per worktree and validated on terminal open, so you resume where you left off.
- Prompt buffer — A small scratch buffer attached to the terminal for sending prompts, with keymaps for submit, insert newline, send line, and send visual selection - makes editing prompts a breeze.
- Toggle commands — Open/close the terminal and prompt buffer with a single keymap or command.
- opencode CLI installed and on
$PATH
With lazy.nvim:
{
"13janderson/opencode-wt.nvim",
dependencies = {
"13janderson/git-worktree.nvim"
},
opts = {},
}Default options:
require("opencode-wt").setup({
size = 70, -- terminal width (vertical) or height (horizontal)
prompt_size = 8, -- prompt buffer height
direction = "vertical", -- "vertical" or "horizontal"
opencode_cmd = "opencode", -- path to the opencode binary
keymaps = {
toggle = "<leader>ot", -- toggle terminal
prompt = "<leader>O", -- toggle prompt buffer
},
})| Command | Description |
|---|---|
:OpencodeWTToggle |
Toggle opencode terminal for current worktree |
:OpencodeWTPrompt |
Toggle prompt buffer |
:OpencodeWTSend <text> |
Send text to the opencode terminal |
:OpencodeWTSessionInfo |
Show session info for current worktree |
:OpencodeWTSessionRefresh |
Refresh session ID for current worktree |
| Key | Mode | Action |
|---|---|---|
<CR> |
Normal / Insert | Send prompt and clear |
<C-j> |
Insert | Insert newline |
<CR> |
Visual | Send visual selection |
<C-l> |
Normal | Send current line |
q |
Normal | Close prompt buffer |
- When you toggle the terminal, the plugin resolves the current git worktree path and opens an opencode terminal in a split.
- A prompt buffer is attached below (or beside) the terminal for quick prompting.
- When you switch worktrees (via git-worktree.nvim's hooks or Neovim's
DirChangedevent), the plugin closes the old terminal and opens a new one for the active worktree. - Session IDs are persisted to
stdpath("data")/opencode-wt/sessions.jsonand validated on each terminal open to ensure stale sessions are not reused.