unified_search (grep action) Quick Reference Card

June 27, 2026 ยท View on GitHub

Note: grep_file is now an internal implementation. Use unified_search with action="grep" as the canonical tool.

Essential Parameters

{
  "pattern": "TODO",           // Required: regex or literal string
  "path": "src",               // Directory to search (default: ".")
  "max_results": 50,           // Results limit (default: 100, max: 1000)
  "glob_pattern": "**/*.rs",   // Filter files: **/*.rs, src/**/*.ts, etc.
  "type_pattern": "rust",      // Language: rust, python, typescript, java, go
  "context_lines": 3,          // Lines around match (0-20, default: 0)
  "literal": false,            // false=regex (default), true=literal string
  "case_sensitive": false      // false=smart-case (default), true=case-sensitive
}

Common Search Patterns

TaskPatternGlobNotes
Find functions^(pub )?fn \w+\(**/*.rsRust function definitions
Find imports^import.*from**/*.tsTypeScript/JS imports
Find classes^class \w+**/*.javaJava class definitions
Find TODOsTODO|FIXME**/*.rsCommon markers
Find errorspanic!|unwrap|throw**/*.rsError patterns
Find API calls\.get\(|\.post\(**/*.tsHTTP verbs
Find exports^export **/*.tsModule exports
Find configconfig\.**/*.pyConfig references
Find asyncasync fn**/*.rsAsync functions
Find unused^pub fn**/*.rsPublic functions (for refactoring)

Smart Patterns by Language

Rust

{"pattern": "^fn \\w+", "type_pattern": "rust"}
{"pattern": "impl \\w+", "type_pattern": "rust"}
{"pattern": "#\\[test\\]", "context_lines": 1}
{"pattern": "Result<|Option<", "type_pattern": "rust"}

TypeScript

{"pattern": "^export (function|const|class)", "glob": "**/*.ts"}
{"pattern": "interface \\w+", "glob": "**/*.ts"}
{"pattern": "async \\(", "glob": "**/*.tsx"}
{"pattern": "useState|useEffect|useContext", "glob": "**/*.tsx"}

Python

{"pattern": "^def \\w+", "type_pattern": "python"}
{"pattern": "^class \\w+", "type_pattern": "python"}
{"pattern": "import |from .* import", "type_pattern": "python"}
{"pattern": "@property|@staticmethod", "context_lines": 2}

Performance Tips

OptimizationBenefitExample
Use glob_pattern10-100x fasterglob: "**/*.rs"
Use type_pattern5-10x fastertype_pattern: "rust"
Set max_file_sizeSkip large filesmax_file_size: 5242880
Keep respect_ignore_files: trueSkip node_modules, build(default)
Reduce context_linesSmaller outputcontext_lines: 0
Use literal: trueFaster for exact stringsliteral: true

Output Example

{
  "success": true,
  "query": "TODO",
  "matches": [
    {
      "type": "match",
      "data": {
        "path": {"text": "src/main.rs"},
        "line_number": 42,
        "lines": {"text": "// TODO: refactor this function\n"}
      }
    }
  ]
}

Real-World Examples

Refactor: Replace old import

{
  "pattern": "^import.*OldLib",
  "glob": "src/**/*.ts",
  "files_with_matches": true
}

Result: All files needing import updates

Audit: Find hardcoded secrets

{
  "pattern": "password|api.key|token",
  "case_sensitive": false,
  "glob": "src/**/*.{ts,js,py}",
  "context_lines": 1
}

Refactor: Identify deprecated API

{
  "pattern": "\\.oldMethod\\(",
  "glob": "src/**/*.{ts,tsx}",
  "max_results": 500
}

Analysis: Find error handling patterns

{
  "pattern": "try\\s*{|catch\\s*\\(|throw ",
  "type_pattern": "typescript",
  "context_lines": 2
}

Regex Cheat Sheet

PatternMatches
.Any character
\wWord character [a-zA-Z0-9_]
\dDigit [0-9]
\sWhitespace
^Line start
$Line end
|OR (escaped in JSON)
(...)Group
*0 or more
+1 or more
?0 or 1
[...]Character class

In JSON, escape backslashes: \\w, \\d, \\s

Decision Tree

What do you want to find?

 Functions/Classes?
   Rust: ^(pub )?fn \w+|^pub struct
   Python: ^def |^class 
   TypeScript: ^export (function|class)

 Imports/Exports?
   TypeScript/JS: ^import|^export
   Python: ^import |^from

 Error handling?
   Rust: panic!|unwrap|Result
   JS/TS: try|catch|throw
   Python: try|except|raise

 TODOs/Comments?
   (TODO|FIXME|HACK|XXX)

 API/Database?
   HTTP: \.get\(|\.post\(|\.put\(
   SQL: SELECT|INSERT|UPDATE

 Config/Constants?
    config\.|process.env|os.getenv

Common Mistakes

WrongRightWhy
pattern: "fn test"pattern: "^fn test"Anchor patterns to line start
glob_pattern: "*.rs"glob_pattern: "**/*.rs"Use ** for recursive
pattern: "my.variable"pattern: "my\.variable"Escape special chars
No glob + huge searchglob: "src/**/*.ts"Always narrow scope
context_lines: 50context_lines: 3Reasonable context (0-20)
Large codebase searchestype_pattern: "rust"Use type_pattern not glob

See Also

  • Full guide: docs/development/grep-tool-guide.md
  • Outline mode (action=outline): symbol maps via ast-grep outline (>= 0.44.0); see the grep-tool-guide "Outline mode" section.
  • System prompt: Agent instructions for grep usage
  • ripgrep docs: https://github.com/BurntSushi/ripgrep