MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / #handleExit

Method #handleExit

src/utils/ShellCommand.ts:291–335  ·  view source on GitHub ↗
(code: number)

Source from the content-addressed store, hash-verified

289 }
290
291 async #handleExit(code: number): Promise<void> {
292 this.#cleanupListeners()
293 if (this.#status === 'running' || this.#status === 'backgrounded') {
294 this.#status = 'completed'
295 }
296
297 const stdout = await this.taskOutput.getStdout()
298 const result: ExecResult = {
299 code,
300 stdout,
301 stderr: this.taskOutput.getStderr(),
302 interrupted: code === SIGKILL,
303 backgroundTaskId: this.#backgroundTaskId,
304 }
305
306 if (this.taskOutput.stdoutToFile && !this.#backgroundTaskId) {
307 if (this.taskOutput.outputFileRedundant) {
308 // Small file — full content is in result.stdout, delete the file
309 void this.taskOutput.deleteOutputFile()
310 } else {
311 // Large file — tell the caller where the full output lives
312 result.outputFilePath = this.taskOutput.path
313 result.outputFileSize = this.taskOutput.outputFileSize
314 result.outputTaskId = this.taskOutput.taskId
315 }
316 }
317
318 if (this.#killedForSize) {
319 result.stderr = prependStderr(
320 `Background command killed: output file exceeded ${MAX_TASK_OUTPUT_BYTES_DISPLAY}`,
321 result.stderr,
322 )
323 } else if (code === SIGTERM) {
324 result.stderr = prependStderr(
325 `Command timed out after ${formatDuration(this.#timeout)}`,
326 result.stderr,
327 )
328 }
329
330 const resultResolver = this.#resultResolver
331 if (resultResolver) {
332 this.#resultResolver = null
333 resultResolver(result)
334 }
335 }
336
337 #doKill(code?: number): void {
338 this.#status = 'killed'

Callers

nothing calls this directly

Calls 6

#cleanupListenersMethod · 0.95
prependStderrFunction · 0.85
getStdoutMethod · 0.80
getStderrMethod · 0.80
deleteOutputFileMethod · 0.80
formatDurationFunction · 0.70

Tested by

no test coverage detected