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

Function setup

src/setup.ts:57–509  ·  view source on GitHub ↗
(
  cwd: string,
  permissionMode: PermissionMode,
  allowDangerouslySkipPermissions: boolean,
  worktreeEnabled: boolean,
  worktreeName: string | undefined,
  tmuxEnabled: boolean,
  customSessionId?: string | null,
  worktreePRNumber?: number,
  messagingSocketPath?: string,
)

Source from the content-addressed store, hash-verified

55} from './utils/worktree.js'
56
57export async function setup(
58 cwd: string,
59 permissionMode: PermissionMode,
60 allowDangerouslySkipPermissions: boolean,
61 worktreeEnabled: boolean,
62 worktreeName: string | undefined,
63 tmuxEnabled: boolean,
64 customSessionId?: string | null,
65 worktreePRNumber?: number,
66 messagingSocketPath?: string,
67): Promise<void> {
68 logForDiagnosticsNoPII('info', 'setup_started')
69
70 // Check for Node.js version < 18
71 const nodeVersion = process.version.match(/^v(\d+)\./)?.[1]
72 if (!nodeVersion || parseInt(nodeVersion, 10) < 18) {
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 try {
98 await m.startUdsMessaging(
99 messagingSocketPath ?? m.getDefaultUdsSocketPath(),
100 { isExplicit: messagingSocketPath !== undefined },
101 )
102 } catch (error) {
103 logError(error)
104 console.error(
105 chalk.red(
106 `Error: Failed to start messaging socket (UDS_INBOX): ${errorMessage(error)}`,
107 ),
108 )
109 process.exit(1)
110 }
111 }
112 }
113
114 // Teammate snapshot — SIMPLE-only gate (no escape hatch, swarm not used in bare)

Callers 3

runFunction · 0.85
installHandlerFunction · 0.85
mcpServeHandlerFunction · 0.85

Calls 15

logForDiagnosticsNoPIIFunction · 0.85
switchSessionFunction · 0.85
asSessionIdFunction · 0.85
isBareModeFunction · 0.85
isAgentSwarmsEnabledFunction · 0.85
setCwdFunction · 0.85

Tested by

no test coverage detected