Skip to content

Commit f97d351

Browse files
George-iamclaude
andcommitted
fix: pass pathToClaudeCodeExecutable to SDK query options
SDK fallback uses import.meta.url to find claude binary, which is undefined in CJS bundles (esbuild replaces import.meta with {}). Now explicitly find and pass claude path via `which claude`. Also: improved error logging in init.ts (stack trace on scan failure). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f8bcec1 commit f97d351

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/tools/init.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ export async function initProjectWithLLM(projectPath: string, opts?: {
174174
log(` [${projectName}] Scanners complete, processing results...`);
175175
for (const settled of scanners) {
176176
if (settled.status === "rejected") {
177-
errors.push(`LLM scan failed: ${settled.reason?.message ?? settled.reason}`);
177+
const err = settled.reason;
178+
const msg = err?.message ?? String(err);
179+
const stack = err?.stack ? `\n${err.stack.split("\n").slice(0, 3).join("\n")}` : "";
180+
errors.push(`LLM scan failed: ${msg}${stack}`);
178181
continue;
179182
}
180183
const val = settled.value;

src/utils/agent-options.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,22 @@
22
* Shared agent query options builder for LLM scanner agents.
33
*/
44

5+
import { execSync } from "node:child_process";
6+
57
type 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+
721
export type AgentRole = "scanner" | "tester" | "reviewer" | "engineer" | "architect" | "auditor";
822

923
const 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

Comments
 (0)