Skip to content
Open
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
25 changes: 20 additions & 5 deletions lua/claude-code/file_refresh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,32 @@ function M.setup(claude_code, config)
desc = 'Set shorter updatetime when Claude Code is open',
})

-- When Claude Code closes, restore normal updatetime
-- When Claude Code closes, restore normal updatetime and clean up
vim.api.nvim_create_autocmd('TermClose', {
group = augroup,
pattern = '*',
callback = function()
local buf_name = vim.api.nvim_buf_get_name(0)
if buf_name:match('claude%-code$') then
callback = function(args)
local buf_name = vim.api.nvim_buf_get_name(args.buf)
if buf_name:match('claude%-code') then
vim.o.updatetime = claude_code.claude_code.saved_updatetime
-- Clean up instance tracking and close window
for instance_id, bufnr in pairs(claude_code.claude_code.instances) do
if bufnr == args.buf then
claude_code.claude_code.instances[instance_id] = nil
break
end
end
-- Close windows and delete buffer after a short delay to allow TermClose to complete
vim.schedule(function()
local win_ids = vim.fn.win_findbuf(args.buf)
for _, win_id in ipairs(win_ids) do
pcall(vim.api.nvim_win_close, win_id, true)
end
pcall(vim.api.nvim_buf_delete, args.buf, { force = true })
end)
end
end,
desc = 'Restore normal updatetime when Claude Code is closed',
desc = 'Restore normal updatetime and clean up when Claude Code is closed',
})
end

Expand Down
9 changes: 8 additions & 1 deletion lua/claude-code/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,14 @@ function M.toggle(claude_code, config, git)

-- Validate existing buffer
if bufnr and not is_valid_terminal_buffer(bufnr) then
-- Buffer is no longer a valid terminal, reset
-- Buffer is no longer a valid terminal, clean up and reset
-- Close any windows showing this buffer
local win_ids = vim.fn.win_findbuf(bufnr)
for _, win_id in ipairs(win_ids) do
pcall(vim.api.nvim_win_close, win_id, true)
end
-- Delete the old buffer to free up the name
pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
claude_code.claude_code.instances[instance_id] = nil
bufnr = nil
end
Expand Down