google-gemini/gemini-cli · error · Error

Failed to start shell command in '${this.commandName}': ${ex

Error message

Failed to start shell command in '${this.commandName}': ${executionResult.error.message}. Command: ${injection.resolvedCommand}

What it means

Thrown when ShellExecutionService.execute() returns a result whose .error is set and .aborted is false — i.e. the shell command failed to spawn/start (a spawn error, not a cancellation). The message includes the underlying error message and the resolved command.

Source

Thrown at packages/cli/src/services/prompt-processors/shellProcessor.ts:184

        const shellExecutionConfig = {
          ...config.getShellExecutionConfig(),
          defaultFg: activeTheme.colors.Foreground,
          defaultBg: activeTheme.colors.Background,
        };
        const { result } = await ShellExecutionService.execute(
          injection.resolvedCommand,
          config.getTargetDir(),
          () => {},
          new AbortController().signal,
          config.getEnableInteractiveShell(),
          shellExecutionConfig,
        );

        const executionResult = await result;

        // Handle Spawn Errors
        if (executionResult.error && !executionResult.aborted) {
          throw new Error(
            `Failed to start shell command in '${this.commandName}': ${executionResult.error.message}. Command: ${injection.resolvedCommand}`,
          );
        }

        // Append the output, making stderr explicit for the model.
        processedPrompt += executionResult.output;

        // Append a status message if the command did not succeed.
        if (executionResult.aborted) {
          processedPrompt += `\n[Shell command '${injection.resolvedCommand}' aborted]`;
        } else if (
          executionResult.exitCode !== 0 &&
          executionResult.exitCode !== null
        ) {
          processedPrompt += `\n[Shell command '${injection.resolvedCommand}' exited with code ${executionResult.exitCode}]`;
        } else if (executionResult.signal !== null) {
          processedPrompt += `\n[Shell command '${injection.resolvedCommand}' terminated by signal ${executionResult.signal}]`;
        }

View on GitHub (pinned to 5024443c72)

Solutions

  1. Check the error.message in the thrown text — ENOENT usually means a missing binary, EACCES a permission problem.
  2. Verify the command runs standalone in config.getTargetDir() with the same shell (getShellConfiguration()).
  3. Ensure the binary is installed and on PATH (or use an absolute path) inside the sandbox/working directory.
  4. Confirm the shell binary (bash/sh) is available in the execution environment.

Example fix

# before — python not on PATH in sandbox
report !{python ./analyze.py} data
# after
report !{/usr/bin/python3 ./analyze.py} data
Defensive patterns

Strategy: validation

Validate before calling

import commandExists from 'command-exists';
function firstToken(cmd: string): string | null {
  const t = cmd.trim().split(/\s+/)[0];
  return t || null;
}
function commandIsSpawnable(cmd: string, cwd: string): boolean {
  const bin = firstToken(cmd);
  if (!bin) return false;
  if (fs.existsSync(path.resolve(cwd, bin)) || fs.existsSync(bin)) return true;
  try { return commandExists.sync(bin); } catch { return false; }
}

Type guard

interface ExecResult { error?: Error; aborted?: boolean; output?: string; exitCode?: number | null; signal?: number | null; }
function isSpawnError(r: ExecResult): boolean {
  return !!r.error && !r.aborted;
}

Try / catch

try {
  await shellProcessor.process(prompt, ctx);
} catch (e) {
  if (e instanceof Error && /Failed to start shell command/.test(e.message)) {
    // inspect embedded error.message: ENOENT=missing binary, EACCES=permissions
  }
  throw e;
}

Prevention

When it happens

Trigger: ShellExecutionService spawns the resolved command and the spawn fails (ENOENT for a missing binary, EACCES, invalid shell configuration); executionResult.error is populated and executionResult.aborted is false.

Common situations: The command references a binary not on PATH inside the target dir; the configured shell is invalid or missing; insufficient permissions to execute; the spawned program exited with a spawn-level error before producing output.

Related errors


AI-assisted analysis of google-gemini/gemini-cli@5024443c72 (2026-08-12). Data as JSON: /api/errors/09040886f51b0d10. Report an issue: GitHub.