[BUG] Claude CLI Runs Ripgrep across whole working directory, even when prompted with a simple -p prompt

Resolved 💬 3 comments Opened Sep 3, 2025 by ejc3 Closed Jan 5, 2026

Environment

  • Claude CLI Version: 1.0.95
  • Platform: Linux x64
  • Ripgrep: Bundled version at /usr/lib/node_modules/@anthropic-ai/claude-code/vendor/ripgrep/x64-linux/rg
  • Working Directory: Large codebase (e.g., fbsource or similar)

Problem Description

Claude CLI unnecessarily runs ripgrep on claude invocation (even simple prompts like claude -p 'hello'), potentially scanning thousands of files and causing crashes with ABORT_ERR, significantly slowing down command execution.

Root Cause

The CLI is designed to scan the entire directory with ripgrep on every claude execution, regardless of whether code context is needed. In large directories, this leads to ripgrep processing thousands of files and crashing with ABORT_ERR.

Reproduction Steps

  1. Navigate to a large codebase directory:

``bash
cd /path/to/large/codebase # e.g., fbsource, linux kernel, etc.
``

  1. Run even a simple prompt that doesn't need code context:

``bash
claude -p 'hello' # Just a simple greeting, no code context needed
``

  1. Verify ripgrep is still running on all files using debug mode:

``bash
claude --model 'sonnet' -p 'hello' --debug 2>&1 | grep -E "(rg|ripgrep)"
``

  1. Observe the ripgrep unnecessarily scanning 27k+ files and crashing

Expected vs Actual Behavior

Expected: CLI should only perform ripgrep scanning when code context is actually needed for the command
Actual: CLI runs ripgrep on EVERY command, even simple prompts like claude -p 'hello', unnecessarily scanning thousands of files

Evidence

Debug Output Shows Ripgrep Crash

[DEBUG] Ripgrep first use test: PASSED (mode=builtin, path=/usr/lib/node_modules/@anthropic-ai/claude-code/vendor/ripgrep/x64-linux/rg)
[DEBUG] rg error (signal=undefined, code=ABORT_ERR, stderr: ), 27793 results

Performance Impact

The ripgrep crash adds overhead to CLI initialization:

  • Extra error handling
  • Potential fallback mechanisms
  • Processing of thousands of results before crash

Environment Details

$ /usr/lib/node_modules/@anthropic-ai/claude-code/vendor/ripgrep/x64-linux/rg --version
# Version info of bundled ripgrep

$ pwd
/home/ejc3  # Large directory with many files

Reproduction in Different Environments

Fast Environment (small directory):

cd /tmp
claude --model 'sonnet' -p 'hello' --debug  # No ripgrep error

Slow Environment (large directory):

cd /path/to/large/codebase
claude --model 'sonnet' -p 'hello' --debug  # Shows ripgrep ABORT_ERR

Impact

  • Contributes to overall CLI slowness in large codebases
  • Error handling overhead during initialization
  • Potential memory/resource waste processing large result sets

Suggested Fixes

  1. Only run ripgrep when needed - don't scan files for simple text prompts that don't require code context
  2. Add command flag to control scanning - e.g., --no-scan to disable ripgrep completely
  3. Implement smart detection - determine if code context is needed based on the prompt
  4. Add result limit - prevent processing excessive results in large codebases
  5. Add proper directory size detection - warn or avoid scanning when directory has too many files

Workaround

Move to smaller directory or disable ripgrep if possible:

cd /tmp  # Work from smaller directory
# OR
CLAUDE_CODE_ENABLE_RIPGREP=0 claude --model 'sonnet' -p 'hello'  # If this env var exists

View original on GitHub ↗

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