Skip to content

Commit 3a68387

Browse files
him0claude
andcommitted
Fix Claude adapter to support shell function definitions
When `claude` is defined as a shell function (e.g., wrapping ~/.claude/local/claude), the previous implementation failed because shell functions are not inherited by subshells. Changes: - Add `find_claude_executable()` helper to detect executable files only - Check common installation path (~/.claude/local/claude) first - Use `type -P` to find executables, excluding shell functions - Both `ai_can_start()` and `ai_start()` now use the executable path directly This allows the adapter to work correctly even when users have `claude` defined as a shell function that wraps the actual executable. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent fae9160 commit 3a68387

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

‎adapters/ai/claude.sh‎

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
#!/usr/bin/env bash
22
# Claude Code AI adapter
33

4+
# Find the actual claude executable (not a shell function)
5+
# Returns the path to the executable, or empty string if not found
6+
find_claude_executable(){
7+
local cmd
8+
9+
# Check common installation paths first
10+
if [ -x"$HOME/.claude/local/claude" ];then
11+
echo"$HOME/.claude/local/claude"
12+
return 0
13+
fi
14+
15+
# Try to find executable using type -P (Bash/Zsh)
16+
forcmdin claude claude-code;do
17+
ifcommand -v type>/dev/null 2>&1;then
18+
local exe_path
19+
exe_path="$(type -P "$cmd"2>/dev/null)"&& [ -n"$exe_path" ] &&{
20+
echo"$exe_path"
21+
return 0
22+
}
23+
fi
24+
done
25+
26+
# Fallback: use command -v but exclude functions
27+
forcmdin claude claude-code;do
28+
iftype"$cmd"2>/dev/null | grep -qv "function";then
29+
ifcommand -v "$cmd">/dev/null 2>&1;then
30+
echo"$cmd"
31+
return 0
32+
fi
33+
fi
34+
done
35+
36+
return 1
37+
}
38+
439
# Check if Claude Code is available
540
ai_can_start(){
6-
command -v claude >/dev/null 2>&1||command -v claude-code>/dev/null 2>&1
41+
find_claude_executable>/dev/null 2>&1
742
}
843

944
# Start Claude Code in a directory
@@ -12,7 +47,10 @@ ai_start(){
1247
local path="$1"
1348
shift
1449

15-
if! ai_can_start;then
50+
local claude_cmd
51+
claude_cmd="$(find_claude_executable)"
52+
53+
if [ -z"$claude_cmd" ];then
1654
log_error "Claude Code not found. Install from https://claude.com/claude-code"
1755
log_info "The CLI is called 'claude' (or 'claude-code' in older versions)"
1856
return 1
@@ -23,10 +61,5 @@ ai_start(){
2361
return 1
2462
fi
2563

26-
# Try 'claude' first (official binary name), fallback to 'claude-code'
27-
ifcommand -v claude >/dev/null 2>&1;then
28-
(cd "$path"&& claude "$@")
29-
else
30-
(cd "$path"&& claude-code "$@")
31-
fi
64+
(cd "$path"&&"$claude_cmd""$@")
3265
}

0 commit comments

Comments
(0)