| import { feature } from 'bun:bundle'; |
| import { |
| applyProfileEnvToProcessEnv, |
| buildStartupEnvFromProfile, |
| } from '../utils/providerProfile.js' |
| import { |
| getProviderValidationError, |
| validateProviderEnvForStartupOrExit, |
| } from '../utils/providerValidation.js' |
|
|
| |
| |
| |
| |
| |
| |
| if (typeof globalThis.File === 'undefined') { |
| try { |
| |
| |
| const { File: NodeFile } = require('node:buffer') |
| |
| globalThis.File = NodeFile |
| } catch { |
| |
| |
| globalThis.File = class File extends Blob { |
| name: string |
| lastModified: number |
| constructor(parts: BlobPart[], name: string, opts?: FilePropertyBag) { |
| super(parts, opts) |
| this.name = name |
| this.lastModified = opts?.lastModified ?? Date.now() |
| } |
| } |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| process.env.CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS ??= 'true' |
|
|
| |
| |
| process.env.COREPACK_ENABLE_AUTO_PIN = '0'; |
|
|
| |
| |
| if (process.env.CLAUDE_CODE_REMOTE === 'true') { |
| |
| const existing = process.env.NODE_OPTIONS || ''; |
| |
| process.env.NODE_OPTIONS = existing ? `${existing} --max-old-space-size=8192` : '--max-old-space-size=8192'; |
| } |
|
|
| |
| |
| |
| |
| |
| if (feature('ABLATION_BASELINE') && process.env.CLAUDE_CODE_ABLATION_BASELINE) { |
| for (const k of ['CLAUDE_CODE_SIMPLE', 'CLAUDE_CODE_DISABLE_THINKING', 'DISABLE_INTERLEAVED_THINKING', 'DISABLE_COMPACT', 'DISABLE_AUTO_COMPACT', 'CLAUDE_CODE_DISABLE_AUTO_MEMORY', 'CLAUDE_CODE_DISABLE_BACKGROUND_TASKS']) { |
| |
| process.env[k] ??= '1'; |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| async function main(): Promise<void> { |
| const args = process.argv.slice(2); |
|
|
| |
| if (args.length === 1 && (args[0] === '--version' || args[0] === '-v' || args[0] === '-V')) { |
| |
| |
| console.log(`${MACRO.DISPLAY_VERSION ?? MACRO.VERSION} (Open Claude)`); |
| return; |
| } |
|
|
| |
| |
| if (args.includes('--provider')) { |
| const { applyProviderFlagFromArgs } = await import('../utils/providerFlag.js'); |
| const result = applyProviderFlagFromArgs(args); |
| if (result?.error) { |
| |
| console.error(`Error: ${result.error}`); |
| process.exit(1); |
| } |
| } |
|
|
| |
| { |
| const { enableConfigs } = await import('../utils/config.js') |
| enableConfigs() |
| } |
|
|
| |
| { |
| const { applySafeConfigEnvironmentVariables } = await import('../utils/managedEnv.js') |
| applySafeConfigEnvironmentVariables() |
| } |
|
|
| const startupEnv = await buildStartupEnvFromProfile({ |
| processEnv: process.env, |
| }) |
| if (startupEnv !== process.env) { |
| const startupProfileError = await getProviderValidationError(startupEnv) |
| if (startupProfileError) { |
| console.error( |
| `Warning: ignoring saved provider profile. ${startupProfileError}`, |
| ) |
| } else { |
| applyProfileEnvToProcessEnv(process.env, startupEnv) |
| } |
| } |
|
|
| |
| { |
| const { |
| hydrateGithubModelsTokenFromSecureStorage, |
| refreshGithubModelsTokenIfNeeded, |
| } = await import('../utils/githubModelsCredentials.js') |
| await refreshGithubModelsTokenIfNeeded() |
| hydrateGithubModelsTokenFromSecureStorage() |
| } |
|
|
| await validateProviderEnvForStartupOrExit() |
|
|
| |
| const { printStartupScreen } = await import('../components/StartupScreen.js') |
| printStartupScreen() |
|
|
| |
| const { |
| profileCheckpoint |
| } = await import('../utils/startupProfiler.js'); |
| profileCheckpoint('cli_entry'); |
|
|
| |
| |
| |
| if (feature('DUMP_SYSTEM_PROMPT') && args[0] === '--dump-system-prompt') { |
| profileCheckpoint('cli_dump_system_prompt_path'); |
| const { |
| enableConfigs |
| } = await import('../utils/config.js'); |
| enableConfigs(); |
| const { |
| getMainLoopModel |
| } = await import('../utils/model/model.js'); |
| const modelIdx = args.indexOf('--model'); |
| const model = modelIdx !== -1 && args[modelIdx + 1] || getMainLoopModel(); |
| const { |
| getSystemPrompt |
| } = await import('../constants/prompts.js'); |
| const prompt = await getSystemPrompt([], model); |
| |
| console.log(prompt.join('\n')); |
| return; |
| } |
| if (process.argv[2] === '--claude-in-chrome-mcp') { |
| profileCheckpoint('cli_claude_in_chrome_mcp_path'); |
| const { |
| runClaudeInChromeMcpServer |
| } = await import('../utils/claudeInChrome/mcpServer.js'); |
| await runClaudeInChromeMcpServer(); |
| return; |
| } else if (process.argv[2] === '--chrome-native-host') { |
| profileCheckpoint('cli_chrome_native_host_path'); |
| const { |
| runChromeNativeHost |
| } = await import('../utils/claudeInChrome/chromeNativeHost.js'); |
| await runChromeNativeHost(); |
| return; |
| } else if (feature('CHICAGO_MCP') && process.argv[2] === '--computer-use-mcp') { |
| profileCheckpoint('cli_computer_use_mcp_path'); |
| const { |
| runComputerUseMcpServer |
| } = await import('../utils/computerUse/mcpServer.js'); |
| await runComputerUseMcpServer(); |
| return; |
| } |
|
|
| |
| |
| |
| |
| |
| if (feature('DAEMON') && args[0] === '--daemon-worker') { |
| const { |
| runDaemonWorker |
| } = await import('../daemon/workerRegistry.js'); |
| await runDaemonWorker(args[1]); |
| return; |
| } |
|
|
| |
| |
| |
| |
| if (feature('BRIDGE_MODE') && (args[0] === 'remote-control' || args[0] === 'rc' || args[0] === 'remote' || args[0] === 'sync' || args[0] === 'bridge')) { |
| profileCheckpoint('cli_bridge_path'); |
| const { |
| enableConfigs |
| } = await import('../utils/config.js'); |
| enableConfigs(); |
| const { |
| getBridgeDisabledReason, |
| checkBridgeMinVersion |
| } = await import('../bridge/bridgeEnabled.js'); |
| const { |
| BRIDGE_LOGIN_ERROR |
| } = await import('../bridge/types.js'); |
| const { |
| bridgeMain |
| } = await import('../bridge/bridgeMain.js'); |
| const { |
| exitWithError |
| } = await import('../utils/process.js'); |
|
|
| |
| |
| |
| |
| const { |
| getClaudeAIOAuthTokens |
| } = await import('../utils/auth.js'); |
| if (!getClaudeAIOAuthTokens()?.accessToken) { |
| exitWithError(BRIDGE_LOGIN_ERROR); |
| } |
| const disabledReason = await getBridgeDisabledReason(); |
| if (disabledReason) { |
| exitWithError(`Error: ${disabledReason}`); |
| } |
| const versionError = checkBridgeMinVersion(); |
| if (versionError) { |
| exitWithError(versionError); |
| } |
|
|
| |
| const { |
| waitForPolicyLimitsToLoad, |
| isPolicyAllowed |
| } = await import('../services/policyLimits/index.js'); |
| await waitForPolicyLimitsToLoad(); |
| if (!isPolicyAllowed('allow_remote_control')) { |
| exitWithError("Error: Remote Control is disabled by your organization's policy."); |
| } |
| await bridgeMain(args.slice(1)); |
| return; |
| } |
|
|
| |
| if (feature('DAEMON') && args[0] === 'daemon') { |
| profileCheckpoint('cli_daemon_path'); |
| const { |
| enableConfigs |
| } = await import('../utils/config.js'); |
| enableConfigs(); |
| const { |
| initSinks |
| } = await import('../utils/sinks.js'); |
| initSinks(); |
| const { |
| daemonMain |
| } = await import('../daemon/main.js'); |
| await daemonMain(args.slice(1)); |
| return; |
| } |
|
|
| |
| |
| |
| if (feature('BG_SESSIONS') && (args[0] === 'ps' || args[0] === 'logs' || args[0] === 'attach' || args[0] === 'kill' || args.includes('--bg') || args.includes('--background'))) { |
| profileCheckpoint('cli_bg_path'); |
| const { |
| enableConfigs |
| } = await import('../utils/config.js'); |
| enableConfigs(); |
| const bg = await import('../cli/bg.js'); |
| switch (args[0]) { |
| case 'ps': |
| await bg.psHandler(args.slice(1)); |
| break; |
| case 'logs': |
| await bg.logsHandler(args[1]); |
| break; |
| case 'attach': |
| await bg.attachHandler(args[1]); |
| break; |
| case 'kill': |
| await bg.killHandler(args[1]); |
| break; |
| default: |
| await bg.handleBgFlag(args); |
| } |
| return; |
| } |
|
|
| |
| if (feature('TEMPLATES') && (args[0] === 'new' || args[0] === 'list' || args[0] === 'reply')) { |
| profileCheckpoint('cli_templates_path'); |
| const { |
| templatesMain |
| } = await import('../cli/handlers/templateJobs.js'); |
| await templatesMain(args); |
| |
| |
| |
| process.exit(0); |
| } |
|
|
| |
| |
| if (feature('BYOC_ENVIRONMENT_RUNNER') && args[0] === 'environment-runner') { |
| profileCheckpoint('cli_environment_runner_path'); |
| const { |
| environmentRunnerMain |
| } = await import('../environment-runner/main.js'); |
| await environmentRunnerMain(args.slice(1)); |
| return; |
| } |
|
|
| |
| |
| |
| if (feature('SELF_HOSTED_RUNNER') && args[0] === 'self-hosted-runner') { |
| profileCheckpoint('cli_self_hosted_runner_path'); |
| const { |
| selfHostedRunnerMain |
| } = await import('../self-hosted-runner/main.js'); |
| await selfHostedRunnerMain(args.slice(1)); |
| return; |
| } |
|
|
| |
| const hasTmuxFlag = args.includes('--tmux') || args.includes('--tmux=classic'); |
| if (hasTmuxFlag && (args.includes('-w') || args.includes('--worktree') || args.some(a => a.startsWith('--worktree=')))) { |
| profileCheckpoint('cli_tmux_worktree_fast_path'); |
| const { |
| enableConfigs |
| } = await import('../utils/config.js'); |
| enableConfigs(); |
| const { |
| isWorktreeModeEnabled |
| } = await import('../utils/worktreeModeEnabled.js'); |
| if (isWorktreeModeEnabled()) { |
| const { |
| execIntoTmuxWorktree |
| } = await import('../utils/worktree.js'); |
| const result = await execIntoTmuxWorktree(args); |
| if (result.handled) { |
| return; |
| } |
| |
| if (result.error) { |
| const { |
| exitWithError |
| } = await import('../utils/process.js'); |
| exitWithError(result.error); |
| } |
| } |
| } |
|
|
| |
| if (args.length === 1 && (args[0] === '--update' || args[0] === '--upgrade')) { |
| process.argv = [process.argv[0]!, process.argv[1]!, 'update']; |
| } |
|
|
| |
| |
| if (args.includes('--bare')) { |
| process.env.CLAUDE_CODE_SIMPLE = '1'; |
| } |
|
|
| |
| if (process.env.OPENCLAUDE_DISABLE_EARLY_INPUT !== '1') { |
| const { |
| startCapturingEarlyInput |
| } = await import('../utils/earlyInput.js'); |
| startCapturingEarlyInput(); |
| } |
| profileCheckpoint('cli_before_main_import'); |
| const { |
| main: cliMain |
| } = await import('../main.js'); |
| profileCheckpoint('cli_after_main_import'); |
| await cliMain(); |
| profileCheckpoint('cli_after_main_complete'); |
| } |
|
|
| |
| void main(); |
|
|