MCPcopy Create free account
hub / github.com/T-Lab-CUHKSZ/claude-code / main

Function main

src/main.tsx:598–869  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

596 extraCliArgs: []
597} : undefined;
598export async function main() {
599 profileCheckpoint('main_function_start');
600
601 // SECURITY: Prevent Windows from executing commands from current directory
602 // This must be set before ANY command execution to prevent PATH hijacking attacks
603 // See: https://docs.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-searchpathw
604 process.env.NoDefaultCurrentDirectoryInExePath = '1';
605
606 // Initialize warning handler early to catch warnings
607 initializeWarningHandler();
608 process.on('exit', () => {
609 resetCursor();
610 });
611 process.on('SIGINT', () => {
612 // In print mode, print.ts registers its own SIGINT handler that aborts
613 // the in-flight query and calls gracefulShutdown; skip here to avoid
614 // preempting it with a synchronous process.exit().
615 if (process.argv.includes('-p') || process.argv.includes('--print')) {
616 return;
617 }
618 process.exit(0);
619 });
620 profileCheckpoint('main_warning_handler_initialized');
621
622 // Check for cc:// or cc+unix:// URL in argv — rewrite so the main command
623 // handles it, giving the full interactive TUI instead of a stripped-down subcommand.
624 // For headless (-p), we rewrite to the internal `open` subcommand.
625 if (feature('DIRECT_CONNECT')) {
626 const rawCliArgs = process.argv.slice(2);
627 const ccIdx = rawCliArgs.findIndex(a => a.startsWith('cc://') || a.startsWith('cc+unix://'));
628 if (ccIdx !== -1 && _pendingConnect) {
629 const ccUrl = rawCliArgs[ccIdx]!;
630 const {
631 parseConnectUrl
632 } = await import('./server/parseConnectUrl.js');
633 const parsed = parseConnectUrl(ccUrl);
634 _pendingConnect.dangerouslySkipPermissions = rawCliArgs.includes('--dangerously-skip-permissions');
635 if (rawCliArgs.includes('-p') || rawCliArgs.includes('--print')) {
636 // Headless: rewrite to internal `open` subcommand
637 const stripped = rawCliArgs.filter((_, i) => i !== ccIdx);
638 const dspIdx = stripped.indexOf('--dangerously-skip-permissions');
639 if (dspIdx !== -1) {
640 stripped.splice(dspIdx, 1);
641 }
642 process.argv = [process.argv[0]!, process.argv[1]!, 'open', ccUrl, ...stripped];
643 } else {
644 // Interactive: strip cc:// URL and flags, run main command
645 _pendingConnect.url = parsed.serverUrl;
646 _pendingConnect.authToken = parsed.authToken;
647 const stripped = rawCliArgs.filter((_, i) => i !== ccIdx);
648 const dspIdx = stripped.indexOf('--dangerously-skip-permissions');
649 if (dspIdx !== -1) {
650 stripped.splice(dspIdx, 1);
651 }
652 process.argv = [process.argv[0]!, process.argv[1]!, ...stripped];
653 }
654 }
655 }

Callers

nothing calls this directly

Calls 15

profileCheckpointFunction · 0.85
initializeWarningHandlerFunction · 0.85
resetCursorFunction · 0.85
featureFunction · 0.85
enableConfigsFunction · 0.85
handleDeepLinkUriFunction · 0.85
handleUrlSchemeLaunchFunction · 0.85
extractFlagFunction · 0.85
gracefulShutdownSyncFunction · 0.85
stopCapturingEarlyInputFunction · 0.85
setIsInteractiveFunction · 0.85
initializeEntrypointFunction · 0.85

Tested by

no test coverage detected