MCPcopy Index your code
hub / github.com/codeaashu/claude-code / findExecutable

Function findExecutable

src/utils/windowsPaths.ts:29–80  ·  view source on GitHub ↗

* Find an executable using where.exe on Windows * @param executable - The name of the executable to find * @returns The path to the executable or null if not found

(executable: string)

Source from the content-addressed store, hash-verified

27 * @returns The path to the executable or null if not found
28 */
29function findExecutable(executable: string): string | null {
30 // For git, check common installation locations first
31 if (executable === 'git') {
32 const defaultLocations = [
33 // check 64 bit before 32 bit
34 'C:\\Program Files\\Git\\cmd\\git.exe',
35 'C:\\Program Files (x86)\\Git\\cmd\\git.exe',
36 // intentionally don't look for C:\Program Files\Git\mingw64\bin\git.exe
37 // because that directory is the "raw" tools with no environment setup
38 ]
39
40 for (const location of defaultLocations) {
41 if (checkPathExists(location)) {
42 return location
43 }
44 }
45 }
46
47 // Fall back to where.exe
48 try {
49 const result = execSync_DEPRECATED(`where.exe ${executable}`, {
50 stdio: 'pipe',
51 encoding: 'utf8',
52 }).trim()
53
54 // SECURITY: Filter out any results from the current directory
55 // to prevent executing malicious git.bat/cmd/exe files
56 const paths = result.split('\r\n').filter(Boolean)
57 const cwd = getCwd().toLowerCase()
58
59 for (const candidatePath of paths) {
60 // Normalize and compare paths to ensure we're not in current directory
61 const normalizedPath = path.resolve(candidatePath).toLowerCase()
62 const pathDir = path.dirname(normalizedPath).toLowerCase()
63
64 // Skip if the executable is in the current working directory
65 if (pathDir === cwd || normalizedPath.startsWith(cwd + path.sep)) {
66 logForDebugging(
67 `Skipping potentially malicious executable in current directory: ${candidatePath}`,
68 )
69 continue
70 }
71
72 // Return the first valid path that's not in the current directory
73 return candidatePath
74 }
75
76 return null
77 } catch {
78 return null
79 }
80}
81
82/**
83 * If Windows, set the SHELL environment variable to git-bash path.

Callers 3

windowsPaths.tsFile · 0.70
env.tsFile · 0.70
ripgrep.tsFile · 0.70

Calls 5

checkPathExistsFunction · 0.85
execSync_DEPRECATEDFunction · 0.85
getCwdFunction · 0.85
logForDebuggingFunction · 0.85
resolveMethod · 0.45

Tested by

no test coverage detected