MCPcopy
hub / github.com/claude-code-best/claude-code / DetachedEngine

Class DetachedEngine

src/cli/bg/engines/detached.ts:12–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import { tailLog } from '../tail.js'
11
12export class DetachedEngine implements BgEngine {
13 readonly name = 'detached' as const
14 readonly supportsInteractiveInput = false
15
16 async available(): Promise<boolean> {
17 return true
18 }
19
20 async start(opts: BgStartOptions): Promise<BgStartResult> {
21 mkdirSync(dirname(opts.logPath), { recursive: true })
22
23 const logFd = openSync(opts.logPath, 'a')
24
25 const launch = buildCliLaunch(opts.args, {
26 env: {
27 ...opts.env,
28 CLAUDE_CODE_SESSION_KIND: 'bg',
29 CLAUDE_CODE_SESSION_NAME: opts.sessionName,
30 CLAUDE_CODE_SESSION_LOG: opts.logPath,
31 } as NodeJS.ProcessEnv,
32 })
33
34 const child = spawnCli(launch, {
35 detached: true,
36 stdio: ['ignore', logFd, logFd],
37 cwd: opts.cwd,
38 })
39
40 child.unref()
41 closeSync(logFd)
42
43 const pid = child.pid ?? 0
44
45 return {
46 pid,
47 sessionName: opts.sessionName,
48 logPath: opts.logPath,
49 engineUsed: 'detached',
50 }
51 }
52
53 async attach(session: SessionEntry): Promise<void> {
54 if (!session.logPath) {
55 throw new Error(`Session ${session.sessionId} has no log path.`)
56 }
57 await tailLog(session.logPath)
58 }
59}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected