MCPcopy Create free account
hub / github.com/Noumena-Network/code / doInitialize

Function doInitialize

src/utils/tmuxSocket.ts:271–418  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

269}
270
271async function doInitialize(): Promise<void> {
272 const socket = getNcodeSocketName()
273
274 // Create a new session with our custom socket
275 // Pass CLAUDE_CODE_SKIP_PROMPT_HISTORY via -e so it's set in the initial shell environment
276 //
277 // On Windows, the tmux server inherits WSL_INTEROP from the short-lived
278 // wsl.exe that spawns it; once `new-session -d` detaches and wsl.exe exits,
279 // that socket stops servicing requests. Any cli.exe launched inside the pane
280 // then hits `UtilAcceptVsock: accept4 failed 110` (ETIMEDOUT). Observed on
281 // 2026-03-25: server PID 386 (started alongside /init at WSL boot) inherited
282 // /run/WSL/383_interop — init's own socket, which listens but doesn't handle
283 // interop. /run/WSL/1_interop is a stable symlink WSL maintains to the real
284 // handler; pin the server to it so interop survives the spawning wsl.exe.
285 const result = await execTmux([
286 '-L',
287 socket,
288 'new-session',
289 '-d',
290 '-s',
291 'base',
292 '-e',
293 'CLAUDE_CODE_SKIP_PROMPT_HISTORY=true',
294 ...(getPlatform() === 'windows'
295 ? ['-e', 'WSL_INTEROP=/run/WSL/1_interop']
296 : []),
297 ])
298
299 if (result.code !== 0) {
300 // Session might already exist from a previous run with same PID (unlikely but possible)
301 // Check if the session exists
302 const checkResult = await execTmux([
303 '-L',
304 socket,
305 'has-session',
306 '-t',
307 'base',
308 ])
309 if (checkResult.code !== 0) {
310 throw new Error(
311 `Failed to create tmux session on socket ${socket}: ${result.stderr}`,
312 )
313 }
314 }
315
316 // Register cleanup to kill the tmux server on exit
317 registerCleanup(killTmuxServer)
318
319 // Set CLAUDE_CODE_SKIP_PROMPT_HISTORY in the tmux GLOBAL environment (-g).
320 // Without -g this would only apply to the 'base' session, and new sessions
321 // created by TungstenTool (e.g. 'test', 'verify') would not inherit it.
322 // Any NCode instance spawned on this socket will inherit this env var,
323 // preventing test/verification sessions from polluting the user's real
324 // command history and --resume session list.
325 await execTmux([
326 '-L',
327 socket,
328 'set-environment',

Callers 1

ensureSocketInitializedFunction · 0.85

Calls 6

getNcodeSocketNameFunction · 0.85
getPlatformFunction · 0.85
registerCleanupFunction · 0.85
setNcodeSocketInfoFunction · 0.85
execTmuxFunction · 0.70
logForDebuggingFunction · 0.70

Tested by

no test coverage detected