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

Method createSession

src/utils/terminalPanel.ts:83–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

ensureSessionMethod · 0.95

Calls 6

pwdFunction · 0.85
getTerminalPanelSocketFunction · 0.85
registerCleanupFunction · 0.85
logForDebuggingFunction · 0.70
onMethod · 0.65
spawnFunction · 0.50

Tested by

no test coverage detected