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")
Parameter Type Default Description patternstring required Regex pattern to search for pathstring — Limit search to files matching this path max_resultsnumber 20 Cap on returned matches
You want Use Find all TODO comments code_grep(pattern="TODO")Find all process.env reads code_grep(pattern="process\.env\.")Find usages of a string literal code_grep(pattern="stripe_secret")Find a function by name pattern code_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