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

Function exec

source code/utils/Shell.ts:183–444  ·  view source on GitHub ↗
(
  command: string,
  abortSignal: AbortSignal,
  shellType: ShellType,
  options?: ExecOptions,
)

Source from the content-addressed store, hash-verified

181 * Creates a new shell process for each command execution
182 */
183export async function exec(
184 command: string,
185 abortSignal: AbortSignal,
186 shellType: ShellType,
187 options?: ExecOptions,
188): Promise<ShellCommand> {
189 const {
190 timeout,
191 onProgress,
192 preventCwdChanges,
193 shouldUseSandbox,
194 shouldAutoBackground,
195 onStdout,
196 } = options ?? {}
197 const commandTimeout = timeout || DEFAULT_TIMEOUT
198
199 const provider = await resolveProvider[shellType]()
200
201 const id = Math.floor(Math.random() * 0x10000)
202 .toString(16)
203 .padStart(4, '0')
204
205 // Sandbox temp directory - use per-user directory name to prevent multi-user permission conflicts
206 const sandboxTmpDir = posixJoin(
207 process.env.CLAUDE_CODE_TMPDIR || '/tmp',
208 getClaudeTempDirName(),
209 )
210
211 const { commandString: builtCommand, cwdFilePath } =
212 await provider.buildExecCommand(command, {
213 id,
214 sandboxTmpDir: shouldUseSandbox ? sandboxTmpDir : undefined,
215 useSandbox: shouldUseSandbox ?? false,
216 })
217
218 let commandString = builtCommand
219
220 let cwd = pwd()
221
222 // Recover if the current working directory no longer exists on disk.
223 // This can happen when a command deletes its own CWD (e.g., temp dir cleanup).
224 try {
225 await realpath(cwd)
226 } catch {
227 const fallback = getOriginalCwd()
228 logForDebugging(
229 `Shell CWD "${cwd}" no longer exists, recovering to "${fallback}"`,
230 )
231 try {
232 await realpath(fallback)
233 setCwdState(fallback)
234 cwd = fallback
235 } catch {
236 return createFailedCommand(
237 `Working directory "${cwd}" no longer exists. Please restart Claude from an existing directory.`,
238 )
239 }
240 }

Callers 4

runPowerShellCommandFunction · 0.85
runShellCommandFunction · 0.85
refreshAwsAuthFunction · 0.85
refreshGcpAuthFunction · 0.85

Calls 15

clearMethod · 0.95
readFileSyncFunction · 0.90
unlinkSyncFunction · 0.90
getClaudeTempDirNameFunction · 0.85
pwdFunction · 0.85
getOriginalCwdFunction · 0.85
logForDebuggingFunction · 0.85
setCwdStateFunction · 0.85
createFailedCommandFunction · 0.85
createAbortedCommandFunction · 0.85
getFsImplementationFunction · 0.85
generateTaskIdFunction · 0.85

Tested by

no test coverage detected