MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / isClaudeProcess

Function isClaudeProcess

source code/utils/nativeInstaller/pidLock.ts:103–134  ·  view source on GitHub ↗

* Validate that a running process is actually a Claude process * This helps mitigate PID reuse issues

(pid: number, expectedExecPath: string)

Source from the content-addressed store, hash-verified

101 * This helps mitigate PID reuse issues
102 */
103function isClaudeProcess(pid: number, expectedExecPath: string): boolean {
104 if (!isProcessRunning(pid)) {
105 return false
106 }
107
108 // If the PID matches our current process, we know it's valid
109 // This handles test environments where the command might not contain 'claude'
110 if (pid === process.pid) {
111 return true
112 }
113
114 try {
115 const command = getProcessCommand(pid)
116 if (!command) {
117 // If we can't get the command, trust the PID check
118 // This is conservative - we'd rather not delete a running version
119 return true
120 }
121
122 // Check if the command contains 'claude' or the expected exec path
123 const normalizedCommand = command.toLowerCase()
124 const normalizedExecPath = expectedExecPath.toLowerCase()
125
126 return (
127 normalizedCommand.includes('claude') ||
128 normalizedCommand.includes(normalizedExecPath)
129 )
130 } catch {
131 // If command check fails, trust the PID check
132 return true
133 }
134}
135
136/**
137 * Read and parse a lock file's content

Callers 1

isLockActiveFunction · 0.85

Calls 2

getProcessCommandFunction · 0.85
isProcessRunningFunction · 0.70

Tested by

no test coverage detected