From 0b4f98a00afae8dc2a3d204548f0648418ed9b64 Mon Sep 17 00:00:00 2001 From: Krishna Balasubramanian Date: Sun, 18 May 2025 16:42:25 -0700 Subject: [PATCH] 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 | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2b82cb..c2ead3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,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 - Fixed vertical split behavior when the window position is set to a vertical split command diff --git a/lua/claude-code/terminal.lua b/lua/claude-code/terminal.lua index e2f1d4f..ae78081 100644 --- a/lua/claude-code/terminal.lua +++ b/lua/claude-code/terminal.lua @@ -108,6 +108,7 @@ function M.toggle(claude_code, config, git) vim.cmd(cmd) vim.cmd 'setlocal bufhidden=hide' + vim.cmd 'setlocal nobuflisted' vim.cmd 'file claude-code' if config.window.hide_numbers then diff --git a/tests/spec/terminal_spec.lua b/tests/spec/terminal_spec.lua index 5909fdd..38d397e 100644 --- a/tests/spec/terminal_spec.lua +++ b/tests/spec/terminal_spec.lua @@ -290,4 +290,25 @@ describe('terminal module', function() assert.is_true(success, 'Force insert mode function should run without error') end) end) + + 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)