Claude Code's Grep tool should use --no-require-git for non-git repos that still use .gitignore files

Resolved 💬 5 comments Opened Oct 12, 2025 by ejc3 Closed Jan 12, 2026

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:

  1. Mercurial repositories that use .gitignore files
  2. Git repositories that have been archived/copied without .git directory
  3. Perforce repositories using .gitignore files
  4. 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

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗