opencode
opencode copied to clipboard
Grep tool fails on Windows: CRLF line ending not stripped from ripgrep path
Bug Description
The built-in grep tool fails on Windows because it doesn't strip the carriage return (\r) from the ripgrep path returned by where rg.
Environment
- OS: Windows 10/11
- ripgrep version: 14.1.0
-
ripgrep location:
C:\ProgramData\chocolatey\bin\rg.exe(installed via Chocolatey)
Steps to Reproduce
- Have ripgrep installed on Windows (via Chocolatey, Scoop, or Winget)
- Use the
greptool in opencode
Expected Behavior
Grep tool finds and executes ripgrep successfully.
Actual Behavior
Error: Executable not found in $PATH: "C:\ProgramData\chocolatey\bin\rg.exe\r"
Note the \r at the end of the path.
Root Cause
The grep tool appears to run where rg to locate ripgrep on Windows. Windows returns paths with CRLF line endings (\r\n). The tool strips \n but leaves the \r, resulting in an invalid path.
Evidence:
> where rg
C:\ProgramData\chocolatey\bin\rg.exe\r\n
C:\Users\Hamza\AppData\Local\Microsoft\WinGet\Links\rg.exe\r\n
Suggested Fix
When parsing the output of where rg on Windows, strip both \r and \n:
// Instead of:
path = strings.TrimSuffix(path, "\n")
// Use:
path = strings.TrimSpace(path)
// or
path = strings.TrimRight(path, "\r\n")
Workaround
Use bash tool with rg command directly:
rg "pattern" --glob "*.py" src/