[BUG] Grep tool returns 0 matches when bash grep finds 314 matches
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
The Grep tool returns 0 matches (or drastically fewer matches) compared to equivalent bash grep commands on the same directory and pattern.
When searching for TODO|FIXME in ~/.claude/hooks:
- Grep tool: 0 matches
- Bash grep: 314 matches
The Grep tool appears to be silently excluding files or directories that bash grep includes.
What Should Happen?
The Grep tool should return results consistent with grep -r "pattern" path or clearly document what exclusions are applied (e.g., respecting .gitignore, excluding certain directories).
Error Messages/Logs
# Grep tool result:
No matches found
Found 0 total occurrences across 0 files.
# Bash grep result (same pattern, same path):
$ grep -r "TODO\|FIXME" ~/.claude/hooks --include="*.py" --include="*.sh" --include="*.md" | wc -l
314
Steps to Reproduce
- Have a directory with Python/shell files containing TODO comments (e.g.,
~/.claude/hookswith test files)
- Run the Grep tool:
Grep(
pattern="TODO|FIXME",
path="/Users/user/.claude/hooks",
output_mode="count"
)
Result: No matches found. Found 0 total occurrences across 0 files.
- Run equivalent bash grep:
grep -r "TODO\|FIXME" /Users/user/.claude/hooks --include="*.py" --include="*.sh" --include="*.md" | wc -l
Result: 314
- Even simpler reproduction - first grep returns only 1 match (a filename in CLAUDE.md), not the 287+ actual TODO comments in the codebase:
Grep(
pattern="TODO|FIXME",
path="/Users/user/.claude/hooks",
output_mode="content",
"-i": true,
"-n": true
)
Result: Only 1 match from CLAUDE.md:139 (a filename reference), missing 300+ actual matches.
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.1
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
Session ID: 7530b6cc-afad-416a-ab26-6a15dc577600
The session shows Claude correctly using the Grep tool but receiving incomplete data:
{
"pattern": "TODO|FIXME",
"path": "/Users/user/.claude/hooks",
"output_mode": "content",
"-i": true,
"-n": true
}
Tool returned only 1 match (a filename in documentation), leading Claude to incorrectly conclude "0 TODOs need attention" when the actual count is 314.
Hypothesis
The Grep tool may be:
- Respecting .gitignore patterns more aggressively than expected
- Excluding
tests/,mutants/, or other directories by default - Having issues with the
|OR pattern in regex - Limiting results in a way that's not documented
Impact
This causes Claude to make incorrect conclusions about codebases when using the Grep tool for analysis tasks. Users asking "how many TODOs are in my project?" will get wrong answers.
Workaround
Use bash grep instead of the Grep tool:
grep -rn "TODO\|FIXME" /path/to/project --include="*.py"This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗