Skip to content

code_grep

code_grep searches the indexed codebase by regex pattern and returns matching lines with file and line number context. Faster and more token-efficient than shell grep because it operates on the indexed graph, not raw disk files.

code_grep(pattern="TODO")
code_grep(pattern="stripe\.charges\.create")
code_grep(pattern="process\.env\.[A-Z_]+", max_results=10)
code_grep(pattern="deprecated", path="src/api")
ParameterTypeDefaultDescription
patternstringrequiredRegex pattern to search for
pathstringLimit search to files matching this path
max_resultsnumber20Cap on returned matches
You wantUse
Find all TODO commentscode_grep(pattern="TODO")
Find all process.env readscode_grep(pattern="process\.env\.")
Find usages of a string literalcode_grep(pattern="stripe_secret")
Find a function by name patterncode_search(query="...") instead
  • Results are ranked: definitions appear before usages
  • Use max_results to keep context small when you only need a few examples
  • For finding symbols by name, code_search is more precise
  • For understanding all code connected to a symbol, prefer code_context or code_related