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.

ReportWhat it coversState
Claude Code: invalid UTF-8 files skippedthe encoding skip measured hereopen, filed 2026-11-11
ugrep: nested negated ignore rulethe Linux perf_dlfilter.h caseopen, filed 2026-11-11
claude-code#102875ignore rules that differ from git; my nested-negation caseopen
claude-code#84161silent .gitignore skippingclosed as not planned (inactivity), still reproducible in 2.1.322
claude-code#56644NUL-byte files skippedclosed as not planned
claude-code#69736request for an opt-out of the shimsopen

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:

  • -I skips 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-files skips anything matched by .gitignore files, 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 matchClaude Code grepGNU grep 3.11macOS grep 2.6.0 (BSD)bundled rg
plain UTF-8foundfoundfoundfound
Latin-1 byte in a C commentmissedfoundfoundfound
Windows-1252 quotes on the matching linemissedfoundmissedfound
one invalid byte after 200 KB of textmissedfoundfoundfound
UTF-16 with BOMfoundmissedmissedfound
NUL byte in the filemissedsays binary file matchessays Binary file … matchesmissed
hidden filefoundfoundfoundmissed
directory listed in .gitignoremissedfoundfoundmissed inside a repo
*.log listed in .gitignoremissedfoundfoundmissed 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.

RepositoryText filesSkipped: not valid UTF-8of which source-like extensionSkipped: matched an ignore rule
vim8,5851731195
php-src28,20120366
emacs5,19678118
perl57,00857404
postgres7,72857221
node55,873383418
ruby11,798262513
cpython5,42819170
openssl5,9641600
git4,83611100
linux97,197202
curl4,565001
Total242,37968028458

“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 -rna when 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. -U is close but not complete: 679 of 680, missing a Shift-JIS file that ends in a truncated multibyte character.
  • Add --no-ignore-files when generated, vendored or re-included paths matter. With -a as well, it recovered every planted match in the nine-file test.
  • command grep reaches the system grep. On macOS that is BSD grep, which has its own gaps (see the table).
  • Per the changelog, listing Grep and Glob explicitly in --tools restores 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 grep is 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.