Skip to content

Grep Tool Fails on Symlinks #7498

@kdcokenny

Description

@kdcokenny

Ran into an issue where grep returns "No files found" when working in directories with symlinked content. What's frustrating is that glob and list handle these cases just fine, so the behavior feels inconsistent and broken from a user perspective.

The Problem

When you run OpenCode from a symlink farm (think ln -s /real/project/src src), here's what happens:

  • glob **/*.ts works perfectly
  • list shows all the files you'd expect
  • grep "pattern" mysteriously finds nothing

How to Reproduce

Set up a quick test case:

mkdir /tmp/symlink-test && cd /tmp/symlink-test
ln -s /path/to/real/project/src src
ln -s /path/to/real/project/packages packages

Now run OpenCode from /tmp/symlink-test and try searching. glob and list cooperate, but grep gives you "No files found" every time.

Diving into the Code

The issue is pretty clear once you look at the implementation. There's an internal inconsistency in how ripgrep is called:

  • Ripgrep.search() (the internal function) skips the --follow flag
  • Ripgrep.files() (used by glob/list) correctly includes --follow

So the same tool behaves differently depending on which wrapper function you use.

The Weird Twist

Here's what got me: when ripgrep isn't available and the code falls back to standard grep -r, it actually works. That's because grep -r follows symlinks by default—ripgrep doesn't. So our "better" tool is actually what broke things.

Fix

Need to add --follow flag in two spots:

  1. packages/opencode/src/tool/grep.ts — the CLI args
  2. packages/opencode/src/file/ripgrep.ts — the Ripgrep.search args

That should make all the file-finding tools behave consistently across symlinked directories.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions