Ask Claude Code to grep -rn your repository and it will answer. The answer is not always grep’s answer.
Since version 2.1.117, Claude Code’s native builds for macOS and Linux run nearly every shell grep (a few flags such as -Z fall through to the system grep) through a bundled copy of ugrep with extra flags. Those flags make it skip some files that GNU grep would search, and it says nothing when it does. For a person that is a quirk. For an agent that treats “no match” as a fact, it is a blind spot.
Everything below was measured on 2026-11-11 with Claude Code 2.1.322 on an Apple Silicon Mac. I did not test a Linux build; what I say about Linux comes from the changelog. The scripts are in the reproduction repo.
Status (last checked 2026-11-11)
I will update this section as the reports below change. If a fix ships, the post will say which version.
| Report | What it covers | State |
|---|---|---|
| Claude Code: invalid UTF-8 files skipped | the encoding skip measured here | open, filed 2026-11-11 |
| ugrep: nested negated ignore rule | the Linux perf_dlfilter.h case | open, filed 2026-11-11 |
| claude-code#102875 | ignore rules that differ from git; my nested-negation case | open |
| claude-code#84161 | silent .gitignore skipping | closed as not planned (inactivity), still reproducible in 2.1.322 |
| claude-code#56644 | NUL-byte files skipped | closed as not planned |
| claude-code#69736 | request for an opt-out of the shims | open |
Other people found parts of this first: the NUL-byte skip (#56644), the silent .gitignore filtering (#84161) and ignore rules that disagree with git (#102875, whose reporter also noticed that a partial result with exit 0 is worse than an empty one). What this post adds is the invalid-UTF-8 case, the nested-negation case, and measurements across four tools and twelve large repositories.
What grep is inside Claude Code
Claude Code builds a shell snapshot for its Bash tool. On native macOS and Linux builds that snapshot contains this, under the comment # Shadow find/grep with embedded bfs/ugrep (abridged):
function grep {
...
ARGV0=ugrep "$_cc_bin" -G --ignore-files --hidden -I \
--exclude-dir=.git --exclude-dir=.svn --exclude-dir=.hg \
--exclude-dir=.bzr --exclude-dir=.jj --exclude-dir=.sl "$@"
}
find is shadowed the same way by a bundled bfs, and rg by a bundled ripgrep. The changelog entry for 2.1.117 says why: “Native builds on macOS and Linux: the Glob and Grep tools are replaced by embedded bfs and ugrep available through the Bash tool”, for faster searches without a separate tool round-trip; Windows and npm-installed builds are unchanged. So on those builds this wrapper is how the agent searches code.
Two of the flags change what gets searched:
-Iskips binary files. ugrep’s own help defines binary broadly: “Files having NUL (zero) bytes are binary. Also files with invalid UTF encoding are binary unless option -U or –ascii or –binary is specified.” A C file with one Latin-1 byte in a comment is “binary”.--ignore-filesskips anything matched by.gitignorefiles, whether or not you are in a git repository, and whether or not git actually tracks the file.
Neither prints anything when it skips a file.
A nine-file test
I planted the same kind of identifier in nine files, each exercising one failure mode, and searched recursively with four tools.
| Planted match | Claude Code grep | GNU grep 3.11 | macOS grep 2.6.0 (BSD) | bundled rg |
|---|---|---|---|---|
| plain UTF-8 | found | found | found | found |
| Latin-1 byte in a C comment | missed | found | found | found |
| Windows-1252 quotes on the matching line | missed | found | missed | found |
| one invalid byte after 200 KB of text | missed | found | found | found |
| UTF-16 with BOM | found | missed | missed | found |
| NUL byte in the file | missed | says binary file matches | says Binary file … matches | missed |
| hidden file | found | found | found | missed |
directory listed in .gitignore | missed | found | found | missed inside a repo |
*.log listed in .gitignore | missed | found | found | missed inside a repo |
Every tool has gaps, and they are different gaps. GNU grep’s only silent miss here is UTF-16. The wrapper misses six of nine and never says so. A whole file disappears because of one byte, even when that byte is 200 KB away from the match.
None of this is wrong by itself. Skipping binaries and ignored build output is usually what you want, and it saves an agent tokens. The problem is the name. A model that has read a decade of Stack Overflow knows what grep does. This is not that grep, and nothing in its output tells the model so.
How often does it bite?
I downloaded the default-branch source of 12 large projects, ran the wrapper’s exact command (ugrep with the same flags, -rl '') from each repository root, and classified every non-empty file it did not search. Then I re-checked every skipped file against a second listing with the recovering flag added, so a path-formatting quirk could not pass for a skip: all 680 encoding skips reappear with -a (679 with -U), and all 58 ignore-rule skips reappear without --ignore-files.
| Repository | Text files | Skipped: not valid UTF-8 | of which source-like extension | Skipped: matched an ignore rule |
|---|---|---|---|---|
| vim | 8,585 | 173 | 119 | 5 |
| php-src | 28,201 | 203 | 6 | 6 |
| emacs | 5,196 | 78 | 11 | 8 |
| perl5 | 7,008 | 57 | 40 | 4 |
| postgres | 7,728 | 57 | 22 | 1 |
| node | 55,873 | 38 | 34 | 18 |
| ruby | 11,798 | 26 | 25 | 13 |
| cpython | 5,428 | 19 | 17 | 0 |
| openssl | 5,964 | 16 | 0 | 0 |
| git | 4,836 | 11 | 10 | 0 |
| linux | 97,197 | 2 | 0 | 2 |
| curl | 4,565 | 0 | 0 | 1 |
| Total | 242,379 | 680 | 284 | 58 |
“Text files” means no NUL byte. “Source-like” is a fixed extension list in the repo (.c, .py, .rb, .pl, .vim, .el and similar); php-src’s 169 skipped .phpt test files are not on it, so its count is low. A handful of invalid-UTF-8 files were searched anyway, so ugrep’s test is not literally “any invalid byte”.
Overall that is 0.28% of text files. Small, and concentrated where you would expect: encoding tests, translations, spell files, legacy comments. Emacs’s lisp/language/ethiopic.el and tibetan.el, Vim’s runtime scripts, CPython’s Lib/test/encoded_modules/module_koi8_r.py, PostgreSQL’s KOI8-R locale tests. Those are exactly the files you need when the bug is about encodings.
The worst case: a definition that vanishes
The 58 ignore-rule skips hide the sharpest problem. In the Linux kernel, tools/perf/.gitignore contains:
perf
!include/perf/
The first line ignores the built perf binary; the second re-includes the public header directory. Git tracks tools/perf/include/perf/perf_dlfilter.h, which holds the real definition of struct perf_dlfilter_fns.
Search for that definition from the repository root:
$ grep -rln 'struct perf_dlfilter_fns {' . # inside Claude Code
tools/perf/Documentation/perf-dlfilter.txt
tools/perf/dlfilters/dlfilter-test-api-v0.c
tools/perf/dlfilters/dlfilter-test-api-v2.c
$ /usr/bin/grep -rln 'struct perf_dlfilter_fns {' tools
tools/perf/Documentation/perf-dlfilter.txt
tools/perf/dlfilters/dlfilter-test-api-v0.c
tools/perf/dlfilters/dlfilter-test-api-v2.c
tools/perf/include/perf/perf_dlfilter.h
Exit status 0, three plausible hits, and the canonical header missing. Start the same search from tools/perf/ and the header appears. The re-include rule is only honoured when the search starts in the directory that owns it.
That is worse than a “not found”. An agent that gets three results has no reason to doubt them; it will read a documentation copy or a test fixture and treat it as the API.
The cause is in ugrep, not in Claude Code: upstream ugrep 7.8.5 behaves the same. A two-file reproduction:
mkdir -p sub/include/perf
printf 'perf\n!include/perf/\n' > sub/.gitignore
echo needle > sub/include/perf/api.h
echo needle > sub/other.c
ugrep --ignore-files -rl needle . # sub/other.c only
(cd sub && ugrep --ignore-files -rl needle .) # both files
Claude Code turns --ignore-files on for every search, so the bug reaches every agent session on those builds.
What to do
If you use Claude Code on macOS or Linux:
- Ask for
grep -rnawhen encodings might matter.-a(search binary files as text) brought back all 680 encoding skips in the survey and, in the nine-file test, the NUL-byte file too.-Uis close but not complete: 679 of 680, missing a Shift-JIS file that ends in a truncated multibyte character. - Add
--no-ignore-fileswhen generated, vendored or re-included paths matter. With-aas well, it recovered every planted match in the nine-file test. command grepreaches the system grep. On macOS that is BSD grep, which has its own gaps (see the table).- Per the changelog, listing
GrepandGlobexplicitly in--toolsrestores the dedicated search tools on native builds.
If you build agent tooling:
- Don’t give a different tool a standard command’s name. A model’s prior about
grepis strong and specific. - When a search skips files, say so in one line on stderr, with a count. Silence is the bug; skipping is a choice.
- Results from a recursive search should not depend on the starting directory when the tracked files are the same.
Reproduce it
Reproduction repo: github.com/bsbhadwal/claude-code-grep-survey. It contains the corpus generator, the 12-repository survey, the Linux case and the two-file ugrep reproduction. Versions: Claude Code 2.1.322 with bundled ugrep 7.8.4; upstream ugrep 7.8.5 (Debian testing); GNU grep 3.11 (Debian stable); BSD grep 2.6.0 (macOS). Source trees were the projects’ default branches on 2026-11-11.
Corrections
- 2026-11-11, about an hour after publishing: re-checking every skipped file one by one changed two things. The ignore-rule count is 58, not 60 (two files I had counted contain only a byte-order mark, which an empty pattern cannot match). And
-a, not-U, is the flag that recovers every encoding skip. The other figures were confirmed.
Reported to: Claude Code and ugrep; the Status section at the top tracks them, along with the Claude Code issue tracker.
