Skip to content

Commit b822036

Browse files
authored
Merge pull request #31 from coder/thomask33/claudecode-command-args
feat: configurable auto-close and enhanced terminal architecture
1 parent 6f6b8d1 commit b822036

File tree

15 files changed

+1649
-601
lines changed

15 files changed

+1649
-601
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@ jobs:
159159
ln -s "$(pwd)" ~/.local/share/nvim/site/pack/vendor/start/claudecode.nvim
160160
161161
- name: Run integration tests
162-
run: nix develop .#ci -c nvim --headless -u tests/minimal_init.lua -c "lua require('plenary.test_harness').test_directory('tests/integration', {minimal_init = 'tests/minimal_init.lua'})"
162+
run: nix develop .#ci -c ./scripts/run_integration_tests_individually.sh

README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim):
5151
keys = {
5252
{ "<leader>a", nil, desc = "AI/Claude Code" },
5353
{ "<leader>ac", "<cmd>ClaudeCode<cr>", desc = "Toggle Claude" },
54+
{ "<leader>ar", "<cmd>ClaudeCode --resume<cr>", desc = "Resume Claude" },
55+
{ "<leader>aC", "<cmd>ClaudeCode --continue<cr>", desc = "Continue Claude" },
5456
{ "<leader>as", "<cmd>ClaudeCodeSend<cr>", mode = "v", desc = "Send to Claude" },
5557
{
5658
"<leader>as",
@@ -78,7 +80,9 @@ That's it! For more configuration options, see [Advanced Setup](#advanced-setup)
7880

7981
## Commands
8082

81-
- `:ClaudeCode` - Toggle the Claude Code terminal window
83+
- `:ClaudeCode [arguments]` - Toggle the Claude Code terminal window (arguments are passed to claude command)
84+
- `:ClaudeCode --resume` - Resume a previous Claude conversation
85+
- `:ClaudeCode --continue` - Continue Claude conversation
8286
- `:ClaudeCodeSend` - Send current visual selection to Claude, or add files from tree explorer
8387
- `:ClaudeCodeTreeAdd` - Add selected file(s) from tree explorer to Claude context (also available via ClaudeCodeSend)
8488
- `:ClaudeCodeAdd <file-path> [start-line] [end-line]` - Add a specific file or directory to Claude context by path with optional line range
@@ -108,7 +112,7 @@ The `:ClaudeCodeAdd` command allows you to add files or directories directly by
108112
:ClaudeCodeAdd ~/projects/myproject/
109113
:ClaudeCodeAdd ./README.md
110114
:ClaudeCodeAdd src/main.lua 50 100 " Lines 50-100 only
111-
:ClaudeCodeAdd config.lua 25 " From line 25 to end of file
115+
:ClaudeCodeAdd config.lua 25 " Only line 25
112116
```
113117

114118
#### Features
@@ -132,7 +136,7 @@ The `:ClaudeCodeAdd` command allows you to add files or directories directly by
132136
133137
" Add specific line ranges
134138
:ClaudeCodeAdd src/main.lua 50 100 " Lines 50 through 100
135-
:ClaudeCodeAdd config.lua 25 " From line 25 to end of file
139+
:ClaudeCodeAdd config.lua 25 " Only line 25
136140
:ClaudeCodeAdd utils.py 1 50 " First 50 lines
137141
:ClaudeCodeAdd README.md 10 20 " Just lines 10-20
138142
@@ -196,6 +200,7 @@ See [DEVELOPMENT.md](./DEVELOPMENT.md) for build instructions and development gu
196200
split_side = "right",
197201
split_width_percentage = 0.3,
198202
provider = "snacks", -- or "native"
203+
auto_close = true, -- Auto-close terminal after command completion
199204
},
200205

201206
-- Diff options
@@ -223,6 +228,29 @@ See [DEVELOPMENT.md](./DEVELOPMENT.md) for build instructions and development gu
223228

224229
</details>
225230

231+
### Terminal Auto-Close Behavior
232+
233+
The `auto_close` option controls what happens when Claude commands finish:
234+
235+
**When `auto_close = true` (default):**
236+
237+
- Terminal automatically closes after command completion
238+
- Error notifications shown for failed commands (non-zero exit codes)
239+
- Clean workflow for quick command execution
240+
241+
**When `auto_close = false`:**
242+
243+
- Terminal stays open after command completion
244+
- Allows reviewing command output and any error messages
245+
- Useful for debugging or when you want to see detailed output
246+
247+
```lua
248+
terminal = {
249+
provider = "snacks",
250+
auto_close = false, -- Keep terminal open to review output
251+
}
252+
```
253+
226254
## Troubleshooting
227255

228256
- **Claude not connecting?** Check `:ClaudeCodeStatus` and verify lock file exists in `~/.claude/ide/`

dev-config.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
-- Development configuration for claudecode.nvim
2+
-- This is Thomas's personal config for developing claudecode.nvim
3+
-- Symlink this to your personal Neovim config:
4+
-- ln -s ~/GitHub/claudecode.nvim/dev-config.lua ~/.config/nvim/lua/plugins/dev-claudecode.lua
5+
6+
return {
7+
"coder/claudecode.nvim",
8+
dev = true, -- Use local development version
9+
dir = "~/GitHub/claudecode.nvim", -- Adjust path as needed
10+
keys = {
11+
-- AI/Claude Code prefix
12+
{ "<leader>a", nil, desc = "AI/Claude Code" },
13+
14+
-- Core Claude commands
15+
{ "<leader>ac", "<cmd>ClaudeCode<cr>", desc = "Toggle Claude" },
16+
{ "<leader>ar", "<cmd>ClaudeCode --resume<cr>", desc = "Resume Claude" },
17+
{ "<leader>aC", "<cmd>ClaudeCode --continue<cr>", desc = "Continue Claude" },
18+
19+
-- Context sending
20+
{ "<leader>as", "<cmd>ClaudeCodeSend<cr>", mode = "v", desc = "Send to Claude" },
21+
{
22+
"<leader>as",
23+
"<cmd>ClaudeCodeTreeAdd<cr>",
24+
desc = "Add file from tree",
25+
ft = { "NvimTree", "neo-tree" },
26+
},
27+
28+
-- Development helpers
29+
{ "<leader>ao", "<cmd>ClaudeCodeOpen<cr>", desc = "Open Claude" },
30+
{ "<leader>aq", "<cmd>ClaudeCodeClose<cr>", desc = "Close Claude" },
31+
{ "<leader>ai", "<cmd>ClaudeCodeStatus<cr>", desc = "Claude Status" },
32+
{ "<leader>aS", "<cmd>ClaudeCodeStart<cr>", desc = "Start Claude Server" },
33+
{ "<leader>aQ", "<cmd>ClaudeCodeStop<cr>", desc = "Stop Claude Server" },
34+
},
35+
36+
-- Development configuration
37+
opts = {
38+
-- auto_start = true,
39+
-- log_level = "debug",
40+
-- terminal_cmd = "claude --debug",
41+
-- terminal = {
42+
-- provider = "native",
43+
-- auto_close = false, -- Keep terminals open to see output
44+
-- },
45+
},
46+
}

lua/claudecode/init.lua

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -648,22 +648,24 @@ function M._create_commands()
648648

649649
local terminal_ok, terminal = pcall(require, "claudecode.terminal")
650650
if terminal_ok then
651-
vim.api.nvim_create_user_command("ClaudeCode", function(_opts)
651+
vim.api.nvim_create_user_command("ClaudeCode", function(opts)
652652
local current_mode = vim.fn.mode()
653653
if current_mode == "v" or current_mode == "V" or current_mode == "\22" then
654654
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", false)
655655
end
656-
terminal.toggle({})
656+
local cmd_args = opts.args and opts.args ~= "" and opts.args or nil
657+
terminal.toggle({}, cmd_args)
657658
end, {
658-
nargs = "?",
659-
desc = "Toggle the Claude Code terminal window",
659+
nargs = "*",
660+
desc = "Toggle the Claude Code terminal window with optional arguments",
660661
})
661662

662-
vim.api.nvim_create_user_command("ClaudeCodeOpen", function(_opts)
663-
terminal.open({})
663+
vim.api.nvim_create_user_command("ClaudeCodeOpen", function(opts)
664+
local cmd_args = opts.args and opts.args ~= "" and opts.args or nil
665+
terminal.open({}, cmd_args)
664666
end, {
665-
nargs = "?",
666-
desc = "Open the Claude Code terminal window",
667+
nargs = "*",
668+
desc = "Open the Claude Code terminal window with optional arguments",
667669
})
668670

669671
vim.api.nvim_create_user_command("ClaudeCodeClose", function()

lua/claudecode/meta/vim.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@
7979
---@field termopen fun(cmd: string|string[], opts?: table):number For vim.fn.termopen()
8080
-- Add other vim.fn functions as needed
8181

82+
---@class vim_v_table
83+
---@field event table Event data containing status and other event information
84+
8285
---@class vim_global_api
8386
---@field notify fun(msg: string | string[], level?: number, opts?: vim_notify_opts):nil
8487
---@field log vim_log
88+
---@field v vim_v_table For vim.v.event access
8589
---@field _last_echo table[]? table of tables, e.g. { {"message", "HighlightGroup"} }
8690
---@field _last_error string?
8791
---@field o vim_options_table For vim.o.option_name

lua/claudecode/server/init.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ function M.stop()
8989

9090
tcp_server.stop_server(M.state.server)
9191

92+
-- CRITICAL: Clear global deferred responses to prevent memory leaks and hanging
93+
if _G.claude_deferred_responses then
94+
_G.claude_deferred_responses = {}
95+
end
96+
9297
M.state.server = nil
9398
M.state.port = nil
9499
M.state.clients = {}

0 commit comments

Comments
 (0)