From f3799ac8e1aa11e119d39e985c9cecf5c5314a67 Mon Sep 17 00:00:00 2001 From: Krishna Balasubramanian Date: Sun, 18 May 2025 16:42:25 -0700 Subject: [PATCH 1/2] feat: make claude-code buffer unlisted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevents claude-code terminal buffer from appearing in buffer lists (`:ls`, `:buffers`) by adding 'setlocal nobuflisted' when creating the terminal window. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- CHANGELOG.md | 1 + lua/claude-code/terminal.lua | 1 + tests/spec/terminal_spec.lua | 23 ++++++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15dedfb..c4b1b5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - New `split_ratio` config option to replace `height_ratio` for better handling of both horizontal and vertical splits +- Buffer is now unlisted by default (doesn't appear in `:ls` output) ### Fixed diff --git a/lua/claude-code/terminal.lua b/lua/claude-code/terminal.lua index 6adaf16..b6c4c91 100644 --- a/lua/claude-code/terminal.lua +++ b/lua/claude-code/terminal.lua @@ -155,6 +155,7 @@ function M.toggle(claude_code, config, git) vim.cmd(cmd) vim.cmd 'setlocal bufhidden=hide' + vim.cmd 'setlocal nobuflisted' -- Create a unique buffer name (or a standard one in single instance mode) local buffer_name diff --git a/tests/spec/terminal_spec.lua b/tests/spec/terminal_spec.lua index d861c4a..c768bf4 100644 --- a/tests/spec/terminal_spec.lua +++ b/tests/spec/terminal_spec.lua @@ -405,4 +405,25 @@ describe('terminal module', function() assert.is_true(success, 'Force insert mode function should run without error') end) end) -end) \ No newline at end of file + + describe('buffer listing', function() + it('should set buffer as nobuflisted when creating terminal', function() + -- Claude Code is not running (bufnr is nil) + claude_code.claude_code.bufnr = nil + + -- Call toggle + terminal.toggle(claude_code, config, git) + + -- Check that nobuflisted command was called + local nobuflisted_found = false + for _, cmd in ipairs(vim_cmd_calls) do + if cmd == 'setlocal nobuflisted' then + nobuflisted_found = true + break + end + end + + assert.is_true(nobuflisted_found, 'setlocal nobuflisted should be called') + end) + end) +end) From 02f17234ac4f4a706a2a71de7bd3cab81d0d4438 Mon Sep 17 00:00:00 2001 From: Krishna Balasubramanian Date: Mon, 2 Jun 2025 18:40:28 -0700 Subject: [PATCH 2/2] style: apply stylua formatting --- lua/claude-code/terminal.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lua/claude-code/terminal.lua b/lua/claude-code/terminal.lua index b6c4c91..3aecd5e 100644 --- a/lua/claude-code/terminal.lua +++ b/lua/claude-code/terminal.lua @@ -69,10 +69,7 @@ function M.force_insert_mode(claude_code, config) -- Check if current buffer is any of our Claude instances local is_claude_instance = false for _, bufnr in pairs(claude_code.claude_code.instances) do - if bufnr - and bufnr == current_bufnr - and vim.api.nvim_buf_is_valid(bufnr) - then + if bufnr and bufnr == current_bufnr and vim.api.nvim_buf_is_valid(bufnr) then is_claude_instance = true break end @@ -110,7 +107,7 @@ function M.toggle(claude_code, config, git) end else -- Use a fixed ID for single instance mode - instance_id = "global" + instance_id = 'global' end claude_code.claude_code.current_instance = instance_id