gemini-cli - 💡(How to fix) Fix Bug: run_shell_command fails on macOS (zsh) due to hardcoded shopt guard

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

On macOS systems (where the default shell is zsh), the run_shell_command tool fails with the error: zsh:1: command not found: shopt

Error Message

On macOS systems (where the default shell is zsh), the run_shell_command tool fails with the error:

Root Cause

The issue stems from a hardcoded shell configuration in packages/core/src/utils/shell-utils.ts. The getShellConfiguration() function defaults to bash for all non-Windows systems:

// packages/core/src/utils/shell-utils.ts
export function getShellConfiguration(): ShellConfiguration {
  // ...
  // Unix-like systems (Linux, macOS)
  return { executable: 'bash', argsPrefix: ['-c'], shell: 'bash' };
}

Because shell is hardcoded to 'bash', the shellExecutionService.ts always applies the BASH_SHOPT_GUARD:

// packages/core/src/services/shellExecutionService.ts
function ensurePromptvarsDisabled(command: string, shell: ShellType): string {
  if (shell !== 'bash') {
    return command;
  }
  // ...
  return `${BASH_SHOPT_GUARD} ${command}`;
}

Since shopt is a Bash builtin and does not exist in Zsh, every command executed via the CLI on a Mac fails immediately.

Code Example

// packages/core/src/utils/shell-utils.ts
export function getShellConfiguration(): ShellConfiguration {
  // ...
  // Unix-like systems (Linux, macOS)
  return { executable: 'bash', argsPrefix: ['-c'], shell: 'bash' };
}

---

// packages/core/src/services/shellExecutionService.ts
function ensurePromptvarsDisabled(command: string, shell: ShellType): string {
  if (shell !== 'bash') {
    return command;
  }
  // ...
  return `${BASH_SHOPT_GUARD} ${command}`;
}

---

export function getShellConfiguration(): ShellConfiguration {
  if (isWindows()) {
    // ... existing Windows logic
  }

  const shellEnv = process.env['SHELL'];
  const executable = shellEnv ? path.basename(shellEnv) : 'bash';
  
  // Map the executable name to a known ShellType
  // Note: ShellType union may need to be expanded to include 'zsh'
  let shellType: ShellType = 'bash';
  if (executable.includes('zsh')) shellType = 'zsh' as any; 
  
  return { 
    executable: shellEnv || 'bash', 
    argsPrefix: ['-c'], 
    shell: shellType 
  };
}
RAW_BUFFERClick to expand / collapse

Description

On macOS systems (where the default shell is zsh), the run_shell_command tool fails with the error: zsh:1: command not found: shopt

Root Cause

The issue stems from a hardcoded shell configuration in packages/core/src/utils/shell-utils.ts. The getShellConfiguration() function defaults to bash for all non-Windows systems:

// packages/core/src/utils/shell-utils.ts
export function getShellConfiguration(): ShellConfiguration {
  // ...
  // Unix-like systems (Linux, macOS)
  return { executable: 'bash', argsPrefix: ['-c'], shell: 'bash' };
}

Because shell is hardcoded to 'bash', the shellExecutionService.ts always applies the BASH_SHOPT_GUARD:

// packages/core/src/services/shellExecutionService.ts
function ensurePromptvarsDisabled(command: string, shell: ShellType): string {
  if (shell !== 'bash') {
    return command;
  }
  // ...
  return `${BASH_SHOPT_GUARD} ${command}`;
}

Since shopt is a Bash builtin and does not exist in Zsh, every command executed via the CLI on a Mac fails immediately.

Regression Context

This behavior was introduced in commit f17cfb2 (approx. April 28, 2026) as part of the "Shell Command Safety" initiative. Previously, the CLI was shell-agnostic on Unix-like systems.

Suggested Fix

Update getShellConfiguration to respect the user's SHELL environment variable rather than assuming bash.

export function getShellConfiguration(): ShellConfiguration {
  if (isWindows()) {
    // ... existing Windows logic
  }

  const shellEnv = process.env['SHELL'];
  const executable = shellEnv ? path.basename(shellEnv) : 'bash';
  
  // Map the executable name to a known ShellType
  // Note: ShellType union may need to be expanded to include 'zsh'
  let shellType: ShellType = 'bash';
  if (executable.includes('zsh')) shellType = 'zsh' as any; 
  
  return { 
    executable: shellEnv || 'bash', 
    argsPrefix: ['-c'], 
    shell: shellType 
  };
}

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - 💡(How to fix) Fix Bug: run_shell_command fails on macOS (zsh) due to hardcoded shopt guard