diff --git a/lua/claudecode/init.lua b/lua/claudecode/init.lua index 489785c..f8b7289 100644 --- a/lua/claudecode/init.lua +++ b/lua/claudecode/init.lua @@ -299,7 +299,7 @@ function M._create_commands() if current_mode == "v" or current_mode == "V" or current_mode == "\22" then -- \22 is CTRL-V (blockwise visual mode) vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("", true, false, true), "n", false) end - terminal.toggle({}) -- `opts.fargs` can be used for future enhancements. + terminal.toggle({}, nil) -- `opts.fargs` can be used for future enhancements. end, { nargs = "?", desc = "Toggle the Claude Code terminal window", @@ -323,6 +323,40 @@ function M._create_commands() "Terminal module not found. Terminal commands (ClaudeCode, ClaudeCodeOpen, ClaudeCodeClose) not registered." ) end + + vim.api.nvim_create_user_command("ClaudeSelectModel", function() + M.open_with_model() + end, { + desc = "Select and open Claude terminal with chosen model", + }) +end + +M.open_with_model = function() + local models = { + { name = "Claude Opus 4 (Latest)", value = "claude-opus-4-20250514" }, + { name = "Claude Sonnet 4 (Latest)", value = "claude-sonnet-4-20250514" }, + { name = "Claude 3.7 Sonnet (Latest)", value = "claude-3-7-sonnet-latest" }, + { name = "Claude 3.5 Haiku (Latest)", value = "claude-3-5-haiku-latest" }, + } + + vim.ui.select(models, { + prompt = "Select Claude model:", + format_item = function(item) + return item.name + end, + }, function(choice) + if not choice then + return -- User cancelled + end + + local terminal_ok, terminal = pcall(require, "claudecode.terminal") + if not terminal_ok then + vim.notify("Terminal module not available", vim.log.levels.ERROR) + return + end + + terminal.toggle({}, "--model " .. choice.value) + end) end --- Get version information diff --git a/lua/claudecode/terminal.lua b/lua/claudecode/terminal.lua index 4880388..684d7df 100644 --- a/lua/claudecode/terminal.lua +++ b/lua/claudecode/terminal.lua @@ -37,9 +37,12 @@ local native_term_tip_shown = false -- Uses the `terminal_cmd` from the module's configuration, or defaults to "claude". -- @local -- @return string The command to execute. -local function get_claude_command() +local function get_claude_command(model) local cmd_from_config = term_module_config.terminal_cmd if not cmd_from_config or cmd_from_config == "" then + if model ~= nil then + return "claude " .. model -- Default if not configured + end return "claude" -- Default if not configured end return cmd_from_config @@ -332,8 +335,8 @@ end -- @local -- @return string|nil cmd_string The command string, or nil on failure. -- @return table|nil env_table The environment variables table, or nil on failure. -local function get_claude_command_and_env() - local cmd_string = get_claude_command() +local function get_claude_command_and_env(model) + local cmd_string = get_claude_command(model) if not cmd_string or cmd_string == "" then vim.notify("Claude terminal base command cannot be determined.", vim.log.levels.ERROR) return nil, nil @@ -387,10 +390,10 @@ end --- Opens or focuses the Claude terminal. -- @param opts_override table (optional) Overrides for terminal appearance (split_side, split_width_percentage). -function M.open(opts_override) +function M.open(opts_override, model) local provider = get_effective_terminal_provider() local effective_config = build_effective_term_config(opts_override) - local cmd_string, claude_env_table = get_claude_command_and_env() + local cmd_string, claude_env_table = get_claude_command_and_env(model) if not cmd_string then -- Error already notified by the helper function @@ -460,10 +463,10 @@ end --- Toggles the Claude terminal open or closed. -- @param opts_override table (optional) Overrides for terminal appearance (split_side, split_width_percentage). -function M.toggle(opts_override) +function M.toggle(opts_override, model) local provider = get_effective_terminal_provider() local effective_config = build_effective_term_config(opts_override) - local cmd_string, claude_env_table = get_claude_command_and_env() + local cmd_string, claude_env_table = get_claude_command_and_env(model) if not cmd_string then return -- Error already notified