Code Search
Scope Constraints
- Read-only file search operations using Grep and Glob
- Does not modify, create, or delete files
- Does not execute found code or run tests
Input Sanitization
- Search patterns: reject null bytes, validate regex syntax before passing to Grep
- File glob patterns: reject
..traversal, null bytes, and shell metacharacters
Use Grep for content searches, Glob for file pattern matching.
Output Format
Found 5 matches for "handleAuth" in 3 files:
src/lib/auth.ts:23 export function handleAuth(req: Request) {
src/lib/auth.ts:45 return handleAuth(nextReq);
src/middleware.ts:12 import { handleAuth } from "@/lib/auth";
Gotchas
- Using
greporrgvia Bash instead of the Grep tool — the Grep tool has optimized permissions and better output formatting - Forgetting
--globor--typefiltering returns matches fromnode_modules,.git, and vendored code — always scope searches - Glob patterns are for file names only, not content — use Grep for content, Glob for finding files by path pattern
Grepuses ripgrep regex, not grep regex — literal braces need escaping (interface\{\}notinterface{})- Reading an entire large file when you only need a section — use
offsetandlimitparameters on Read
Examples
- "find all usages of X" → Grep for X
- "where is the config file" → Glob for config patterns
- "search for error handling" → Grep for try/catch, .catch, error patterns