[FEATURE]: Intercept known Bash tool call patterns and replace them with specialized tools #7607

Open
opened 2026-02-16 18:07:42 -05:00 by yindo · 1 comment
Owner

Originally created by @smola on GitHub (Jan 26, 2026).

Originally assigned to: @thdxr on GitHub.

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Some models tend to prefer exploring the code base with direct bash tool calls instead of using Grep/Glob. gemini-3-pro-preview is a particularly bad case (see https://github.com/anomalyco/opencode/issues/10438), but also happens with others like claude-opus-4.5.

While system prompts and tool descriptions should be improved to mitigate this behavior, in many cases these calls to Bash follow easily recognizable patterns with an equivalent in specialized tools. OpenCode could intercept those and replace the tool call on the fly.

The benefits of doing so:

  • Appropriate exclusion of git dir from searches, and other features of the specialized tools.
  • Less permission requests: many read-only operations will be allowed without the need of adding a rule for each of these Bash commands.
  • Read/Write timestamp detection: if an agent issues a cat $file, it will be detected as a Read, and so tools like Edit will not fail because the file has not been read before writing it.

Here's some candidates:

cat $file -> read($file)
head $file -> read($file, range)
tail $file -> read($file, range)
grep -r $pat $file -> grep(pattern=$pat, $file)  # probably needs verification that the pattern is compatible
find -name '*.py' -> glob(pattern='**/*.py')
...

Ideally, this would have the following behaviors:

  • Replacement happens before permission checks, so that the permission prompt is for the tool that actually runs.
  • Output has an indication of the replacement (e.g. <tool_metadata>Tool call bash(command="cat foo") was automatically replaced by tool call read(path="foo")</tool_metadata>). This warns the LLM of why the output format is different than expected, and also should steer it towards using he specialized tools directly later in the session.

The main edge case that should be taken care of is how to let the LLM really pick grep or find in a case that would be replaced, but there's really a requirement to run the plain tools (e.g. the LLM really really needs to grep within .git.

Originally created by @smola on GitHub (Jan 26, 2026). Originally assigned to: @thdxr on GitHub. ### Feature hasn't been suggested before. - [x] I have verified this feature I'm about to request hasn't been suggested before. ### Describe the enhancement you want to request Some models tend to prefer exploring the code base with direct bash tool calls instead of using Grep/Glob. `gemini-3-pro-preview` is a particularly bad case (see https://github.com/anomalyco/opencode/issues/10438), but also happens with others like `claude-opus-4.5`. While system prompts and tool descriptions should be improved to mitigate this behavior, in many cases these calls to Bash follow easily recognizable patterns with an equivalent in specialized tools. OpenCode could intercept those and replace the tool call on the fly. The benefits of doing so: * Appropriate exclusion of git dir from searches, and other features of the specialized tools. * Less permission requests: many read-only operations will be allowed without the need of adding a rule for each of these Bash commands. * Read/Write timestamp detection: if an agent issues a `cat $file`, it will be detected as a Read, and so tools like Edit will not fail because the file has not been read before writing it. Here's some candidates: ``` cat $file -> read($file) head $file -> read($file, range) tail $file -> read($file, range) grep -r $pat $file -> grep(pattern=$pat, $file) # probably needs verification that the pattern is compatible find -name '*.py' -> glob(pattern='**/*.py') ... ``` Ideally, this would have the following behaviors: - Replacement happens before permission checks, so that the permission prompt is for the tool that actually runs. - Output has an indication of the replacement (e.g. `<tool_metadata>Tool call bash(command="cat foo") was automatically replaced by tool call read(path="foo")</tool_metadata>`). This warns the LLM of why the output format is different than expected, and also should steer it towards using he specialized tools directly later in the session. The main edge case that should be taken care of is how to let the LLM really pick `grep` or `find` in a case that would be replaced, but there's really a requirement to run the plain tools (e.g. the LLM really really needs to grep within `.git`.
yindo added the discussion label 2026-02-16 18:07:42 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 26, 2026):

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

  • #10438: gemini-3-pro-preview in opencode tends to avoid grep/glob (possible system prompt issue)

Feel free to ignore if this doesn't address your specific case.

@github-actions[bot] commented on GitHub (Jan 26, 2026): This issue might be a duplicate of existing issues. Please check: - #10438: gemini-3-pro-preview in opencode tends to avoid grep/glob (possible system prompt issue) Feel free to ignore if this doesn't address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7607