( cwd: string, permissionMode: PermissionMode, allowDangerouslySkipPermissions: boolean, worktreeEnabled: boolean, worktreeName: string | undefined, tmuxEnabled: boolean, customSessionId?: string | null, worktreePRNumber?: number, messagingSocketPath?: string, )
| 54 | } from './utils/worktree.js' |
| 55 | |
| 56 | export async function setup( |
| 57 | cwd: string, |
| 58 | permissionMode: PermissionMode, |
| 59 | allowDangerouslySkipPermissions: boolean, |
| 60 | worktreeEnabled: boolean, |
| 61 | worktreeName: string | undefined, |
| 62 | tmuxEnabled: boolean, |
| 63 | customSessionId?: string | null, |
| 64 | worktreePRNumber?: number, |
| 65 | messagingSocketPath?: string, |
| 66 | ): Promise<void> { |
| 67 | logForDiagnosticsNoPII('info', 'setup_started') |
| 68 | |
| 69 | // Check for Node.js version < 18 |
| 70 | const nodeVersion = process.version.match(/^v(\d+)\./)?.[1] |
| 71 | if (!nodeVersion || parseInt(nodeVersion) < 18) { |
| 72 | // biome-ignore lint/suspicious/noConsole:: intentional console output |
| 73 | console.error( |
| 74 | chalk.bold.red( |
| 75 | 'Error: Claude Code requires Node.js version 18 or higher.', |
| 76 | ), |
| 77 | ) |
| 78 | process.exit(1) |
| 79 | } |
| 80 | |
| 81 | // Set custom session ID if provided |
| 82 | if (customSessionId) { |
| 83 | switchSession(asSessionId(customSessionId)) |
| 84 | } |
| 85 | |
| 86 | // --bare / SIMPLE: skip UDS messaging server and teammate snapshot. |
| 87 | // Scripted calls don't receive injected messages and don't use swarm teammates. |
| 88 | // Explicit --messaging-socket-path is the escape hatch (per #23222 gate pattern). |
| 89 | if (!isBareMode() || messagingSocketPath !== undefined) { |
| 90 | // Start UDS messaging server (Mac/Linux only). |
| 91 | // Enabled by default for ants — creates a socket in tmpdir if no |
| 92 | // --messaging-socket-path is passed. Awaited so the server is bound |
| 93 | // and $CLAUDE_CODE_MESSAGING_SOCKET is exported before any hook |
| 94 | // (SessionStart in particular) can spawn and snapshot process.env. |
| 95 | if (feature('UDS_INBOX')) { |
| 96 | const m = await import('./utils/udsMessaging.js') |
| 97 | await m.startUdsMessaging( |
| 98 | messagingSocketPath ?? m.getDefaultUdsSocketPath(), |
| 99 | { isExplicit: messagingSocketPath !== undefined }, |
| 100 | ) |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // Teammate snapshot — SIMPLE-only gate (no escape hatch, swarm not used in bare) |
| 105 | if (!isBareMode() && isAgentSwarmsEnabled()) { |
| 106 | const { captureTeammateModeSnapshot } = await import( |
| 107 | './utils/swarm/backends/teammateModeSnapshot.js' |
| 108 | ) |
| 109 | captureTeammateModeSnapshot() |
| 110 | } |
| 111 | |
| 112 | // Terminal backup restoration — interactive only. Print mode doesn't |
| 113 | // interact with terminal settings; the next interactive session will |
no test coverage detected