Did you check docs and existing issues?
:checkhealth opencode output
opencode.nvim ~
- OS: Darwin 25.4.0 (x86_64)
- `nvim` version: `0.12.1`.
- `opencode.nvim` git commit hash: `b3cdd746a5ca321b6884badefa0ba22c86c3d45e`.
- `vim.g.opencode_opts`: `nil`
opencode.nvim [binaries] ~
- ✅ OK `opencode` available with version `1.4.0`.
- ✅ OK `curl` available.
- ✅ OK `pgrep` available.
- ✅ OK `lsof` available.
opencode.nvim [snacks] ~
- ⚠️ WARNING `snacks.input` is disabled: `ask()` will not be enhanced.
- ✅ OK `snacks.picker` is enabled: `select()` will be enhanced.
Describe the bug
nvim_set_current_win(winid) at terminal.lua:66 inside the TermRequest autocmd callback errors with Invalid 'window' when winid becomes invalid before the callback fires.
Error in TermRequest Autocommands for "<buffer=5>":
Lua callback: ...te/pack/core/opt/opencode.nvim/lua/opencode/terminal.lua:66: Invalid 'window': Expected Lua number
stack traceback:
[C]: in function 'nvim_set_current_win'
...te/pack/core/opt/opencode.nvim/lua/opencode/terminal.lua:66: in function <...te/pack/core/opt/opencode.nvim/lua/opencode/terminal.lua:63>
The callback at line 63-70 doesn't guard against winid being invalid:
auid = vim.api.nvim_create_autocmd("TermRequest", {
buffer = bufnr,
callback = function(ev)
if ev.data.cursor[1] > 1 then
vim.api.nvim_del_autocmd(auid)
vim.api.nvim_set_current_win(winid) -- winid can be invalid here
vim.cmd([[startinsert | call feedkeys("\<C-\>\<C-n>\<C-w>p", "n")]])
end
end,
})
Adding if vim.api.nvim_win_is_valid(winid) then before line 66 would fix it.
Steps To Reproduce
- Open nvim (0.12.1)
- Toggle opencode terminal via
require("opencode").toggle()
- Error fires on initial terminal render
Expected Behavior
Terminal opens without error. The TermRequest callback should validate winid before calling nvim_set_current_win.
Did you check docs and existing issues?
:checkhealth opencodeoutputDescribe the bug
nvim_set_current_win(winid)atterminal.lua:66inside theTermRequestautocmd callback errors withInvalid 'window'whenwinidbecomes invalid before the callback fires.The callback at line 63-70 doesn't guard against
winidbeing invalid:Adding
if vim.api.nvim_win_is_valid(winid) thenbefore line 66 would fix it.Steps To Reproduce
require("opencode").toggle()Expected Behavior
Terminal opens without error. The
TermRequestcallback should validatewinidbefore callingnvim_set_current_win.