Description
Bug description
The built-in Grep tool always fails with the error "invalid ripgrep output" when any matched file contains non-UTF-8 encoded characters (e.g. GBK/GB2312 Chinese comments or text files).
Steps to reproduce
- Have a project that contains source files with GBK-encoded content
- Use the Grep tool to search for any pattern that matches those files
- Grep tool returns: invalid ripgrep output
Root cause
When ripgrep encounters bytes that cannot be decoded as valid UTF-8, it outputs the matched line as lines.bytes (base64-encoded) instead of lines.text in its JSON format.
Example of the JSON ripgrep actually emits:
{"type":"match","data":{"path":{"text":"./server/sctrl/main.cpp"},
"lines":{"bytes":"CS8vRU5BQkxFX0VYU0RL..."}, ← bytes, not text!
"line_number":1780, ...}}
opencode's ripgrep JSON parser only handles lines.text and throws "invalid ripgrep output" when it encounters lines.bytes, even though the rest of the results (all UTF-8 files) are perfectly valid.
This means a single non-UTF-8 file in the project completely breaks the Grep tool for ALL searches, regardless of whether the specific search matches that file.
Expected behavior
The Grep tool should handle lines.bytes gracefully — either by base64-decoding it, replacing it with a placeholder like [binary/non-UTF-8 line], or skipping only that specific match while returning all valid UTF-8 matches.
Workaround
Use the Bash tool with rg --text instead:
rg --text "PATTERN" .
The --text flag forces ripgrep to treat all files as text, avoiding the bytes field entirely.
Environment
- opencode version: latest
- OS: Ubuntu Linux (x86_64)
- ripgrep version: 15.1.0
- Affected file types: GBK-encoded .c / .cpp / .txt files
Plugins
No response
OpenCode version
No response
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
ubuntu18
Terminal
No response
Description
Bug description
The built-in Grep tool always fails with the error "invalid ripgrep output" when any matched file contains non-UTF-8 encoded characters (e.g. GBK/GB2312 Chinese comments or text files).
Steps to reproduce
Root cause
When ripgrep encounters bytes that cannot be decoded as valid UTF-8, it outputs the matched line as lines.bytes (base64-encoded) instead of lines.text in its JSON format.
Example of the JSON ripgrep actually emits:
{"type":"match","data":{"path":{"text":"./server/sctrl/main.cpp"},
"lines":{"bytes":"CS8vRU5BQkxFX0VYU0RL..."}, ← bytes, not text!
"line_number":1780, ...}}
opencode's ripgrep JSON parser only handles lines.text and throws "invalid ripgrep output" when it encounters lines.bytes, even though the rest of the results (all UTF-8 files) are perfectly valid.
This means a single non-UTF-8 file in the project completely breaks the Grep tool for ALL searches, regardless of whether the specific search matches that file.
Expected behavior
The Grep tool should handle lines.bytes gracefully — either by base64-decoding it, replacing it with a placeholder like [binary/non-UTF-8 line], or skipping only that specific match while returning all valid UTF-8 matches.
Workaround
Use the Bash tool with rg --text instead:
rg --text "PATTERN" .
The --text flag forces ripgrep to treat all files as text, avoiding the bytes field entirely.
Environment
Plugins
No response
OpenCode version
No response
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
ubuntu18
Terminal
No response