Skip to content

Commit 0e7ecc1

Browse files
Add support for command variants and arguments
This commit adds support for different Claude Code command line arguments: - Configure command-line arguments for modes like --continue and --resume - Generate commands for each variant (e.g. :ClaudeCodeContinue) - Add configurable keymaps for each variant - Add validation for variant keymap correspondence - Update documentation with the new features This allows users to easily access conversation history and other Claude CLI modes directly from Neovim with dedicated commands and keymaps.
1 parent b5c64c4 commit 0e7ecc1

6 files changed

Lines changed: 187 additions & 0 deletions

File tree

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ This plugin was built entirely with Claude Code in a Neovim terminal, and then i
3030
## Features
3131

3232
- 🚀 Toggle Claude Code in a terminal window with a single key press
33+
- 🧠 Support for command-line arguments like `--continue` and custom variants
3334
- 🔄 Automatically detect and reload files modified by Claude Code
3435
- ⚡ Real-time buffer updates when files are changed externally
3536
- 📱 Customizable window position and size
@@ -114,11 +115,24 @@ require("claude-code").setup({
114115
},
115116
-- Command settings
116117
command = "claude", -- Command used to launch Claude Code
118+
-- Command variants
119+
command_variants = {
120+
-- Conversation management
121+
continue = "--continue", -- Resume the most recent conversation
122+
resume = "--resume", -- Display an interactive conversation picker
123+
124+
-- Output options
125+
verbose = "--verbose", -- Enable verbose logging with full turn-by-turn output
126+
},
117127
-- Keymaps
118128
keymaps = {
119129
toggle = {
120130
normal = "<C-,>", -- Normal mode keymap for toggling Claude Code, false to disable
121131
terminal = "<C-,>", -- Terminal mode keymap for toggling Claude Code, false to disable
132+
variants = {
133+
continue = "<leader>cC", -- Normal mode keymap for Claude Code with continue flag
134+
verbose = "<leader>cV", -- Normal mode keymap for Claude Code with verbose flag
135+
},
122136
},
123137
window_navigation = true, -- Enable window navigation keymaps (<C-h/j/k/l>)
124138
scrolling = true, -- Enable scrolling keymaps (<C-f/b>) for page up/down
@@ -145,15 +159,33 @@ vim.keymap.set('n', '<leader>cc', '<cmd>ClaudeCode<CR>', { desc = 'Toggle Claude
145159

146160
### Commands
147161

162+
Basic command:
163+
148164
- `:ClaudeCode` - Toggle the Claude Code terminal window
149165

166+
Conversation management commands:
167+
168+
- `:ClaudeCodeContinue` - Resume the most recent conversation
169+
- `:ClaudeCodeResume` - Display an interactive conversation picker
170+
171+
Output options command:
172+
173+
- `:ClaudeCodeVerbose` - Enable verbose logging with full turn-by-turn output
174+
175+
Note: Commands are automatically generated for each entry in your `command_variants` configuration.
176+
150177
### Key Mappings
151178

152179
Default key mappings:
153180

154181
- `<leader>ac` - Toggle Claude Code terminal window (normal mode)
155182
- `<C-,>` - Toggle Claude Code terminal window (both normal and terminal modes)
156183

184+
Variant mode mappings (if configured):
185+
186+
- `<leader>cC` - Toggle Claude Code with --continue flag
187+
- `<leader>cV` - Toggle Claude Code with --verbose flag
188+
157189
Additionally, when in the Claude Code terminal:
158190

159191
- `<C-h>` - Move to the window on the left

doc/claude-code.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,24 @@ default configuration:
109109
},
110110
-- Command settings
111111
command = "claude", -- Command used to launch Claude Code (do not include --cwd)
112+
-- Command variants
113+
command_variants = {
114+
-- Conversation management
115+
continue = "--continue", -- Resume the most recent conversation
116+
resume = "--resume", -- Display an interactive conversation picker
117+
118+
-- Output options
119+
verbose = "--verbose", -- Enable verbose logging with full turn-by-turn output
120+
},
112121
-- Keymaps
113122
keymaps = {
114123
toggle = {
115124
normal = "<leader>ac", -- Normal mode keymap for toggling Claude Code
116125
terminal = "<C-o>", -- Terminal mode keymap for toggling Claude Code
126+
variants = {
127+
continue = "<leader>cC", -- Normal mode keymap for Claude Code with continue flag
128+
verbose = "<leader>cV", -- Normal mode keymap for Claude Code with verbose flag
129+
},
117130
}
118131
}
119132
})
@@ -125,13 +138,31 @@ default configuration:
125138
:ClaudeCode *:ClaudeCode*
126139
Toggle the Claude Code terminal window.
127140

141+
Conversation Management Commands:
142+
:ClaudeCodeContinue *:ClaudeCodeContinue*
143+
Toggle Claude Code with the --continue flag to resume the most recent conversation.
144+
145+
:ClaudeCodeResume *:ClaudeCodeResume*
146+
Toggle Claude Code with the --resume flag to display an interactive conversation picker.
147+
148+
Output Options Commands:
149+
:ClaudeCodeVerbose *:ClaudeCodeVerbose*
150+
Toggle Claude Code with the --verbose flag for full turn-by-turn output.
151+
152+
Note: Commands are automatically generated for each entry in your command_variants configuration.
153+
128154
==============================================================================
129155
6. MAPPINGS *claude-code-mappings*
130156

131157
Default key mappings:
132158

133159
<leader>ac Toggle Claude Code terminal window (normal mode)
134160
<C-.> Toggle Claude Code terminal window (both normal and terminal modes)
161+
162+
Variant mode mappings (if configured):
163+
164+
<leader>cC Toggle Claude Code with --continue flag
165+
<leader>cV Toggle Claude Code with --verbose flag
135166

136167
Additionally, when in the Claude Code terminal:
137168

lua/claude-code/commands.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ function M.register_commands(claude_code)
1717
claude_code.toggle()
1818
end, { desc = 'Toggle Claude Code terminal' })
1919

20+
-- Create commands for each command variant
21+
for variant_name, variant_args in pairs(claude_code.config.command_variants) do
22+
if variant_args ~= false then
23+
-- Convert variant name to PascalCase for command name (e.g., "continue" -> "Continue")
24+
local capitalized_name = variant_name:gsub('^%l', string.upper)
25+
local cmd_name = 'ClaudeCode' .. capitalized_name
26+
27+
vim.api.nvim_create_user_command(cmd_name, function()
28+
claude_code.toggle_with_variant(variant_name)
29+
end, { desc = 'Toggle Claude Code terminal with ' .. variant_name .. ' option' })
30+
end
31+
end
32+
2033
-- Add version command
2134
vim.api.nvim_create_user_command('ClaudeCodeVersion', function()
2235
vim.notify('Claude Code version: ' .. claude_code.version(), vim.log.levels.INFO)

lua/claude-code/config.lua

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@ local M = {}
3636
-- @field window_navigation boolean Enable window navigation keymaps
3737
-- @field scrolling boolean Enable scrolling keymaps
3838

39+
--- ClaudeCodeCommandVariants class for command variant configuration
40+
-- @table ClaudeCodeCommandVariants
41+
-- Conversation management:
42+
-- @field continue string|boolean Resume the most recent conversation
43+
-- @field resume string|boolean Display an interactive conversation picker
44+
-- Output options:
45+
-- @field verbose string|boolean Enable verbose logging with full turn-by-turn output
46+
-- Additional options can be added as needed
47+
3948
--- ClaudeCodeConfig class for main configuration
4049
-- @table ClaudeCodeConfig
4150
-- @field window ClaudeCodeWindow Terminal window settings
4251
-- @field refresh ClaudeCodeRefresh File refresh settings
4352
-- @field git ClaudeCodeGit Git integration settings
4453
-- @field command string Command used to launch Claude Code
54+
-- @field command_variants ClaudeCodeCommandVariants Command variants configuration
4555
-- @field keymaps ClaudeCodeKeymaps Keymaps configuration
4656

4757
--- Default configuration options
@@ -69,11 +79,24 @@ M.default_config = {
6979
},
7080
-- Command settings
7181
command = 'claude', -- Command used to launch Claude Code
82+
-- Command variants
83+
command_variants = {
84+
-- Conversation management
85+
continue = '--continue', -- Resume the most recent conversation
86+
resume = '--resume', -- Display an interactive conversation picker
87+
88+
-- Output options
89+
verbose = '--verbose', -- Enable verbose logging with full turn-by-turn output
90+
},
7291
-- Keymaps
7392
keymaps = {
7493
toggle = {
7594
normal = '<C-,>', -- Normal mode keymap for toggling Claude Code
7695
terminal = '<C-,>', -- Terminal mode keymap for toggling Claude Code
96+
variants = {
97+
continue = '<leader>cC', -- Normal mode keymap for Claude Code with continue flag
98+
verbose = '<leader>cV', -- Normal mode keymap for Claude Code with verbose flag
99+
},
77100
},
78101
window_navigation = true, -- Enable window navigation keymaps (<C-h/j/k/l>)
79102
scrolling = true, -- Enable scrolling keymaps (<C-f/b>) for page up/down
@@ -149,6 +172,18 @@ local function validate_config(config)
149172
return false, 'command must be a string'
150173
end
151174

175+
-- Validate command variants settings
176+
if type(config.command_variants) ~= 'table' then
177+
return false, 'command_variants config must be a table'
178+
end
179+
180+
-- Check each command variant
181+
for variant_name, variant_args in pairs(config.command_variants) do
182+
if not (variant_args == false or type(variant_args) == 'string') then
183+
return false, 'command_variants.' .. variant_name .. ' must be a string or false'
184+
end
185+
end
186+
152187
-- Validate keymaps settings
153188
if type(config.keymaps) ~= 'table' then
154189
return false, 'keymaps config must be a table'
@@ -172,6 +207,25 @@ local function validate_config(config)
172207
return false, 'keymaps.toggle.terminal must be a string or false'
173208
end
174209

210+
-- Validate variant keymaps if they exist
211+
if config.keymaps.toggle.variants then
212+
if type(config.keymaps.toggle.variants) ~= 'table' then
213+
return false, 'keymaps.toggle.variants must be a table'
214+
end
215+
216+
-- Check each variant keymap
217+
for variant_name, keymap in pairs(config.keymaps.toggle.variants) do
218+
if not (keymap == false or type(keymap) == 'string') then
219+
return false, 'keymaps.toggle.variants.' .. variant_name .. ' must be a string or false'
220+
end
221+
-- Ensure variant exists in command_variants
222+
if keymap ~= false and not config.command_variants[variant_name] then
223+
return false,
224+
'keymaps.toggle.variants.' .. variant_name .. ' has no corresponding command variant'
225+
end
226+
end
227+
end
228+
175229
if type(config.keymaps.window_navigation) ~= 'boolean' then
176230
return false, 'keymaps.window_navigation must be a boolean'
177231
end

lua/claude-code/init.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,32 @@ function M.toggle()
5555
end
5656
end
5757

58+
--- Toggle the Claude Code terminal window with a specific command variant
59+
--- @param variant_name string The name of the command variant to use
60+
function M.toggle_with_variant(variant_name)
61+
if not variant_name or not M.config.command_variants[variant_name] then
62+
-- If variant doesn't exist, fall back to regular toggle
63+
return M.toggle()
64+
end
65+
66+
-- Store the original command
67+
local original_command = M.config.command
68+
69+
-- Set the command with the variant args
70+
M.config.command = original_command .. ' ' .. M.config.command_variants[variant_name]
71+
72+
-- Call the toggle function with the modified command
73+
terminal.toggle(M, M.config, git)
74+
75+
-- Set up terminal navigation keymaps after toggling
76+
if M.claude_code.bufnr and vim.api.nvim_buf_is_valid(M.claude_code.bufnr) then
77+
keymaps.setup_terminal_navigation(M, M.config)
78+
end
79+
80+
-- Restore the original command
81+
M.config.command = original_command
82+
end
83+
5884
--- Get the current version of the plugin
5985
--- @return string version Current version string
6086
function M.get_version()

lua/claude-code/keymaps.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ function M.register_keymaps(claude_code, config)
3434
)
3535
end
3636

37+
-- Register variant keymaps if configured
38+
if config.keymaps.toggle.variants then
39+
for variant_name, keymap in pairs(config.keymaps.toggle.variants) do
40+
if keymap then
41+
-- Convert variant name to PascalCase for command name (e.g., "continue" -> "Continue")
42+
local capitalized_name = variant_name:gsub('^%l', string.upper)
43+
local cmd_name = 'ClaudeCode' .. capitalized_name
44+
45+
vim.api.nvim_set_keymap(
46+
'n',
47+
keymap,
48+
string.format([[<cmd>%s<CR>]], cmd_name),
49+
vim.tbl_extend('force', map_opts, { desc = 'Claude Code: ' .. capitalized_name })
50+
)
51+
end
52+
end
53+
end
54+
3755
-- Register with which-key if it's available
3856
vim.defer_fn(function()
3957
local status_ok, which_key = pcall(require, 'which-key')
@@ -50,6 +68,19 @@ function M.register_keymaps(claude_code, config)
5068
{ config.keymaps.toggle.terminal, desc = 'Claude Code: Toggle', icon = '🤖' },
5169
}
5270
end
71+
72+
-- Register variant keymaps with which-key
73+
if config.keymaps.toggle.variants then
74+
for variant_name, keymap in pairs(config.keymaps.toggle.variants) do
75+
if keymap then
76+
local capitalized_name = variant_name:gsub('^%l', string.upper)
77+
which_key.add {
78+
mode = 'n',
79+
{ keymap, desc = 'Claude Code: ' .. capitalized_name, icon = '🤖' },
80+
}
81+
end
82+
end
83+
end
5384
end
5485
end, 100)
5586
end

0 commit comments

Comments
 (0)