MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / createSession

Method createSession

source code/utils/terminalPanel.ts:85–144  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

83 }
84
85 private createSession(): boolean {
86 const shell = process.env.SHELL || '/bin/bash'
87 const cwd = pwd()
88 const socket = getTerminalPanelSocket()
89
90 const result = spawnSync(
91 'tmux',
92 [
93 '-L',
94 socket,
95 'new-session',
96 '-d',
97 '-s',
98 TMUX_SESSION,
99 '-c',
100 cwd,
101 shell,
102 '-l',
103 ],
104 { encoding: 'utf-8' },
105 )
106
107 if (result.status !== 0) {
108 logForDebugging(
109 `Terminal panel: failed to create tmux session: ${result.stderr}`,
110 )
111 return false
112 }
113
114 // Bind Meta+J (toggles back to Claude Code from inside the terminal)
115 // and configure the status bar hint. Chained with ';' to collapse
116 // 5 spawnSync calls into 1.
117 // biome-ignore format: one tmux command per line
118 spawnSync('tmux', [
119 '-L', socket,
120 'bind-key', '-n', 'M-j', 'detach-client', ';',
121 'set-option', '-g', 'status-style', 'bg=default', ';',
122 'set-option', '-g', 'status-left', '', ';',
123 'set-option', '-g', 'status-right', ' Alt+J to return to Claude ', ';',
124 'set-option', '-g', 'status-right-style', 'fg=brightblack',
125 ])
126
127 if (!this.cleanupRegistered) {
128 this.cleanupRegistered = true
129 registerCleanup(async () => {
130 // Detached async spawn — spawnSync here would block the event loop
131 // and serialize the entire cleanup Promise.all in gracefulShutdown.
132 // .on('error') swallows ENOENT if tmux disappears between session
133 // creation and cleanup — prevents spurious uncaughtException noise.
134 spawn('tmux', ['-L', socket, 'kill-server'], {
135 detached: true,
136 stdio: 'ignore',
137 })
138 .on('error', () => {})
139 .unref()
140 })
141 }
142

Callers 1

ensureSessionMethod · 0.95

Calls 5

pwdFunction · 0.85
getTerminalPanelSocketFunction · 0.85
logForDebuggingFunction · 0.85
registerCleanupFunction · 0.85
spawnFunction · 0.85

Tested by

no test coverage detected