Skip to content

Instantly share code, notes, and snippets.

@wilhelmklopp
Created January 11, 2026 00:37
Show Gist options
  • Select an option

  • Save wilhelmklopp/8462b27011d73ee6a77a2575d10627f4 to your computer and use it in GitHub Desktop.

Select an option

Save wilhelmklopp/8462b27011d73ee6a77a2575d10627f4 to your computer and use it in GitHub Desktop.

Making Files Gitignored but Searchable by Claude Code

The Problem

You have files (logs, traces, generated output) that should be:

  • Ignored by git - they shouldn't be committed
  • Searchable by Claude Code - so the AI can find and use them

By default, Claude Code's search respects .gitignore, so gitignored files are invisible to search.

The Solution

ripgrep (which powers Claude Code's Grep tool) supports .ignore files that take precedence over .gitignore. Use negation patterns (!) to override gitignore rules.

In your directory, create two files:

your-directory/
├── .gitignore    # Contains: *
├── .ignore       # Contains: !*
└── ... (your files)
File Content Effect
.gitignore * Git ignores all files in this directory
.ignore !* ripgrep un-ignores them, making them searchable

Why This Works

ripgrep's ignore precedence (highest to lowest):

  1. .ignore files
  2. .rgignore files
  3. .gitignore files

The ! prefix negates a pattern. So !* in .ignore overrides * in .gitignore for ripgrep, while git only sees its own .gitignore.

Benefits

  • Zero configuration - no Claude Code or VS Code settings changes needed
  • Self-contained - the solution lives entirely within the directory
  • Works with nested directories - each directory can have its own rules
  • Standard ripgrep behavior - not Claude-specific, works with any ripgrep-based tool

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment