Skip to content

Commit 90346e3

Browse files
author
Dan Rousseau
committed
feat: ability to pick a model when launching claude
1 parent c1cdcd5 commit 90346e3

File tree

2 files changed

+45
-8
lines changed

2 files changed

+45
-8
lines changed

lua/claudecode/init.lua

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ function M._create_commands()
299299
if current_mode == "v" or current_mode == "V" or current_mode == "\22" then -- \22 is CTRL-V (blockwise visual mode)
300300
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, false, true), "n", false)
301301
end
302-
terminal.toggle({}) -- `opts.fargs` can be used for future enhancements.
302+
terminal.toggle({}, nil) -- `opts.fargs` can be used for future enhancements.
303303
end, {
304304
nargs = "?",
305305
desc = "Toggle the Claude Code terminal window",
@@ -323,6 +323,40 @@ function M._create_commands()
323323
"Terminal module not found. Terminal commands (ClaudeCode, ClaudeCodeOpen, ClaudeCodeClose) not registered."
324324
)
325325
end
326+
327+
vim.api.nvim_create_user_command("ClaudeSelectModel", function()
328+
M.open_with_model()
329+
end, {
330+
desc = "Select and open Claude terminal with chosen model",
331+
})
332+
end
333+
334+
M.open_with_model = function()
335+
local models = {
336+
{ name = "Claude Opus 4 (Latest)", value = "claude-opus-4-20250514" },
337+
{ name = "Claude Sonnet 4 (Latest)", value = "claude-sonnet-4-20250514" },
338+
{ name = "Claude 3.7 Sonnet (Latest)", value = "claude-3-7-sonnet-latest" },
339+
{ name = "Claude 3.5 Haiku (Latest)", value = "claude-3-5-haiku-latest" },
340+
}
341+
342+
vim.ui.select(models, {
343+
prompt = "Select Claude model:",
344+
format_item = function(item)
345+
return item.name
346+
end,
347+
}, function(choice)
348+
if not choice then
349+
return -- User cancelled
350+
end
351+
352+
local terminal_ok, terminal = pcall(require, "claudecode.terminal")
353+
if not terminal_ok then
354+
vim.notify("Terminal module not available", vim.log.levels.ERROR)
355+
return
356+
end
357+
358+
terminal.toggle({}, "--model " .. choice.value)
359+
end)
326360
end
327361

328362
--- Get version information

lua/claudecode/terminal.lua

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ local native_term_tip_shown = false
3737
-- Uses the `terminal_cmd` from the module's configuration, or defaults to "claude".
3838
-- @local
3939
-- @return string The command to execute.
40-
local function get_claude_command()
40+
local function get_claude_command(model)
4141
local cmd_from_config = term_module_config.terminal_cmd
4242
if not cmd_from_config or cmd_from_config == "" then
43+
if model ~= nil then
44+
return "claude " .. model -- Default if not configured
45+
end
4346
return "claude" -- Default if not configured
4447
end
4548
return cmd_from_config
@@ -332,8 +335,8 @@ end
332335
-- @local
333336
-- @return string|nil cmd_string The command string, or nil on failure.
334337
-- @return table|nil env_table The environment variables table, or nil on failure.
335-
local function get_claude_command_and_env()
336-
local cmd_string = get_claude_command()
338+
local function get_claude_command_and_env(model)
339+
local cmd_string = get_claude_command(model)
337340
if not cmd_string or cmd_string == "" then
338341
vim.notify("Claude terminal base command cannot be determined.", vim.log.levels.ERROR)
339342
return nil, nil
@@ -387,10 +390,10 @@ end
387390

388391
--- Opens or focuses the Claude terminal.
389392
-- @param opts_override table (optional) Overrides for terminal appearance (split_side, split_width_percentage).
390-
function M.open(opts_override)
393+
function M.open(opts_override, model)
391394
local provider = get_effective_terminal_provider()
392395
local effective_config = build_effective_term_config(opts_override)
393-
local cmd_string, claude_env_table = get_claude_command_and_env()
396+
local cmd_string, claude_env_table = get_claude_command_and_env(model)
394397

395398
if not cmd_string then
396399
-- Error already notified by the helper function
@@ -460,10 +463,10 @@ end
460463

461464
--- Toggles the Claude terminal open or closed.
462465
-- @param opts_override table (optional) Overrides for terminal appearance (split_side, split_width_percentage).
463-
function M.toggle(opts_override)
466+
function M.toggle(opts_override, model)
464467
local provider = get_effective_terminal_provider()
465468
local effective_config = build_effective_term_config(opts_override)
466-
local cmd_string, claude_env_table = get_claude_command_and_env()
469+
local cmd_string, claude_env_table = get_claude_command_and_env(model)
467470

468471
if not cmd_string then
469472
return -- Error already notified

0 commit comments

Comments
 (0)