Skip to content

fix: do not wipe claude buffer on window close (native) #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lua/claudecode/terminal/native.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ local function open_terminal(cmd_string, env_table, effective_config, focus)

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

if focus then
Expand Down Expand Up @@ -185,9 +185,6 @@ end
local function hide_terminal()
-- Hide the terminal window but keep the buffer and job alive
if bufnr and vim.api.nvim_buf_is_valid(bufnr) and winid and vim.api.nvim_win_is_valid(winid) then
-- Set buffer to hide instead of being wiped when window closes
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "hide")

-- Close the window - this preserves the buffer and job
vim.api.nvim_win_close(winid, false)
winid = nil -- Clear window reference
Expand Down
12 changes: 3 additions & 9 deletions tests/unit/native_terminal_toggle_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ describe("claudecode.terminal.native toggle behavior", function()

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

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

-- 2. bufhidden should have been set to "hide" (this is the core fix)
assert.are.equal("hide", mock_state.buffer_options[initial_bufnr].bufhidden)

-- 3. Window should be closed/invalid
-- 2. Window should be closed/invalid
assert.is_nil(mock_state.windows[terminal_winid])
end)

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

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

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

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

-- Should have hidden the terminal
assert.are.equal("hide", mock_state.buffer_options[initial_bufnr].bufhidden)
assert.is_nil(mock_state.windows[terminal_winid])
end)
end)
Expand Down