Skip to content

Grep Tool Fails on Symlinks #7498

Closed

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.

Activity

  1. github-actions commented on Jan 9, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of or related to existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. added a commit that references this issue on Jan 9, 2026
    67a7c7f
  3. changed the title [-]Grep Tool Fails on Symlinks—But Only When It Matters[/-] [+]Grep Tool Fails on Symlinks[/+] on Jan 9, 2026
  4. slockers37 commented on Jan 10, 2026

    @slockers37

    This is pretty important for my workflow, and it’s honestly really annoying to deal with. It breaks my usual way of working, so I’d really appreciate a fix.

  5. jeroenev commented on Feb 19, 2026

    @jeroenev

    This was broken again in #11415
    Maybe this issue should be re-opened?
    I've fixed this again in #12992 with an optional setting, so you can follow symlinks but it's not the default, since following symlinks can cause issues of it's own (recursive symlinks etc...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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