Skip to content

Commit 397e144

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

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

lua/claudecode/init.lua

Lines changed: 29 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",
@@ -325,6 +325,34 @@ function M._create_commands()
325325
end
326326
end
327327

328+
M.open_with_model = function()
329+
local models = {
330+
{ name = "Claude Opus 4 (Latest)", value = "claude-opus-4-20250514" },
331+
{ name = "Claude Sonnet 4 (Latest)", value = "claude-sonnet-4-20250514" },
332+
{ name = "Claude 3.7 Sonnet (Latest)", value = "claude-3-7-sonnet-latest" },
333+
{ name = "Claude 3.5 Haiku (Latest)", value = "claude-3-5-haiku-latest" },
334+
}
335+
336+
vim.ui.select(models, {
337+
prompt = "Select Claude model:",
338+
format_item = function(item)
339+
return item.name
340+
end,
341+
}, function(choice)
342+
if not choice then
343+
return -- User cancelled
344+
end
345+
346+
local terminal_ok, terminal = pcall(require, "claudecode.terminal")
347+
if not terminal_ok then
348+
vim.notify("Terminal module not available", vim.log.levels.ERROR)
349+
return
350+
end
351+
352+
terminal.open({}, "--model " .. choice.value)
353+
end)
354+
end
355+
328356
--- Get version information
329357
---@return table Version information
330358
function M.get_version()

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)