Skip to content

Commit 849a5f6

Browse files
authored
fix(tmux): add config options to prevent OSC response leak into Neovim buffer (#144)
fixes #148
1 parent 0f85a44 commit 849a5f6

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

lua/opencode/config.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ local defaults = {
158158
},
159159
tmux = {
160160
options = "-h", -- Open in a horizontal split
161+
focus = false, -- Keep focus in Neovim
162+
-- Disables allow-passthrough in the tmux split
163+
-- preventing OSC escape sequences from leaking into the nvim buffer
164+
allow_passthrough = false,
161165
},
162166
},
163167
}

lua/opencode/provider/tmux.lua

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ Tmux.name = "tmux"
1313
---
1414
---`tmux` options for creating the pane.
1515
---@field options? string
16+
---
17+
---Focus the opencode pane when created. Default: `false`
18+
---@field focus? boolean
19+
--
20+
---Allow `allow-passthrough` on the opencode pane.
21+
-- When enabled, opencode.nvim will use your configured tmux `allow-passthrough` option on its pane.
22+
-- This allows opencode to use OSC escape sequences, but may leak escape codes to the buffer
23+
-- (e.g., "=31337;OK" appearing in your buffer).
24+
--
25+
-- Limitations of having allow-passthrough disabled in the opencode pane:
26+
-- - can't display images
27+
-- - can't use special (terminal specific; non-system) clipboards
28+
-- - may have issues setting window properties like the title from the pane
29+
--
30+
-- If you enable this, consider also enabling `focus` to auto-focus the pane on creation,
31+
-- which can help avoid OSC code leakage while opencode is sending escape sequences on startup.
32+
--
33+
-- Default: `false` (allow-passthrough is disabled to prevent OSC code leakage)
34+
---@field allow_passthrough? boolean
1635

1736
---@param opts? opencode.provider.tmux.Opts
1837
---@return opencode.provider.Tmux
@@ -74,8 +93,14 @@ function Tmux:start()
7493
local pane_id = self:get_pane_id()
7594
if not pane_id then
7695
-- Create new pane
77-
self.pane_id =
78-
vim.fn.system(string.format("tmux split-window -d -P -F '#{pane_id}' %s '%s'", self.opts.options, self.cmd))
96+
local detach_flag = self.opts.focus and "" or "-d"
97+
self.pane_id = vim.fn.system(
98+
string.format("tmux split-window %s -P -F '#{pane_id}' %s '%s'", detach_flag, self.opts.options or "", self.cmd)
99+
)
100+
local disable_passthrough = self.opts.allow_passthrough ~= true -- default true (disable passthrough)
101+
if disable_passthrough and self.pane_id and self.pane_id ~= "" then
102+
vim.fn.system(string.format("tmux set-option -t %s -p allow-passthrough off", vim.trim(self.pane_id)))
103+
end
79104
end
80105
end
81106

0 commit comments

Comments
 (0)