MCPcopy Index your code
hub / github.com/codeaashu/claude-code / launchWindowsTerminal

Function launchWindowsTerminal

src/utils/deepLink/terminalLauncher.ts:419–469  ·  view source on GitHub ↗
(
  terminal: TerminalInfo,
  claudePath: string,
  claudeArgs: string[],
  cwd?: string,
)

Source from the content-addressed store, hash-verified

417}
418
419async function launchWindowsTerminal(
420 terminal: TerminalInfo,
421 claudePath: string,
422 claudeArgs: string[],
423 cwd?: string,
424): Promise<boolean> {
425 const args: string[] = []
426
427 switch (terminal.name) {
428 // --- PURE ARGV PATH ---
429 case 'Windows Terminal':
430 if (cwd) args.push('-d', cwd)
431 args.push('--', claudePath, ...claudeArgs)
432 break
433
434 // --- SHELL-STRING PATHS ---
435 // PowerShell -Command and cmd /k take a command string. No argv exec
436 // mode that also keeps the session interactive after claude exits.
437 // User input is escaped per-shell; correctness of that escaping is
438 // load-bearing here.
439
440 case 'PowerShell': {
441 // Single-quoted PowerShell strings have NO escape sequences (only
442 // '' for a literal quote). Double-quoted strings interpret backtick
443 // escapes — a query containing `" could break out.
444 const cdCmd = cwd ? `Set-Location ${psQuote(cwd)}; ` : ''
445 args.push(
446 '-NoExit',
447 '-Command',
448 `${cdCmd}& ${psQuote(claudePath)} ${claudeArgs.map(psQuote).join(' ')}`,
449 )
450 break
451 }
452
453 default: {
454 const cdCmd = cwd ? `cd /d ${cmdQuote(cwd)} && ` : ''
455 args.push(
456 '/k',
457 `${cdCmd}${cmdQuote(claudePath)} ${claudeArgs.map(a => cmdQuote(a)).join(' ')}`,
458 )
459 break
460 }
461 }
462
463 // cmd.exe does NOT use MSVCRT-style argument parsing. libuv's default
464 // quoting for spawn() on Windows assumes MSVCRT rules and would double-
465 // escape our already-cmdQuote'd string. Bypass it for cmd.exe only.
466 return spawnDetached(terminal.command, args, {
467 windowsVerbatimArguments: terminal.name === 'Command Prompt',
468 })
469}
470
471/**
472 * Spawn a terminal detached so the handler process can exit without

Callers 1

launchInTerminalFunction · 0.85

Calls 4

psQuoteFunction · 0.85
cmdQuoteFunction · 0.85
spawnDetachedFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected