Windows Terminal: Git bash.exe causes ACCESS_VIOLATION crash (0xC0000005) #8422

Open
opened 2026-02-16 18:09:56 -05:00 by yindo · 1 comment
Owner

Originally created by @Qfbxz on GitHub (Feb 3, 2026).

Originally assigned to: @rekram1-node on GitHub.

Problem

On Windows, OpenCode's PTY implementation crashes when trying to use Git's bash.exe as the terminal shell.

Error:

ERROR service=pty error=failed exitCode=-1073741819
exitCode=-1073741819 = 0xC0000005 (ACCESS_VIOLATION)

Root Cause:
Git's bash.exe has compatibility issues with OpenCode's PTY implementation on Windows, causing memory access violations.

Impact:

  • Terminal crashes immediately on startup when Git bash is the default shell
  • Unix commands (ls, cat, bun, git, npm) don't work when using native Windows shells (cmd.exe, PowerShell)

Solution

  1. Interactive PTY Sessions: Use native Windows shells (PowerShell → cmd.exe) by default to avoid crashes
  2. Command Execution: Automatically detect Unix commands and use Git bash only when needed
  3. Configurable: Users can still explicitly choose their preferred terminal via:
    • Environment variable: OPENCODE_TERMINAL
    • Config file: "terminal": "powershell.exe" or "terminal": "cmd.exe"

Files Changed

  • packages/opencode/src/shell/shell.ts: Improved shell detection and selection
  • packages/opencode/src/tool/bash.ts: Use intelligent shell selection per command
  • packages/opencode/src/config/config.ts: Add terminal config option

Testing

  • Terminal opens without crash on Windows (using PowerShell/cmd.exe)
  • Unix commands (ls, cat, bun, git, npm) work correctly (using Git bash when needed)
  • Windows commands work in PowerShell/cmd.exe
  • Config option allows custom terminal selection
Originally created by @Qfbxz on GitHub (Feb 3, 2026). Originally assigned to: @rekram1-node on GitHub. ## Problem On Windows, OpenCode's PTY implementation crashes when trying to use Git's bash.exe as the terminal shell. **Error**: ``` ERROR service=pty error=failed exitCode=-1073741819 exitCode=-1073741819 = 0xC0000005 (ACCESS_VIOLATION) ``` **Root Cause**: Git's bash.exe has compatibility issues with OpenCode's PTY implementation on Windows, causing memory access violations. **Impact**: - Terminal crashes immediately on startup when Git bash is the default shell - Unix commands (ls, cat, bun, git, npm) don't work when using native Windows shells (cmd.exe, PowerShell) ## Solution 1. **Interactive PTY Sessions**: Use native Windows shells (PowerShell → cmd.exe) by default to avoid crashes 2. **Command Execution**: Automatically detect Unix commands and use Git bash only when needed 3. **Configurable**: Users can still explicitly choose their preferred terminal via: - Environment variable: `OPENCODE_TERMINAL` - Config file: `"terminal": "powershell.exe"` or `"terminal": "cmd.exe"` ## Files Changed - `packages/opencode/src/shell/shell.ts`: Improved shell detection and selection - `packages/opencode/src/tool/bash.ts`: Use intelligent shell selection per command - `packages/opencode/src/config/config.ts`: Add `terminal` config option ## Testing - [x] Terminal opens without crash on Windows (using PowerShell/cmd.exe) - [x] Unix commands (ls, cat, bun, git, npm) work correctly (using Git bash when needed) - [x] Windows commands work in PowerShell/cmd.exe - [x] Config option allows custom terminal selection
yindo added the windows label 2026-02-16 18:09:56 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 3, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #11043: Segfault on Windows git bash (msys) when using bash tool with cwd - same root cause of Git bash compatibility issues
  • #10871: Windows: Git Bash auto-detection derives invalid bash.exe path - related shell detection problem
  • #10719: Terminal state not restored when exiting with ctrl+c on windows (git bash) - another Git bash issue on Windows
  • #5525: git bash.exe processes on Windows get orphaned - longstanding Git bash issue

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Feb 3, 2026): This issue might be a duplicate of existing issues. Please check: - #11043: Segfault on Windows git bash (msys) when using bash tool with cwd - same root cause of Git bash compatibility issues - #10871: Windows: Git Bash auto-detection derives invalid bash.exe path - related shell detection problem - #10719: Terminal state not restored when exiting with ctrl+c on windows (git bash) - another Git bash issue on Windows - #5525: git bash.exe processes on Windows get orphaned - longstanding Git bash issue Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8422