Claude Code's Grep tool should use --no-require-git for non-git repos that still use .gitignore files
Problem
Claude Code's Grep tool doesn't respect .gitignore files in Mercurial repositories because ripgrep by default only honors .gitignore when a .git directory is present.
This causes large amounts of unwanted results from directories like node_modules/, vendor/, dist/, etc. that would normally be filtered by .gitignore patterns.
Impact
In large monorepos (like Meta's fbsource which uses Mercurial) that uses .gitignore files, Grep searches return massive results from ignored directories:
- Searches that should return ~10 files return 1000+ files
- Search results include minified JavaScript, build artifacts, vendored code
- This significantly impacts usability and performance
Root Cause
Ripgrep's default behavior requires a .git directory to respect .gitignore files. From the ripgrep documentation:
By default, ripgrep will only respect filter rules from source control ignore files when ripgrep detects that the search is executed inside a source control repository. For example, when a .git directory is observed.
Mercurial uses .hg directories, not .git, so .gitignore files are ignored.
Solution
Ripgrep added the --no-require-git flag specifically for this use case (see ripgrep#1414).
From ripgrep's help:
--no-require-git
When this flag is given, source control ignore files such as .gitignore
are respected even if no git repository is present.
Claude Code should pass --no-require-git when invoking ripgrep to support:
- Mercurial repositories that use
.gitignorefiles - Git repositories that have been archived/copied without
.gitdirectory - Perforce repositories using
.gitignorefiles - Any repository structure using
.gitignorefor filtering
Workaround
Users can create a .rgignore file at the repository root with the same patterns as .gitignore. Ripgrep always respects .rgignore files regardless of repository type.
However, this requires duplicating ignore rules and isn't a sustainable solution for large repositories with many .gitignore files.
Implementation
The fix should be straightforward - add --no-require-git to the ripgrep invocation in Claude Code's Grep tool.
Environment
- Claude Code version: 2.0.13
- Bundled ripgrep version: 14.1.1
- Repository type: Mercurial (
.hg) - Uses
.gitignorefiles: Yes
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗