Repository navigation
Add optional literal search mode to the grep tool #38
Description
Problem
The grep tool always treats pattern as a Go regular expression. Searching for ordinary code such as func( fails with a regex error, while strings such as config.json can match unintended text because . is a wildcard. The agent must escape regex metacharacters correctly or fall back to a shell command for a simple literal search.
Proposed improvement
Add an optional boolean fixed_strings argument to grep. When true, treat the entire pattern as literal text, equivalent to grep -F. Keep regex matching as the default.
For example, this should find a literal func( in Go files without requiring regex escaping:
{"pattern":"func(","path":".","include":"*.go","fixed_strings":true}Acceptance criteria
- The tool schema exposes
fixed_stringsas an optional boolean and explains that the default is regex matching. Update the tool and pattern descriptions to make literal mode discoverable. - With
fixed_strings: true, metacharacters such as.,(,[,*, and backslashes are matched literally. For example,config.jsonmatches that exact substring but notconfigXjson;func(is a valid literal search. - Omitted, false, or null values preserve existing regex behavior, including inline regex flags and invalid-regex errors. Invalid non-boolean values return an actionable tool error using the existing
boolArgconvention. - Literal mode works for both single-file and recursive searches and combines with the existing
includeglob. Preserve path confinement, skipped directories, binary/large-file exclusions, match limits,file:line: contentoutput, and theno matchesresponse. - Add focused tests for literal metacharacters, the default regex behavior, single-file and recursive/include searches, executor argument validation, and the optional boolean schema property.
go test ./...passes. - Add a brief README note showing a literal search example.
Implementation pointers and scope
The change should fit within internal/tools/grep.go, the argument/schema/dispatch handling in internal/tools/tools.go, existing tests in internal/tools/tools_test.go, and README.md. Quoting the supplied pattern with regexp.QuoteMeta in literal mode would allow reuse of the existing search loop. No new dependency or CLI flag is needed.
This is separate from #36 (ignore_case): that issue changes case sensitivity; this one changes how regex syntax is interpreted. It does not depend on #36 being implemented.
Activity
vicgupta commentedon Oct 24, 2026
amf opened #46 for this issue.
Fix #38: Add optional literal search mode to the grep tool
vicgupta commentedon Oct 24, 2026
amf opened #48 for this issue.
Fix #38: Add optional literal search mode to the grep tool (#48)