@@ -4,6 +4,7 @@ import { promisify } from "util";
44import * as fs from "fs" ;
55import * as path from "path" ;
66import * as os from "os" ;
7+ import { log } from "../utils/logger" ;
78
89const execAsync = promisify ( exec ) ;
910
@@ -79,36 +80,44 @@ export async function findClaudeCliPath(): Promise<string | null> {
7980 const userPath = config . get < string > ( "cliPath" ) ;
8081
8182 if ( userPath && userPath . trim ( ) ) {
83+ log ( `Checking user-configured CLI path: ${ userPath } ` ) ;
8284 if ( await fileExists ( userPath ) ) {
85+ log ( `Found CLI at user-configured path: ${ userPath } ` ) ;
8386 return userPath ;
8487 }
8588 throw new Error ( `Configured CLI path not found: ${ userPath } ` ) ;
8689 }
8790
8891 // 2. Check cache
8992 if ( cachedCliPath && ( await fileExists ( cachedCliPath ) ) ) {
93+ log ( `Using cached CLI path: ${ cachedCliPath } ` ) ;
9094 return cachedCliPath ;
9195 }
9296
97+ log ( "Searching for Claude CLI..." ) ;
98+
9399 // 3. Try which/where
94100 try {
95101 const cmd = process . platform === "win32" ? "where claude" : "which claude" ;
102+ log ( `Trying command: ${ cmd } ` ) ;
96103 const { stdout } = await execAsync ( cmd , {
97104 env : { ...process . env } ,
98105 shell : process . platform === "win32" ? "cmd.exe" : "/bin/bash" ,
99106 } ) ;
100107 const foundPath = stdout . trim ( ) . split ( "\n" ) [ 0 ] ;
101108 if ( foundPath && ( await fileExists ( foundPath ) ) ) {
109+ log ( `Found CLI via ${ cmd } : ${ foundPath } ` ) ;
102110 cachedCliPath = foundPath ;
103111 return foundPath ;
104112 }
105- } catch {
106- // which/where not found
113+ } catch ( err ) {
114+ log ( ` which/where command failed: ${ err instanceof Error ? err . message : String ( err ) } ` ) ;
107115 }
108116
109117 // 4. Try shell profile
110118 if ( process . platform !== "win32" ) {
111119 try {
120+ log ( "Trying shell profile sourcing..." ) ;
112121 const { stdout } = await execAsync (
113122 "source ~/.zshrc 2>/dev/null || source ~/.bashrc 2>/dev/null || true; which claude" ,
114123 {
@@ -117,24 +126,28 @@ export async function findClaudeCliPath(): Promise<string | null> {
117126 ) ;
118127 const foundPath = stdout . trim ( ) ;
119128 if ( foundPath && ( await fileExists ( foundPath ) ) ) {
129+ log ( `Found CLI via shell profile: ${ foundPath } ` ) ;
120130 cachedCliPath = foundPath ;
121131 return foundPath ;
122132 }
123- } catch {
124- // Failed
133+ } catch ( err ) {
134+ log ( `Shell profile sourcing failed: ${ err instanceof Error ? err . message : String ( err ) } ` ) ;
125135 }
126136 }
127137
128138 // 5. Check common paths
139+ log ( "Checking common installation paths..." ) ;
129140 const commonPaths = getCommonCliPaths ( ) ;
130141 for ( const p of commonPaths ) {
131142 const found = await findCliWithGlob ( p ) ;
132143 if ( found ) {
144+ log ( `Found CLI at common path: ${ found } ` ) ;
133145 cachedCliPath = found ;
134146 return found ;
135147 }
136148 }
137149
150+ log ( "Claude CLI not found in any location" ) ;
138151 return null ;
139152}
140153
0 commit comments