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
.gitignore files
- Git repositories that have been archived/copied without
.git directory
- Perforce repositories using
.gitignore files
- Any repository structure using
.gitignore for 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
.gitignore files: Yes
Problem
Claude Code's Grep tool doesn't respect
.gitignorefiles in Mercurial repositories because ripgrep by default only honors.gitignorewhen a.gitdirectory is present.This causes large amounts of unwanted results from directories like
node_modules/,vendor/,dist/, etc. that would normally be filtered by.gitignorepatterns.Impact
In large monorepos (like Meta's fbsource which uses Mercurial) that uses .gitignore files, Grep searches return massive results from ignored directories:
Root Cause
Ripgrep's default behavior requires a
.gitdirectory to respect.gitignorefiles. From the ripgrep documentation:Mercurial uses
.hgdirectories, not.git, so.gitignorefiles are ignored.Solution
Ripgrep added the
--no-require-gitflag specifically for this use case (see ripgrep#1414).From ripgrep's help:
Claude Code should pass
--no-require-gitwhen invoking ripgrep to support:.gitignorefiles.gitdirectory.gitignorefiles.gitignorefor filteringWorkaround
Users can create a
.rgignorefile at the repository root with the same patterns as.gitignore. Ripgrep always respects.rgignorefiles regardless of repository type.However, this requires duplicating ignore rules and isn't a sustainable solution for large repositories with many
.gitignorefiles.Implementation
The fix should be straightforward - add
--no-require-gitto the ripgrep invocation in Claude Code's Grep tool.Environment
.hg).gitignorefiles: Yes