Skip to content

Commit 27075ec

Browse files
yamork779claude
andcommitted
feat(cli_with_custom_uri): support environment base uri cli mode
Refactor shell command construction to use login shell (-l flag) on Unix-like systems, ensuring that user environment variables are properly loaded from shell configuration files (.bashrc, .profile, etc.) when executing the CLI through a pipe. This change allows the CLI to access environment variables that may be required for proper functionality, which is important when the command is invoked with stdin input. 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 646f564 commit 27075ec

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

‎src/cli/execution.ts‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,18 @@ export async function generateWithCLI(
3939
progressCallback(`Using ${model} model...`);
4040
}
4141

42-
const command =
43-
process.platform === "win32"
44-
? `type "${promptFile}" | ${escapedCliPath} -p --model ${model}`
45-
: `cat "${promptFile}" | ${escapedCliPath} -p --model ${model}`;
42+
const baseCommand = process.platform === "win32"
43+
? `type "${promptFile}" | ${escapedCliPath} -p --model ${model}`
44+
: `cat "${promptFile}" | ${escapedCliPath} -p --model ${model}`;
45+
46+
// Use login shell to load user's environment variables (e.g., from .bashrc, .profile)
47+
const command = process.platform === "win32"
48+
? baseCommand
49+
: `/bin/bash -l -c ${JSON.stringify(baseCommand)}`;
4650

4751
logCommand(command);
4852

4953
const { stdout, stderr } = await execAsync(command, {
50-
shell: process.platform === "win32" ? "cmd.exe" : "/bin/bash",
5154
maxBuffer: 10 * 1024 * 1024,
5255
timeout: 120000,
5356
});
@@ -163,15 +166,18 @@ export async function generateWithCLIManaged(
163166
progressCallback("Using haiku model (managed mode)...");
164167
}
165168

166-
const command =
167-
process.platform === "win32"
168-
? `type "${promptFile}" | ${escapedCliPath} -p --model haiku`
169-
: `cat "${promptFile}" | ${escapedCliPath} -p --model haiku`;
169+
const baseCommand = process.platform === "win32"
170+
? `type "${promptFile}" | ${escapedCliPath} -p --model haiku`
171+
: `cat "${promptFile}" | ${escapedCliPath} -p --model haiku`;
172+
173+
// Use login shell to load user's environment variables (e.g., from .bashrc, .profile)
174+
const command = process.platform === "win32"
175+
? baseCommand
176+
: `/bin/bash -l -c ${JSON.stringify(baseCommand)}`;
170177

171178
logCommand(command);
172179

173180
const { stdout, stderr } = await execAsync(command, {
174-
shell: process.platform === "win32" ? "cmd.exe" : "/bin/bash",
175181
maxBuffer: 10 * 1024 * 1024,
176182
timeout: 120000,
177183
cwd: repoPath,

0 commit comments

Comments
 (0)