Skip to content

Grep tool returns 0 results in multi-repo workspace (workspace root is not a git repo) #22455

@jinxiaocheng

Description

@jinxiaocheng

Environment

  • OpenCode version: 1.4.1
  • OS: Windows 11 64-bit (win32)
  • Shell: PowerShell 5.1
  • Workspace root: Not a git repository
  • Subdirectories: Each is an independent git repo

Summary

The built-in \Grep\ tool returns 0 results for patterns that demonstrably exist in source files. Running
g\ (ripgrep) directly from the terminal on the same path returns all expected matches.

Workspace Structure

\
D:\Code_fix\ # NOT a git repo (workspace root)
├── ygp-fms\ # Independent git repo
├── ygp-bciscm-fms\ # Independent git repo
└── ygp-invoice\ # Independent git repo
\\

Each subdirectory is an independent Java microservice with its own .git/\ and .gitignore.

Steps to Reproduce

1. OpenCode Grep tool — 0 results

Called the \Grep\ tool (provided by OpenCode) with:

  • pattern: \9203\
  • path: \D:\Code_fix\ (also tried \D:\Code_fix\ygp-bciscm-fms)
  • include: *.yml, *.properties, *.xml, *.java\ (tried each separately)
  • output_mode: \content\

Result: \No matches found\ — across ALL attempts (6 separate calls with different filters).

2. ripgrep directly — 7 results

\\powershell
rg "9203" "D:\Code_fix\ygp-bciscm-fms" --no-ignore -n
\\

Result:

\
D:\Code_fix\ygp-bciscm-fms\bciscm-fms-service\Dockerfile:9:EXPOSE 9203 19203 29203
D:\Code_fix\ygp-bciscm-fms\bciscm-fms-service\target\classes\bootstrap-local-uat.yml:26:# http://127.0.0.1:9203/actuator/nacos-discovery
D:\Code_fix\ygp-bciscm-fms\bciscm-fms-service\target\classes\bootstrap-local-test1.yml:26:# http://127.0.0.1:9203/actuator/nacos-discovery
D:\Code_fix\ygp-bciscm-fms\bciscm-fms-service\target\classes\bootstrap-local-dev1.yml:30:# http://127.0.0.1:9203/actuator/nacos-discovery
D:\Code_fix\ygp-bciscm-fms\bciscm-fms-service\src\main\resources\bootstrap-local-test1.yml:26:# http://127.0.0.1:9203/actuator/nacos-discovery
D:\Code_fix\ygp-bciscm-fms\bciscm-fms-service\src\main\resources\bootstrap-local-dev1.yml:30:# http://127.0.0.1:9203/actuator/nacos-discovery
D:\Code_fix\ygp-bciscm-fms\bciscm-fms-service\src\main\resources\bootstrap-local-uat.yml:26:# http://127.0.0.1:9203/actuator/nacos-discovery
\\

3. Read tool — works correctly

OpenCode's \Read\ tool on individual files shows the content with \9203\ without issue.

Key Observation

The Grep tool fails to find matches even in \src/main/resources/*.yml\ source files — files that are NOT covered by .gitignore. The .gitignore\ only excludes \ arget/, .idea/, *.iml, \logs/, /data/.

This rules out .gitignore\ as the sole cause. The pattern exists in tracked, non-ignored source files.

Suspected Root Cause

The workspace root (\D:\Code_fix) is not a git repository, but each subdirectory is. The Grep tool likely uses git-aware file traversal (like
g's default behavior) which depends on finding a .git/\ at or above the search root. When the root isn't a git repo:

  1. The tool may skip all files because it can't determine the git boundary
  2. Or it may apply incorrect ignore rules from the wrong directory level
  3. Or the file-walking logic has an edge case for nested git repos without a parent repo

Expected Behavior

The Grep tool should search all files in the specified \path, regardless of whether the workspace root is a git repository. At minimum, it should find matches in source files under \src/main/resources/.

Workaround

  • Use \Read\ tool to directly read known files
  • Use \Bash\ tool to run
    g\ directly (but this defeats the purpose of having a built-in Grep tool)
  • Use \Glob\ tool to find files first, then \Read\ them

Impact

This causes silent data loss — the AI agent receives empty search results and incorrectly concludes the pattern doesn't exist, leading to wrong answers. In this specific case, it caused the agent to repeatedly claim "port 9203 is not in the codebase, it must be in Nacos" when the port was clearly documented in local config files.

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)windows

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions