22 * Shared agent query options builder for LLM scanner agents.
33 */
44
5+ import { execSync } from "node:child_process" ;
6+
57type Options = import ( "@anthropic-ai/claude-agent-sdk" ) . Options ;
68
9+ /** Find claude binary path. Cached after first lookup. */
10+ let _claudePath : string | undefined ;
11+ function findClaudePath ( ) : string | undefined {
12+ if ( _claudePath !== undefined ) return _claudePath || undefined ;
13+ try {
14+ _claudePath = execSync ( "which claude" , { encoding : "utf-8" } ) . trim ( ) ;
15+ } catch {
16+ _claudePath = "" ;
17+ }
18+ return _claudePath || undefined ;
19+ }
20+
721export type AgentRole = "scanner" | "tester" | "reviewer" | "engineer" | "architect" | "auditor" ;
822
923const ROLE_TOOLS : Record < AgentRole , { allowed : string [ ] ; disallowed : string [ ] } > = {
@@ -41,6 +55,8 @@ export function buildAgentQueryOptions(base: {
4155} , role : AgentRole ) : Options {
4256 const tools = ROLE_TOOLS [ role ] ;
4357
58+ const claudePath = findClaudePath ( ) ;
59+
4460 return {
4561 cwd : base . cwd ,
4662 model : base . model ,
@@ -49,6 +65,7 @@ export function buildAgentQueryOptions(base: {
4965 : { type : "preset" as const , preset : "claude_code" as const } ,
5066 settingSources : [ "project" ] ,
5167 ...( base . maxTurns !== undefined ? { maxTurns : base . maxTurns } : { } ) ,
68+ ...( claudePath ? { pathToClaudeCodeExecutable : claudePath } : { } ) ,
5269 permissionMode : "bypassPermissions" ,
5370 allowDangerouslySkipPermissions : true ,
5471 allowedTools : tools . allowed ,
0 commit comments