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

Function ensureSocketInitialized

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

Source from the content-addressed store, hash-verified

206 * Bash commands will run without tmux isolation.
207 */
208export async function ensureSocketInitialized(): Promise<void> {
209 // Already initialized
210 if (isSocketInitialized()) {
211 return
212 }
213
214 // Check if tmux is available before trying to use it
215 const available = await checkTmuxAvailable()
216 if (!available) {
217 return
218 }
219
220 // Another call is already initializing - wait for it but don't propagate errors
221 // The original caller handles the error and sets up graceful degradation
222 if (isInitializing && initPromise) {
223 try {
224 await initPromise
225 } catch {
226 // Ignore - the original caller logs the error
227 }
228 return
229 }
230
231 isInitializing = true
232 initPromise = doInitialize()
233
234 try {
235 await initPromise
236 } catch (error) {
237 // Log error but don't throw - graceful degradation
238 const err = toError(error)
239 logError(err)
240 logForDebugging(
241 `[Socket] Failed to initialize tmux socket: ${err.message}. Tmux isolation will be disabled.`,
242 )
243 } finally {
244 isInitializing = false
245 }
246}
247
248/**
249 * Kills the tmux server for Claude's isolated socket.

Callers 1

getEnvironmentOverridesFunction · 0.85

Calls 6

isSocketInitializedFunction · 0.85
checkTmuxAvailableFunction · 0.85
doInitializeFunction · 0.85
toErrorFunction · 0.85
logErrorFunction · 0.70
logForDebuggingFunction · 0.70

Tested by

no test coverage detected