From 7b22fc5c3fc5086442418629f1005b3d10df6336 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Mon, 9 Mar 2026 16:49:00 +0700 Subject: [PATCH] refactor: extract Claude binary lookup into separate function --- .../server/agent/providers/claude-agent.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/server/src/server/agent/providers/claude-agent.ts b/packages/server/src/server/agent/providers/claude-agent.ts index fcc3080c3..f9124ba55 100644 --- a/packages/server/src/server/agent/providers/claude-agent.ts +++ b/packages/server/src/server/agent/providers/claude-agent.ts @@ -363,14 +363,18 @@ type ClaudeAgentSessionOptions = { logger: Logger; }; -function resolveClaudeBinary(): string { +function whichClaude(): string | null { try { - const claudePath = execSync("which claude", { encoding: "utf8" }).trim(); - if (claudePath) { - return claudePath; - } + return execSync("which claude", { encoding: "utf8", env: process.env }).trim() || null; } catch { - // fall through + return null; + } +} + +function resolveClaudeBinary(): string { + const claudePath = whichClaude(); + if (claudePath) { + return claudePath; } throw new Error( "Claude CLI not found. Install claude or configure agents.providers.claude.command.mode='replace'." @@ -1410,11 +1414,7 @@ export class ClaudeAgentClient implements AgentClient { this.defaults = options.defaults; this.logger = options.logger.child({ module: "agent", provider: "claude" }); this.runtimeSettings = options.runtimeSettings; - try { - this.claudePath = execSync("which claude", { encoding: "utf8" }).trim() || null; - } catch { - this.claudePath = null; - } + this.claudePath = whichClaude(); if (this.claudePath) { try { const version = execSync(`${this.claudePath} --version`, { encoding: "utf8" }).trim(); @@ -1423,7 +1423,7 @@ export class ClaudeAgentClient implements AgentClient { this.logger.info({ claudePath: this.claudePath }, "Resolved Claude binary (version unknown)"); } } else { - this.logger.warn("Claude binary not found via 'which claude'; SDK will use bundled binary"); + this.logger.warn("Claude binary not found in PATH; SDK will use bundled binary"); } }