@@ -3,6 +3,7 @@ import { homedir } from 'node:os';
33
44import { spawnProcess } from '../../../../process/spawn.js' ;
55import { buildClaudeExecCommand } from './commands.js' ;
6+ import { metadata } from '../metadata.js' ;
67import { expandHomeDir } from '../../../../../shared/utils/index.js' ;
78import { logger } from '../../../../../shared/logging/index.js' ;
89
@@ -124,12 +125,14 @@ export async function runClaude(options: RunClaudeOptions): Promise<RunClaudeRes
124125 logger . debug ( `Claude runner - prompt length: ${ prompt . length } , lines: ${ prompt . split ( '\n' ) . length } ` ) ;
125126 logger . debug ( `Claude runner - args count: ${ args . length } , model: ${ model ?? 'default' } ` ) ;
126127
127- const result = await spawnProcess ( {
128- command,
129- args,
130- cwd : workingDir ,
131- env : mergedEnv ,
132- stdinInput : prompt , // Pass prompt via stdin instead of command-line argument
128+ let result ;
129+ try {
130+ result = await spawnProcess ( {
131+ command,
132+ args,
133+ cwd : workingDir ,
134+ env : mergedEnv ,
135+ stdinInput : prompt , // Pass prompt via stdin instead of command-line argument
133136 onStdout : inheritTTY
134137 ? undefined
135138 : ( chunk ) => {
@@ -154,8 +157,21 @@ export async function runClaude(options: RunClaudeOptions): Promise<RunClaudeRes
154157 } ,
155158 signal : abortSignal ,
156159 stdioMode : inheritTTY ? 'inherit' : 'pipe' ,
157- timeout,
158- } ) ;
160+ timeout,
161+ } ) ;
162+ } catch ( error ) {
163+ const err = error as unknown as { code ?: string ; message ?: string } ;
164+ const message = err ?. message ?? '' ;
165+ const notFound = err ?. code === 'ENOENT' || / n o t r e c o g n i z e d a s a n i n t e r n a l o r e x t e r n a l c o m m a n d / i. test ( message ) || / c o m m a n d n o t f o u n d / i. test ( message ) ;
166+ if ( notFound ) {
167+ const full = `${ command } ${ args . join ( ' ' ) } ` . trim ( ) ;
168+ const install = metadata . installCommand ;
169+ const name = metadata . name ;
170+ logger . error ( `${ name } CLI not found when executing: ${ full } ` ) ;
171+ throw new Error ( `'${ command } ' is not available on this system. Please install ${ name } first:\n ${ install } ` ) ;
172+ }
173+ throw error ;
174+ }
159175
160176 if ( result . exitCode !== 0 ) {
161177 const errorOutput = result . stderr . trim ( ) || result . stdout . trim ( ) || 'no error output' ;
0 commit comments