Skip to content

Commit 55986cb

Browse files
feat: add close_on_exit terminal configuration option
Add configurable close_on_exit option to terminal settings that controls whether the terminal window closes automatically when the Claude process exits. This allows users to see Claude's spend metrics and final output that are displayed on process exit, which would otherwise be lost when the terminal window closes immediately. - Add close_on_exit property to terminal configuration (default: true) - Implement early return logic in both snacks and native terminal providers - Update README documentation with new configuration option - Maintain backward compatibility with existing behavior
1 parent 91357d8 commit 55986cb

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ For deep technical details, see [ARCHITECTURE.md](./ARCHITECTURE.md).
157157
split_width_percentage = 0.30,
158158
provider = "auto", -- "auto", "snacks", or "native"
159159
auto_close = true,
160+
close_on_exit = true, -- Close terminal window when process exits
160161
},
161162

162163
-- Diff Integration

lua/claudecode/terminal.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ local config = {
2424
show_native_term_exit_tip = true,
2525
terminal_cmd = nil,
2626
auto_close = true,
27+
close_on_exit = true, -- When true, closes terminal window when process exits
2728
}
2829

2930
-- Lazy load providers
@@ -102,6 +103,7 @@ local function build_config(opts_override)
102103
split_side = effective_config.split_side,
103104
split_width_percentage = effective_config.split_width_percentage,
104105
auto_close = effective_config.auto_close,
106+
close_on_exit = effective_config.close_on_exit,
105107
}
106108
end
107109

@@ -210,6 +212,8 @@ function M.setup(user_term_config, p_terminal_cmd)
210212
config[k] = v
211213
elseif k == "auto_close" and type(v) == "boolean" then
212214
config[k] = v
215+
elseif k == "close_on_exit" and type(v) == "boolean" then
216+
config[k] = v
213217
else
214218
vim.notify("claudecode.terminal.setup: Invalid value for " .. k .. ": " .. tostring(v), vim.log.levels.WARN)
215219
end

lua/claudecode/terminal/native.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ local function open_terminal(cmd_string, env_table, effective_config, focus)
9898

9999
cleanup_state() -- Clear our managed state first
100100

101+
if not effective_config.close_on_exit then
102+
return
103+
end
104+
101105
if current_winid_for_job and vim.api.nvim_win_is_valid(current_winid_for_job) then
102106
if current_bufnr_for_job and vim.api.nvim_buf_is_valid(current_bufnr_for_job) then
103107
-- Optional: Check if the window still holds the same terminal buffer

lua/claudecode/terminal/snacks.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ local function setup_terminal_events(term_instance, config)
2929
-- Clean up
3030
terminal = nil
3131
vim.schedule(function()
32-
term_instance:close({ buf = true })
32+
if config.close_on_exit then
33+
term_instance:close({ buf = true })
34+
end
3335
vim.cmd.checktime()
3436
end)
3537
end, { buf = true })

0 commit comments

Comments
 (0)