[PR #11966] fix(shell): prevent ACCESS_VIOLATION crashes on Windows #14005

Closed
opened 2026-02-16 18:18:49 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/11966

State: closed
Merged: No


On Windows, OpenCode crashes with ACCESS_VIOLATION (0xC0000005) when using Git bash.exe as the default shell due to PTY incompatibility.

This fix:

  • Changes fallback() to use cmd.exe/PowerShell on Windows by default
  • Adds forCommand() to intelligently choose shell based on command type
  • Unix commands (sh, bash, git, etc.) automatically use Git bash on Windows
  • Windows commands use cmd.exe/PowerShell
  • Adds terminal config option for custom shell selection

Fixes: #11954

On Windows, OpenCode crashes with ACCESS_VIOLATION (0xC0000005) when using Git bash.exe as the default shell due to PTY incompatibility.
Root Cause
The original fallback() function in shell.ts tried to use Git bash.exe on Windows:
const git = Bun.which("git")
if (git) {
const bash = path.join(git, "..", "..", "bin", "bash.exe")
if (Bun.file(bash).size) return bash
}
This causes crashes because Git bash.exe has PTY compatibility issues with OpenCode's terminal implementation.
Solution

  1. Change fallback() - Use cmd.exe/PowerShell on Windows by default to avoid crashes
  2. Add forCommand() - Intelligently choose shell based on command type:
    • Unix commands (sh, bash, git, npm, yarn, etc.) → Git bash on Windows
    • Windows commands → cmd.exe/PowerShell
  3. Add needsUnixShell() - Heuristic to detect Unix commands that need a Unix shell
  4. Add terminal config option - Allow users to customize shell selection
    Changes
    packages/opencode/src/shell/shell.ts
  • Modified fallback() to default to cmd.exe on Windows
  • Added forCommand(command: string) for intelligent shell selection
  • Added needsUnixShell(command: string) for Unix command detection
  • Added getGitBashPath() for locating Git bash executable
  • Added getAvailableShells() for listing available shells
    packages/opencode/src/config/config.ts
  • Added terminal config option: z.string().optional().describe("Shell to use for executing commands...")
    packages/opencode/src/tool/bash.ts
  • Updated to use Shell.forCommand() instead of Shell.acceptable()
    Testing
    This fix should be tested on Windows to verify:
  1. Standard Windows commands work without crashes
  2. Unix commands (npm, git, bash scripts) work correctly with Git bash
  3. The terminal config option allows custom shell selection
    Related
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/11966 **State:** closed **Merged:** No --- On Windows, OpenCode crashes with ACCESS_VIOLATION (0xC0000005) when using Git bash.exe as the default shell due to PTY incompatibility. This fix: - Changes fallback() to use cmd.exe/PowerShell on Windows by default - Adds forCommand() to intelligently choose shell based on command type - Unix commands (sh, bash, git, etc.) automatically use Git bash on Windows - Windows commands use cmd.exe/PowerShell - Adds terminal config option for custom shell selection Fixes: #11954 On Windows, OpenCode crashes with `ACCESS_VIOLATION (0xC0000005)` when using Git bash.exe as the default shell due to PTY incompatibility. Root Cause The original `fallback()` function in `shell.ts` tried to use Git bash.exe on Windows: const git = Bun.which("git") if (git) { const bash = path.join(git, "..", "..", "bin", "bash.exe") if (Bun.file(bash).size) return bash } This causes crashes because Git bash.exe has PTY compatibility issues with OpenCode's terminal implementation. Solution 1. Change fallback() - Use cmd.exe/PowerShell on Windows by default to avoid crashes 2. Add forCommand() - Intelligently choose shell based on command type: - Unix commands (sh, bash, git, npm, yarn, etc.) → Git bash on Windows - Windows commands → cmd.exe/PowerShell 3. Add needsUnixShell() - Heuristic to detect Unix commands that need a Unix shell 4. Add terminal config option - Allow users to customize shell selection Changes packages/opencode/src/shell/shell.ts - Modified fallback() to default to cmd.exe on Windows - Added forCommand(command: string) for intelligent shell selection - Added needsUnixShell(command: string) for Unix command detection - Added getGitBashPath() for locating Git bash executable - Added getAvailableShells() for listing available shells packages/opencode/src/config/config.ts - Added terminal config option: z.string().optional().describe("Shell to use for executing commands...") packages/opencode/src/tool/bash.ts - Updated to use Shell.forCommand() instead of Shell.acceptable() Testing This fix should be tested on Windows to verify: 1. ✅ Standard Windows commands work without crashes 2. ✅ Unix commands (npm, git, bash scripts) work correctly with Git bash 3. ✅ The terminal config option allows custom shell selection Related - Issue: #11954
yindo added the pull-request label 2026-02-16 18:18:49 -05:00
yindo closed this issue 2026-02-16 18:18:49 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14005