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

Function createLocalSSHSession

src/ssh/createSSHSession.ts:255–356  ·  view source on GitHub ↗
(config: {
  cwd?: string
  permissionMode?: string
  dangerouslySkipPermissions?: boolean
})

Source from the content-addressed store, hash-verified

253}
254
255export async function createLocalSSHSession(config: {
256 cwd?: string
257 permissionMode?: string
258 dangerouslySkipPermissions?: boolean
259}): Promise<SSHSession> {
260 const { proxy, authEnv } = await createAuthProxy()
261
262 const cliArgs: string[] = [
263 '--output-format',
264 'stream-json',
265 '--input-format',
266 'stream-json',
267 '-p',
268 ]
269 if (config.cwd) {
270 cliArgs.push('--cwd', config.cwd)
271 }
272 if (config.permissionMode) {
273 cliArgs.push('--permission-mode', config.permissionMode)
274 }
275 if (config.dangerouslySkipPermissions) {
276 cliArgs.push('--dangerously-skip-permissions')
277 }
278
279 const spec = buildCliLaunch(cliArgs)
280
281 let proc: Subprocess
282 try {
283 proc = Bun.spawn([spec.execPath, ...spec.args], {
284 stdin: 'pipe',
285 stdout: 'pipe',
286 stderr: 'pipe',
287 env: { ...spec.env, ...authEnv },
288 })
289 } catch (err) {
290 proxy.stop()
291 throw new SSHSessionError(
292 `Failed to spawn local CLI process: ${err instanceof Error ? err.message : String(err)}`,
293 )
294 }
295
296 logForDebugging('[SSH] local session spawned, waiting for init message...')
297
298 const stderrChunks: string[] = []
299 collectStderr(proc, stderrChunks)
300
301 let remoteCwd: string
302 try {
303 remoteCwd = await waitForInit(proc, config.cwd)
304 } catch (err) {
305 proxy.stop()
306 proc.kill()
307 throw err
308 }
309
310 logForDebugging(`[SSH] local session initialized, remoteCwd=${remoteCwd}`)
311
312 let currentProc = proc

Callers 1

runFunction · 0.85

Calls 9

createAuthProxyFunction · 0.85
buildCliLaunchFunction · 0.85
collectStderrFunction · 0.85
waitForInitFunction · 0.85
stopMethod · 0.65
logForDebuggingFunction · 0.50
pushMethod · 0.45
spawnMethod · 0.45
killMethod · 0.45

Tested by

no test coverage detected