(
cliArgs: string[],
opts?: { env?: NodeJS.ProcessEnv },
)
| 98 | * @param opts.env Override environment (defaults to process.env) |
| 99 | */ |
| 100 | export function buildCliLaunch( |
| 101 | cliArgs: string[], |
| 102 | opts?: { env?: NodeJS.ProcessEnv }, |
| 103 | ): CliLaunchSpec { |
| 104 | const baseEnv = opts?.env ?? process.env |
| 105 | |
| 106 | // In bundled mode the execPath IS the CLI binary — no script path needed. |
| 107 | // In script mode (dev / npm) we need the script path between runtime flags |
| 108 | // and CLI args so the runtime knows which file to execute. |
| 109 | const args: string[] = |
| 110 | isInBundledMode() || !SCRIPT_PATH |
| 111 | ? [...BOOTSTRAP_ARGS, ...cliArgs] |
| 112 | : [...BOOTSTRAP_ARGS, SCRIPT_PATH, ...cliArgs] |
| 113 | |
| 114 | // Ensure Windows children can discover git-bash without shelling out |
| 115 | const env: NodeJS.ProcessEnv = { ...baseEnv } |
| 116 | if (IS_WINDOWS) { |
| 117 | if ( |
| 118 | process.env.CLAUDE_CODE_GIT_BASH_PATH && |
| 119 | !env.CLAUDE_CODE_GIT_BASH_PATH |
| 120 | ) { |
| 121 | env.CLAUDE_CODE_GIT_BASH_PATH = process.env.CLAUDE_CODE_GIT_BASH_PATH |
| 122 | } |
| 123 | if (process.env.SHELL && !env.SHELL) { |
| 124 | env.SHELL = process.env.SHELL |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | return { |
| 129 | execPath: EXEC_PATH, |
| 130 | args, |
| 131 | env, |
| 132 | windowsHide: IS_WINDOWS, |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Spawn a child CLI process from a launch spec. |
no test coverage detected