From beb0a50413beddfb16f6b49103e1b6b80567cb90 Mon Sep 17 00:00:00 2001 From: Haile <118998054+blackmammoth@users.noreply.github.com> Date: Mon, 4 May 2026 18:54:02 +0300 Subject: [PATCH] fix: enhance regex to correctly parse wrapper file paths for claude.exe (#741) --- server/shared/claude-cli-path.test.ts | 14 ++++++++++++++ server/shared/claude-cli-path.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/server/shared/claude-cli-path.test.ts b/server/shared/claude-cli-path.test.ts index 87cde218..5d0507d7 100644 --- a/server/shared/claude-cli-path.test.ts +++ b/server/shared/claude-cli-path.test.ts @@ -33,6 +33,20 @@ test('resolveClaudeCodeExecutablePath keeps an explicit JavaScript launcher path assert.equal(resolved, scriptPath); }); +test('resolveClaudeCodeExecutablePath can parse a wrapper file path containing letters r and n before claude.exe', () => { + const wrapperPath = 'C:\\tools\\claude'; + const nativePath = 'C:\\tools\\custom\\bin\\node_modules\\@anthropic-ai\\claude-code\\bin\\claude.exe'; + const readFileSync = (() => `exec "$basedir/custom/bin/node_modules/@anthropic-ai/claude-code/bin/claude.exe" "$@"`) as unknown as ResolveClaudeCodeExecutablePathDependencies['readFileSync']; + + const resolved = resolveClaudeCodeExecutablePath(wrapperPath, { + platform: 'win32', + existsSync: (candidate) => candidate === nativePath, + readFileSync, + }); + + assert.equal(resolved, nativePath); +}); + test('resolveClaudeCodeExecutablePath falls back to the configured command when PATH lookup fails', () => { const execFileSync = (() => { throw new Error('not found'); diff --git a/server/shared/claude-cli-path.ts b/server/shared/claude-cli-path.ts index ae8565d5..d917144e 100644 --- a/server/shared/claude-cli-path.ts +++ b/server/shared/claude-cli-path.ts @@ -50,7 +50,7 @@ function resolveClaudeWrapperBinary( return null; } - const matches = content.matchAll(/["']([^"'\\r\\n]*claude\.exe)["']/gi); + const matches = content.matchAll(/["']([^"'\\\r\n]*claude\.exe)["']/gi); for (const match of matches) { const rawTarget = match[1] .replace(/^\$basedir[\\/]/i, '')