[PR #2665] make file references, fuzzy search & grep tool work on windows #10397

Closed
opened 2026-02-16 18:15:02 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/2665

State: closed
Merged: No


Related issues - #631, #2430

Issues

Currently, there are a few file related features broken in Windows.

  • Fuzzy searching for files using @ only shows agents and files with git diffs. Continuing to search for a filename doesn't show files that match the input
  • Directly referencing a file path with @ displays a failed to send message. 400 Bad Request - Error: ENOENT: no such file or directory, scandir <directory-of-file> error.
  • Searching for a pattern with the grep tool always yields a "No Files Found" message even when there should be matching files.

Fixes

  • Fuzzy searching works by constructing the following command structure with ripgrep & fzf
    rg --files --follow --hidden --glob='!.git/*' | fzf --filter=<input-query> | head -n <input-limit>
    and running it via Bun Shell. Unfortunately, Bun Shell doesn't yet implement head causing any head invocations on Windows to fail. We bypass this by falling back to limiting the results array instead on Windows.
  • Direct file references are converted to file paths using decodeURIComponent in packages/opencode/src/session/prompt.ts. This results in a Windows file path that looks like this - /C:/Users/Username/samplefile.ts. The extra / at the start and the / separators prevent this from being a valid windows file path. Instead, we use the fileURLtoPath function in Bun to create a valid, cross-platform filepath from the message part URL.
  • The grep tool sets the working directory for ripgrep to be the current directory (in absolute path terms) which causes ripgrep to output matches also in absolute path terms (which includes the Drive letter on Windows. This causes the line splitting logic to fail since the Windows Drive Letter includes a :). If we skip doing this, ripgrep will output matches in relative path terms and we can avoid having to write platform specific line splitting.
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/2665 **State:** closed **Merged:** No --- Related issues - #631, #2430 ### Issues Currently, there are a few file related features broken in Windows. - Fuzzy searching for files using `@` only shows agents and files with git diffs. Continuing to search for a filename doesn't show files that match the input - Directly referencing a file path with `@` displays a `failed to send message. 400 Bad Request - Error: ENOENT: no such file or directory, scandir <directory-of-file>` error. - Searching for a pattern with the grep tool always yields a "No Files Found" message even when there should be matching files. ### Fixes - Fuzzy searching works by constructing the following command structure with ripgrep & fzf `rg --files --follow --hidden --glob='!.git/*' | fzf --filter=<input-query> | head -n <input-limit>` and running it via [Bun Shell](https://bun.com/docs/runtime/shell). Unfortunately, Bun Shell [doesn't yet implement `head`](https://github.com/oven-sh/bun/issues/9716) causing any `head` invocations on Windows to fail. We bypass this by falling back to limiting the results array instead on Windows. - Direct file references are converted to file paths using `decodeURIComponent` in `packages/opencode/src/session/prompt.ts`. This results in a Windows file path that looks like this - `/C:/Users/Username/samplefile.ts`. The extra `/` at the start and the `/` separators prevent this from being a valid windows file path. Instead, we use the `fileURLtoPath` function in Bun to create a valid, cross-platform filepath from the message part URL. - The `grep` tool sets the working directory for ripgrep to be the current directory (in absolute path terms) which causes ripgrep to output matches also in absolute path terms (which includes the Drive letter on Windows. This causes the line splitting logic to fail since the Windows Drive Letter includes a `:`). If we skip doing this, ripgrep will output matches in relative path terms and we can avoid having to write platform specific line splitting.
yindo added the pull-request label 2026-02-16 18:15:02 -05:00
yindo closed this issue 2026-02-16 18:15:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10397