Skip to content
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
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
Comment on lines +103 to +105
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Pattern inconsistency between TermOpen and TermClose.

The TermClose autocmd now uses claude%-code (substring match) at line 105, but the TermOpen autocmd at line 91 still uses claude%-code$ (end anchor). This inconsistency means:

  • For multi-instance buffers named claude-code-<path>, TermClose will match and clean up correctly
  • But TermOpen won't match them, so saved_updatetime won't be set when opening multi-instance terminals

Consider aligning the patterns:

Proposed fix
   vim.api.nvim_create_autocmd('TermOpen', {
     group = augroup,
     pattern = '*',
     callback = function()
       local buf = vim.api.nvim_get_current_buf()
       local buf_name = vim.api.nvim_buf_get_name(buf)
-      if buf_name:match('claude%-code$') then
+      if buf_name:match('claude%-code') then
         claude_code.claude_code.saved_updatetime = vim.o.updatetime
         vim.o.updatetime = config.refresh.updatetime
       end
     end,
🤖 Prompt for AI Agents
In `@lua/claude-code/file_refresh.lua` around lines 103 - 105, The TermOpen
autocmd uses the anchored pattern 'claude%-code$' while TermClose uses the
unanchored 'claude%-code', causing saved_updatetime to not be set for
multi-instance buffers; update the TermOpen autocmd (where saved_updatetime is
set) to use the same unanchored pattern 'claude%-code' (or alternatively make
TermClose use the anchored pattern) so both autocmds consistently match
multi-instance buffers and saved_updatetime is always set/cleaned up.

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