Skip to content

Grep tool fails on Windows: CRLF line ending not stripped from ripgrep path #5946

@ham-zax

Description

@ham-zax

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

  1. Have ripgrep installed on Windows (via Chocolatey, Scoop, or Winget)
  2. Use the grep tool 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/

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions