Skip to content

Grep

The Grep tool searches file contents using regular expression pattern matching. It is similar to the Unix grep command but optimized for use by the AI.

  • Searches one or more files for lines matching a pattern
  • Supports regular expressions
  • Returns matching lines with file paths and line numbers
  • Can search recursively through directories

The AI uses Grep when:

  • It needs to find all usages of a function, variable, or symbol across a codebase
  • You ask it to locate specific content in files
  • It’s exploring a project and needs to understand how pieces connect

“Find all places in this project where the authenticate function is called.”

The AI will run a Grep search for authenticate across the relevant source files and report all occurrences with their file paths and line numbers.

  • Grep is most effective when combined with Glob — Glob finds files, Grep searches within them
  • For simple file searches, Glob alone is faster
  • Regular expression patterns give precise control over what’s matched