Skip to content

Commit ff6e531

Browse files
committed
feat: add bin_path configuration option for Claude binary location
Adds a new `bin_path` configuration option to specify the path to the Claude binary, addressing issues where users have Claude installed in non-standard locations or use aliases that aren't recognized when Neovim spawns processes. Changes: - Add `bin_path` to default configuration with "claude" as default - Update terminal module to use `bin_path` when `terminal_cmd` is not set - Add validation for `bin_path` configuration option - Maintain backward compatibility with existing configurations Fixes scenarios where users get exit code 127 errors due to Claude binary not being found in PATH or when using shell aliases that don't work in subprocess environments.
1 parent 91357d8 commit ff6e531

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lua/claudecode/config.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ local M = {}
55
M.defaults = {
66
port_range = { min = 10000, max = 65535 },
77
auto_start = true,
8+
bin_path = "claude",
89
terminal_cmd = nil,
910
log_level = "info",
1011
track_selection = true,
@@ -39,6 +40,8 @@ function M.validate(config)
3940

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

43+
assert(type(config.bin_path) == "string" and config.bin_path ~= "", "bin_path must be a non-empty string")
44+
4245
local valid_log_levels = { "trace", "debug", "info", "warn", "error" }
4346
local is_valid_log_level = false
4447
for _, level in ipairs(valid_log_levels) do

lua/claudecode/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ M.version = {
4848
local default_config = {
4949
port_range = { min = 10000, max = 65535 },
5050
auto_start = true,
51+
bin_path = "claude",
5152
terminal_cmd = nil,
5253
log_level = "info",
5354
track_selection = true,
@@ -312,7 +313,7 @@ function M.setup(opts)
312313
-- Guard in case tests or user replace the module with a minimal stub without `setup`.
313314
if type(terminal_module.setup) == "function" then
314315
-- terminal_opts might be nil, which the setup function should handle gracefully.
315-
terminal_module.setup(terminal_opts, M.state.config.terminal_cmd)
316+
terminal_module.setup(terminal_opts, M.state.config.terminal_cmd, M.state.config.bin_path)
316317
end
317318
else
318319
logger.error("init", "Failed to load claudecode.terminal module for setup.")

lua/claudecode/terminal.lua

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ local config = {
2323
provider = "auto",
2424
show_native_term_exit_tip = true,
2525
terminal_cmd = nil,
26+
bin_path = "claude",
2627
auto_close = true,
2728
}
2829

@@ -126,7 +127,7 @@ local function get_claude_command_and_env(cmd_args)
126127
local cmd_from_config = config.terminal_cmd
127128
local base_cmd
128129
if not cmd_from_config or cmd_from_config == "" then
129-
base_cmd = "claude" -- Default if not configured
130+
base_cmd = config.bin_path or "claude"
130131
else
131132
base_cmd = cmd_from_config
132133
end
@@ -180,7 +181,7 @@ end
180181
-- @field user_term_config.provider string 'snacks' or 'native' (default: 'snacks').
181182
-- @field user_term_config.show_native_term_exit_tip boolean Show tip for exiting native terminal (default: true).
182183
-- @param p_terminal_cmd string|nil The command to run in the terminal (from main config).
183-
function M.setup(user_term_config, p_terminal_cmd)
184+
function M.setup(user_term_config, p_terminal_cmd, p_bin_path)
184185
if user_term_config == nil then -- Allow nil, default to empty table silently
185186
user_term_config = {}
186187
elseif type(user_term_config) ~= "table" then -- Warn if it's not nil AND not a table
@@ -198,6 +199,16 @@ function M.setup(user_term_config, p_terminal_cmd)
198199
config.terminal_cmd = nil -- Fallback to default behavior
199200
end
200201

202+
if p_bin_path == nil or type(p_bin_path) == "string" then
203+
config.bin_path = p_bin_path or "claude"
204+
else
205+
vim.notify(
206+
"claudecode.terminal.setup: Invalid bin_path provided: " .. tostring(p_bin_path) .. ". Using default.",
207+
vim.log.levels.WARN
208+
)
209+
config.bin_path = "claude"
210+
end
211+
201212
for k, v in pairs(user_term_config) do
202213
if config[k] ~= nil and k ~= "terminal_cmd" then -- terminal_cmd is handled above
203214
if k == "split_side" and (v == "left" or v == "right") then

0 commit comments

Comments
 (0)