Windows: Git Bash auto-detection derives invalid bash.exe path #7760

Open
opened 2026-02-16 18:08:09 -05:00 by yindo · 7 comments
Owner

Originally created by @MaxMiksa on GitHub (Jan 27, 2026).

Originally assigned to: @Hona on GitHub.

Description

On Windows, shell auto-detection derives a Git Bash path from Bun.which("git"), but currently treats git.exe as a directory when building the bash.exe path. This can cause Opencode to fall back to cmd.exe even when Git Bash is installed.

Plugins

N/A

OpenCode version

dev (local checkout @ 213c0e18a, package packages/opencode v1.1.36)

Steps to reproduce

  1. Windows with Git for Windows installed (git available on PATH)
  2. Ensure SHELL is unset and OPENCODE_GIT_BASH_PATH is unset
  3. Trigger the bash tool (any tool call that uses Shell.acceptable())
  4. Observe the selected shell path: it may not resolve to the actual Git Bash binary.

Operating System

Windows 11

Terminal

Windows Terminal

Expected

If git.exe is found (e.g. ...\\Git\\cmd\\git.exe), Opencode should derive Git Bash from path.dirname(git) (e.g. ...\\Git\\bin\\bash.exe).

Actual

The derived path may be built from path.join(git, "..", "..", "bin", "bash.exe"), which treats git.exe as a directory and can produce an invalid bash.exe path.

Originally created by @MaxMiksa on GitHub (Jan 27, 2026). Originally assigned to: @Hona on GitHub. ### Description On Windows, shell auto-detection derives a Git Bash path from `Bun.which("git")`, but currently treats `git.exe` as a directory when building the `bash.exe` path. This can cause Opencode to fall back to `cmd.exe` even when Git Bash is installed. ### Plugins N/A ### OpenCode version `dev` (local checkout @ `213c0e18a`, package `packages/opencode` v1.1.36) ### Steps to reproduce 1. Windows with Git for Windows installed (`git` available on PATH) 2. Ensure `SHELL` is unset and `OPENCODE_GIT_BASH_PATH` is unset 3. Trigger the `bash` tool (any tool call that uses `Shell.acceptable()`) 4. Observe the selected shell path: it may not resolve to the actual Git Bash binary. ### Operating System Windows 11 ### Terminal Windows Terminal ### Expected If `git.exe` is found (e.g. `...\\Git\\cmd\\git.exe`), Opencode should derive Git Bash from `path.dirname(git)` (e.g. `...\\Git\\bin\\bash.exe`). ### Actual The derived path may be built from `path.join(git, "..", "..", "bin", "bash.exe")`, which treats `git.exe` as a directory and can produce an invalid `bash.exe` path.
yindo added the windows label 2026-02-16 18:08:09 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 27, 2026):

This issue might be a duplicate of existing issues or closely related to shell detection on Windows. Please check:

  • #10872: bash tool: external_directory prompt skipped when realpath is missing (related Windows shell path issues)
  • #8378: 2 bugs spotted when running Windows Desktop connects to opencode server in WSL: Shell runtime & Path Detection (Windows/WSL path handling bugs)

The core issue of Git Bash path auto-detection on Windows may share root causes with these other Windows shell detection problems. Feel free to ignore if this specific case differs from those issues.

@github-actions[bot] commented on GitHub (Jan 27, 2026): This issue might be a duplicate of existing issues or closely related to shell detection on Windows. Please check: - #10872: bash tool: external_directory prompt skipped when realpath is missing (related Windows shell path issues) - #8378: 2 bugs spotted when running Windows Desktop connects to opencode server in WSL: Shell runtime & Path Detection (Windows/WSL path handling bugs) The core issue of Git Bash path auto-detection on Windows may share root causes with these other Windows shell detection problems. Feel free to ignore if this specific case differs from those issues.
Author
Owner

@MaxMiksa commented on GitHub (Jan 27, 2026):

Thanks! Agreed they’re related to Windows shell handling, but this one is a distinct bug in Shell.fallback() path construction: it treats the git.exe file path as a directory when deriving bash.exe, which can yield an invalid Git Bash path and force fallback to a non-bash shell.

I opened PR #10873 with a 1-line fix (path.dirname(git) before joining).

@MaxMiksa commented on GitHub (Jan 27, 2026): Thanks! Agreed they’re related to Windows shell handling, but this one is a distinct bug in `Shell.fallback()` path construction: it treats the `git.exe` *file path* as a directory when deriving `bash.exe`, which can yield an invalid Git Bash path and force fallback to a non-bash shell. I opened PR #10873 with a 1-line fix (`path.dirname(git)` before joining).
Author
Owner

@AreChen commented on GitHub (Jan 27, 2026):

Git Bash in Windows defaults to opencode, causing command and environment errors. It should use PowerShell instead. Currently, the only workaround is to delete bash.exe to mitigate the issue. Additionally, when using bash, there are cases where it creates undeletable nul files in Windows.

@AreChen commented on GitHub (Jan 27, 2026): Git Bash in Windows defaults to opencode, causing command and environment errors. It should use PowerShell instead. Currently, the only workaround is to delete bash.exe to mitigate the issue. Additionally, when using bash, there are cases where it creates undeletable nul files in Windows.
Author
Owner

@MaxMiksa commented on GitHub (Jan 27, 2026):

Thanks for the context — I agree there are broader Windows+Git Bash edge cases.

This issue/PR (#10873) is narrowly fixing the incorrect Git Bash path derivation (treating git.exe as a directory). It shouldn’t change the overall default shell preference policy.

If the preferred behavior on Windows is to default to PowerShell even when Git Bash is present, that sounds like a separate design decision/issue. Likewise, the “undeletable NUL files” sounds like a separate (and potentially serious) bug; could you share a minimal repro (exact command, working directory, and where the nul file appears)?

In the meantime, users can force PowerShell by setting SHELL (or OPENCODE_GIT_BASH_PATH / OPENCODE_GIT_BASH_PATH-style overrides) so Opencode doesn’t pick Git Bash.

@MaxMiksa commented on GitHub (Jan 27, 2026): Thanks for the context — I agree there are broader Windows+Git Bash edge cases. This issue/PR (#10873) is narrowly fixing the *incorrect* Git Bash path derivation (treating `git.exe` as a directory). It shouldn’t change the overall default shell preference policy. If the preferred behavior on Windows is to default to PowerShell even when Git Bash is present, that sounds like a separate design decision/issue. Likewise, the “undeletable NUL files” sounds like a separate (and potentially serious) bug; could you share a minimal repro (exact command, working directory, and where the `nul` file appears)? In the meantime, users can force PowerShell by setting `SHELL` (or `OPENCODE_GIT_BASH_PATH` / `OPENCODE_GIT_BASH_PATH`-style overrides) so Opencode doesn’t pick Git Bash.
Author
Owner

@AreChen commented on GitHub (Jan 27, 2026):

Thanks for the context — I agree there are broader Windows+Git Bash edge cases.

This issue/PR (#10873) is narrowly fixing the incorrect Git Bash path derivation (treating git.exe as a directory). It shouldn’t change the overall default shell preference policy.

If the preferred behavior on Windows is to default to PowerShell even when Git Bash is present, that sounds like a separate design decision/issue. Likewise, the “undeletable NUL files” sounds like a separate (and potentially serious) bug; could you share a minimal repro (exact command, working directory, and where the nul file appears)?

In the meantime, users can force PowerShell by setting SHELL (or OPENCODE_GIT_BASH_PATH / OPENCODE_GIT_BASH_PATH-style overrides) so Opencode doesn’t pick Git Bash.

Thank you for your quick response. I will try configuring the shell using environment variables.

Regarding the undeletable nul files, I don't think this is an isolated incident in the Windows environment — I've encountered it twice. The solution I found was to navigate to the directory via WSL and delete the files. This is also one of the main reasons pushing me to switch away from the Git Bash terminal.

@AreChen commented on GitHub (Jan 27, 2026): > Thanks for the context — I agree there are broader Windows+Git Bash edge cases. > > This issue/PR ([#10873](https://github.com/anomalyco/opencode/pull/10873)) is narrowly fixing the _incorrect_ Git Bash path derivation (treating `git.exe` as a directory). It shouldn’t change the overall default shell preference policy. > > If the preferred behavior on Windows is to default to PowerShell even when Git Bash is present, that sounds like a separate design decision/issue. Likewise, the “undeletable NUL files” sounds like a separate (and potentially serious) bug; could you share a minimal repro (exact command, working directory, and where the `nul` file appears)? > > In the meantime, users can force PowerShell by setting `SHELL` (or `OPENCODE_GIT_BASH_PATH` / `OPENCODE_GIT_BASH_PATH`-style overrides) so Opencode doesn’t pick Git Bash. Thank you for your quick response. I will try configuring the shell using environment variables. Regarding the undeletable nul files, I don't think this is an isolated incident in the Windows environment — I've encountered it twice. The solution I found was to navigate to the directory via WSL and delete the files. This is also one of the main reasons pushing me to switch away from the Git Bash terminal.
Author
Owner

@pschiel commented on GitHub (Jan 28, 2026):

advise to use OPENCODE_GIT_BASH_PATH

all other path issues concerning path.join would be resolved via #6763

@pschiel commented on GitHub (Jan 28, 2026): advise to use `OPENCODE_GIT_BASH_PATH` all other path issues concerning `path.join` would be resolved via #6763
Author
Owner

@GTonehour commented on GitHub (Feb 12, 2026):

Regarding the undeletable nul files, I don't think this is an isolated incident in the Windows environment — I've encountered it twice

I just created https://github.com/anomalyco/opencode/issues/13369 for that issue.

@GTonehour commented on GitHub (Feb 12, 2026): > Regarding the undeletable nul files, I don't think this is an isolated incident in the Windows environment — I've encountered it twice I just created https://github.com/anomalyco/opencode/issues/13369 for that issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7760