Skip to content

Commit 1410af5

Browse files
committed
fix: remove automatic terminal opening from ClaudeCodeSend
Foundation fix for #42 - removes automatic terminal opening behavior from ClaudeCodeSend command to prevent focus_terminal errors when terminal buffer is hidden. - Remove terminal.open() calls after successful ClaudeCodeSend operations - Update snacks terminal to check window validity before focus - Update tests to reflect new behavior - Update dev-config and documentation This establishes the foundation for the complete fix which will address the core focus_terminal issue in native terminal implementation. Change-Id: Ide3692617e5c6ce721782eab9cf8f2eeeeef3df5 Signed-off-by: Thomas Kosiewski <tk@coder.com>
1 parent 55aba11 commit 1410af5

File tree

5 files changed

+14
-26
lines changed

5 files changed

+14
-26
lines changed

STORY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
While browsing Reddit at DevOpsCon in London, I stumbled upon a post that caught my eye: someone mentioned finding .vsix files in Anthropic's npm package for their Claude Code VS Code extension.
66

7-
Link to the Reddit post: https://www.reddit.com/r/ClaudeAI/comments/1klpzvl/hidden_jetbrains_vs_code_plugin_in_todays_release/
7+
Link to the Reddit post: <https://www.reddit.com/r/ClaudeAI/comments/1klpzvl/hidden_jetbrains_vs_code_plugin_in_todays_release/>
88

99
My first thought? "No way, they wouldn't ship the source like that."
1010

@@ -45,7 +45,7 @@ What I discovered was fascinating:
4545

4646
Armed with this knowledge, I faced a new challenge: I wanted this in Neovim, but I didn't know Lua.
4747

48-
So I did what any reasonable person would do in 2024 — I used AI to help me build it. Using Roo Code with Gemini 2.5 Pro, I scaffolded a Neovim plugin that implements the same protocol.
48+
So I did what any reasonable person would do in 2025 — I used AI to help me build it. Using Roo Code with Gemini 2.5 Pro, I scaffolded a Neovim plugin that implements the same protocol. (Note: Claude 4 models were not publicly available at the time of writing the extension.)
4949

5050
The irony isn't lost on me: I used AI to reverse-engineer an AI tool, then used AI to build a plugin for AI.
5151

dev-config.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
-- Development configuration for claudecode.nvim
22
-- This is Thomas's personal config for developing claudecode.nvim
33
-- Symlink this to your personal Neovim config:
4-
-- ln -s ~/GitHub/claudecode.nvim/dev-config.lua ~/.config/nvim/lua/plugins/dev-claudecode.lua
4+
-- ln -s ~/projects/claudecode.nvim/dev-config.lua ~/.config/nvim/lua/plugins/dev-claudecode.lua
55

66
return {
77
"coder/claudecode.nvim",
88
dev = true, -- Use local development version
9-
dir = "~/GitHub/claudecode.nvim", -- Adjust path as needed
109
keys = {
1110
-- AI/Claude Code prefix
1211
{ "<leader>a", nil, desc = "AI/Claude Code" },

lua/claudecode/init.lua

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -443,17 +443,13 @@ function M._create_commands()
443443
end
444444
local sent_successfully = selection_module.send_at_mention_for_visual_selection(line1, line2)
445445
if sent_successfully then
446-
-- Exit any potential visual mode (for consistency) and focus Claude terminal
446+
-- Exit any potential visual mode (for consistency)
447447
pcall(function()
448448
if vim.api and vim.api.nvim_feedkeys then
449449
local esc = vim.api.nvim_replace_termcodes("<Esc>", true, false, true)
450450
vim.api.nvim_feedkeys(esc, "i", true)
451451
end
452452
end)
453-
local terminal_ok, terminal = pcall(require, "claudecode.terminal")
454-
if terminal_ok then
455-
terminal.open({})
456-
end
457453
end
458454
else
459455
logger.error("command", "ClaudeCodeSend: Failed to load selection module.")
@@ -481,24 +477,13 @@ function M._create_commands()
481477
local message = success_count == 1 and "Added 1 file to Claude context from visual selection"
482478
or string.format("Added %d files to Claude context from visual selection", success_count)
483479
logger.debug("command", message)
484-
485-
local terminal_ok, terminal = pcall(require, "claudecode.terminal")
486-
if terminal_ok then
487-
terminal.open({})
488-
end
489480
end
490481
return
491482
end
492483
end
493484
local selection_module_ok, selection_module = pcall(require, "claudecode.selection")
494485
if selection_module_ok then
495-
local sent_successfully = selection_module.send_at_mention_for_visual_selection()
496-
if sent_successfully then
497-
local terminal_ok, terminal = pcall(require, "claudecode.terminal")
498-
if terminal_ok then
499-
terminal.open({})
500-
end
501-
end
486+
selection_module.send_at_mention_for_visual_selection()
502487
end
503488
end
504489

lua/claudecode/terminal/snacks.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ function M.open(cmd_string, env_table, config)
7676
terminal:focus()
7777
local term_buf_id = terminal.buf
7878
if term_buf_id and vim.api.nvim_buf_get_option(term_buf_id, "buftype") == "terminal" then
79-
vim.api.nvim_win_call(terminal.win, function()
80-
vim.cmd("startinsert")
81-
end)
79+
-- Check if window is valid before calling nvim_win_call
80+
if terminal.win and vim.api.nvim_win_is_valid(terminal.win) then
81+
vim.api.nvim_win_call(terminal.win, function()
82+
vim.cmd("startinsert")
83+
end)
84+
end
8285
end
8386
return
8487
end

tests/unit/claudecode_send_command_spec.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ describe("ClaudeCodeSend Command Range Functionality", function()
216216
assert(mock_selection_module.last_call.line2 == nil)
217217
end)
218218

219-
it("should exit visual mode and focus terminal on successful send", function()
219+
it("should exit visual mode on successful send", function()
220220
assert(command_callback ~= nil, "Command callback should be set")
221221

222222
local opts = {
@@ -228,7 +228,8 @@ describe("ClaudeCodeSend Command Range Functionality", function()
228228
command_callback(opts)
229229

230230
assert.spy(_G.vim.api.nvim_feedkeys).was_called()
231-
assert.spy(mock_terminal.open).was_called()
231+
-- Terminal should not be automatically opened
232+
assert.spy(mock_terminal.open).was_not_called()
232233
end)
233234

234235
it("should handle server not running", function()

0 commit comments

Comments
 (0)