Skip to content

make file references, fuzzy search & grep tool work on windows - #2665

Closed
itsrainingmani wants to merge 7 commits into
anomalyco:devfrom
itsrainingmani:fix/windows-file-list
Closed

itsrainingmani wants to merge 7 commits into
anomalyco:devfrom
itsrainingmani:fix/windows-file-list

Conversation

@itsrainingmani

Copy link
Copy Markdown
Contributor

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.

@itsrainingmani
itsrainingmani marked this pull request as ready for review September 19, 2025 14:45
Comment thread packages/opencode/src/session/prompt.ts Outdated
@itsrainingmani
itsrainingmani deleted the fix/windows-file-list branch December 31, 2025 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants