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+ for cmd in claude claude-code; do
17+ local exe_path
18+ exe_path=" $( type -P " $cmd " 2> /dev/null) " && [ -n " $exe_path " ] && {
19+ echo " $exe_path "
20+ return 0
21+ }
22+ done
23+
24+ # Fallback: use type -t to check if it's an executable file
25+ for cmd in claude claude-code; do
26+ if [ " $( type -t " $cmd " 2> /dev/null) " = " file" ]; then
27+ command -v " $cmd "
28+ return 0
29+ fi
30+ done
31+
32+ return 1
33+ }
34+
435# Check if Claude Code is available
536ai_can_start () {
6- command -v claude > /dev/null 2>&1 || command -v claude-code > /dev/null 2>&1
37+ find_claude_executable > /dev/null 2>&1
738}
839
940# Start Claude Code in a directory
@@ -12,7 +43,10 @@ ai_start() {
1243 local path=" $1 "
1344 shift
1445
15- if ! ai_can_start; then
46+ local claude_cmd
47+ claude_cmd=" $( find_claude_executable) "
48+
49+ if [ -z " $claude_cmd " ]; then
1650 log_error " Claude Code not found. Install from https://claude.com/claude-code"
1751 log_info " The CLI is called 'claude' (or 'claude-code' in older versions)"
1852 return 1
@@ -23,10 +57,5 @@ ai_start() {
2357 return 1
2458 fi
2559
26- # Try 'claude' first (official binary name), fallback to 'claude-code'
27- if command -v claude > /dev/null 2>&1 ; then
28- (cd " $path " && claude " $@ " )
29- else
30- (cd " $path " && claude-code " $@ " )
31- fi
60+ (cd " $path " && " $claude_cmd " " $@ " )
3261}
0 commit comments