Skip to content

feat: add bin_path configuration option for Claude binary location #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lua/claudecode/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local M = {}
M.defaults = {
port_range = { min = 10000, max = 65535 },
auto_start = true,
bin_path = "claude",
terminal_cmd = nil,
log_level = "info",
track_selection = true,
Expand Down Expand Up @@ -39,6 +40,8 @@ function M.validate(config)

assert(config.terminal_cmd == nil or type(config.terminal_cmd) == "string", "terminal_cmd must be nil or a string")

assert(type(config.bin_path) == "string" and config.bin_path ~= "", "bin_path must be a non-empty string")

local valid_log_levels = { "trace", "debug", "info", "warn", "error" }
local is_valid_log_level = false
for _, level in ipairs(valid_log_levels) do
Expand Down
3 changes: 2 additions & 1 deletion lua/claudecode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ M.version = {
local default_config = {
port_range = { min = 10000, max = 65535 },
auto_start = true,
bin_path = "claude",
terminal_cmd = nil,
log_level = "info",
track_selection = true,
Expand Down Expand Up @@ -312,7 +313,7 @@ function M.setup(opts)
-- Guard in case tests or user replace the module with a minimal stub without `setup`.
if type(terminal_module.setup) == "function" then
-- terminal_opts might be nil, which the setup function should handle gracefully.
terminal_module.setup(terminal_opts, M.state.config.terminal_cmd)
terminal_module.setup(terminal_opts, M.state.config.terminal_cmd, M.state.config.bin_path)
end
else
logger.error("init", "Failed to load claudecode.terminal module for setup.")
Expand Down
15 changes: 13 additions & 2 deletions lua/claudecode/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ local config = {
provider = "auto",
show_native_term_exit_tip = true,
terminal_cmd = nil,
bin_path = "claude",
auto_close = true,
}

Expand Down Expand Up @@ -126,7 +127,7 @@ local function get_claude_command_and_env(cmd_args)
local cmd_from_config = config.terminal_cmd
local base_cmd
if not cmd_from_config or cmd_from_config == "" then
base_cmd = "claude" -- Default if not configured
base_cmd = config.bin_path or "claude"
else
base_cmd = cmd_from_config
end
Expand Down Expand Up @@ -180,7 +181,7 @@ end
-- @field user_term_config.provider string 'snacks' or 'native' (default: 'snacks').
-- @field user_term_config.show_native_term_exit_tip boolean Show tip for exiting native terminal (default: true).
-- @param p_terminal_cmd string|nil The command to run in the terminal (from main config).
function M.setup(user_term_config, p_terminal_cmd)
function M.setup(user_term_config, p_terminal_cmd, p_bin_path)
if user_term_config == nil then -- Allow nil, default to empty table silently
user_term_config = {}
elseif type(user_term_config) ~= "table" then -- Warn if it's not nil AND not a table
Expand All @@ -198,6 +199,16 @@ function M.setup(user_term_config, p_terminal_cmd)
config.terminal_cmd = nil -- Fallback to default behavior
end

if p_bin_path == nil or type(p_bin_path) == "string" then
config.bin_path = p_bin_path or "claude"
else
vim.notify(
"claudecode.terminal.setup: Invalid bin_path provided: " .. tostring(p_bin_path) .. ". Using default.",
vim.log.levels.WARN
)
config.bin_path = "claude"
end

for k, v in pairs(user_term_config) do
if config[k] ~= nil and k ~= "terminal_cmd" then -- terminal_cmd is handled above
if k == "split_side" and (v == "left" or v == "right") then
Expand Down