πŸ”§Tool Prompts/file-ops

Grep Tool

src/tools/GrepTool/prompt.ts

Prompt Engineering Insight

The Grep tool prompt uses strong behavioral constraints to prevent the model from falling back to raw shell grep/rg commands, ensuring the purpose-built tool is always used. It provides concrete regex examples as a form of few-shot guidance for pattern syntax, and includes an important disambiguation between grep and ripgrep syntax conventions.

Techniques Used

behavioral-constraintstool-use-guidancefew-shot-examplesscope-limiting
prompt
A powerful search tool built on ripgrep
Usage:
  • ALWAYS use Grep for search tasks. NEVER invoke grep or rg as a Bash command. The Grep tool has been optimized for correct permissions and access.
  • Supports full regex syntax (e.g., "log.*Error", "function\s+\w+")
  • Filter files with glob parameter (e.g., "*.js", "**/*.tsx") or type parameter (e.g., "js", "py", "rust")
  • Output modes: "content" shows matching lines, "files_with_matches" shows only file paths (default), "count" shows match counts
  • Use Agent tool for open-ended searches requiring multiple rounds
  • Pattern syntax: Uses ripgrep (not grep) - literal braces need escaping (use interface\{\} to find interface{} in Go code)
  • Multiline matching: By default patterns match within single lines only. For cross-line patterns like struct \{[\s\S]*?field, use multiline: true

Tags

grepsearchripgrepregexcontent-search