Skip to content

Commit 1da5f67

Browse files
fix: do not wipe claude buffer on window close (native) (#60)
* fix: do not wipe claude buffer on window close * fix tests changes the expected value of 'wipe' to 'hide'. Remove check for buffer options as they will be undefined, given that `nvim_buf_set_option` will now have been called.
1 parent 340319e commit 1da5f67

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

lua/claudecode/terminal/native.lua

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ local function open_terminal(cmd_string, env_table, effective_config, focus)
130130

131131
winid = new_winid
132132
bufnr = vim.api.nvim_get_current_buf()
133-
vim.bo[bufnr].bufhidden = "wipe" -- Wipe buffer when hidden (e.g., window closed)
133+
vim.bo[bufnr].bufhidden = "hide"
134134
-- buftype=terminal is set by termopen
135135

136136
if focus then
@@ -190,9 +190,6 @@ end
190190
local function hide_terminal()
191191
-- Hide the terminal window but keep the buffer and job alive
192192
if bufnr and vim.api.nvim_buf_is_valid(bufnr) and winid and vim.api.nvim_win_is_valid(winid) then
193-
-- Set buffer to hide instead of being wiped when window closes
194-
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "hide")
195-
196193
-- Close the window - this preserves the buffer and job
197194
vim.api.nvim_win_close(winid, false)
198195
winid = nil -- Clear window reference

tests/unit/native_terminal_toggle_spec.lua

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ describe("claudecode.terminal.native toggle behavior", function()
283283

284284
-- Verify initial state - buffer should exist and have a window
285285
assert.is_not_nil(mock_state.buffers[initial_bufnr])
286-
assert.are.equal("wipe", mock_state.buffers[initial_bufnr].options.bufhidden)
286+
assert.are.equal("hide", mock_state.buffers[initial_bufnr].options.bufhidden)
287287

288288
-- Find the window that contains our terminal buffer
289289
local terminal_winid = nil
@@ -306,10 +306,7 @@ describe("claudecode.terminal.native toggle behavior", function()
306306
assert.are.equal(initial_bufnr, native_provider.get_active_bufnr())
307307
assert.is_not_nil(mock_state.buffers[initial_bufnr])
308308

309-
-- 2. bufhidden should have been set to "hide" (this is the core fix)
310-
assert.are.equal("hide", mock_state.buffer_options[initial_bufnr].bufhidden)
311-
312-
-- 3. Window should be closed/invalid
309+
-- 2. Window should be closed/invalid
313310
assert.is_nil(mock_state.windows[terminal_winid])
314311
end)
315312

@@ -383,7 +380,6 @@ describe("claudecode.terminal.native toggle behavior", function()
383380
-- Toggle should hide but preserve process
384381
native_provider.toggle(cmd_string, env_table, config)
385382
assert.are.equal(initial_bufnr, native_provider.get_active_bufnr())
386-
assert.are.equal("hide", mock_state.buffer_options[initial_bufnr].bufhidden)
387383

388384
-- Close should kill the process (cleanup_state called)
389385
native_provider.close()
@@ -415,8 +411,7 @@ describe("claudecode.terminal.native toggle behavior", function()
415411
mock_state.current_win = 1 -- Different window
416412
native_provider.simple_toggle(cmd_string, env_table, config)
417413

418-
-- Should have hidden the terminal (set bufhidden=hide and closed window)
419-
assert.are.equal("hide", mock_state.buffer_options[initial_bufnr].bufhidden)
414+
-- Should have hidden the terminal (closed window)
420415
assert.is_nil(mock_state.windows[terminal_winid])
421416
end)
422417

@@ -530,7 +525,6 @@ describe("claudecode.terminal.native toggle behavior", function()
530525
native_provider.focus_toggle(cmd_string, env_table, config)
531526

532527
-- Should have hidden the terminal
533-
assert.are.equal("hide", mock_state.buffer_options[initial_bufnr].bufhidden)
534528
assert.is_nil(mock_state.windows[terminal_winid])
535529
end)
536530
end)

0 commit comments

Comments
 (0)