Search Tools Decision Tree
Choosing between Glob, Grep, Read, Task and Bash based on context
The 5 native search tools
Claude Code offers 5 distinct tools to find and read information in a project. Each has a precise role, and mixing them without a strategy wastes tokens unnecessarily.
| Tool | Role | Token cost |
|---|---|---|
Glob | Find files by pattern | Low |
Grep | Search content by regex | Low |
Read | Read a full or partial file | High |
Task | Broad, multi-file exploration | Very high |
Bash | System commands, uncovered cases | Variable |
Glob: files by pattern
Glob returns a list of paths without reading their content. It is the fastest tool for locating files before any other operation.
Pattern examples:*.ts → all .ts files at rootsrc/**/*.tsx → all .tsx files in src/**/*.test.ts → all test filesUsage rule: use Glob first to narrow the scope, then Grep or Read on the resulting list.
Grep: content by regex
Grep uses ripgrep under the hood, making it very fast (~20ms on medium codebases). It reads files partially to extract only the matching lines, without loading the full content.
# Find a function by exact nameGrep "authenticate" --type ts
# Search with context (3 lines around)Grep "validateJWT" -A 3Grep is sufficient for 90% of exact text searches. Do not escalate to Task or Bash if the pattern is known.
Read: targeted reading
Read loads a full file or a line range via offset and limit. On large files, it automatically truncates at 2000 lines.
# Read lines 50 to 120 of a fileRead("auth.service.ts", offset=50, limit=70)Always prefer a targeted Read with offset/limit over a full Read on a file with several hundred lines.
Task: broad exploration
The Task tool spawns a sub-agent with its own isolated context. It is the right option when you do not know where to look, the scope is wide, or exploration requires multiple files in parallel.
Cost: each sub-agent opens a new context, which represents a significant overhead. Reserve it for tasks that truly justify it.
Bash: the universal adapter
Bash covers cases the other 4 tools cannot handle directly: git commands, system calls, complex pipes, third-party CLI tools.
# Legitimate use cases for Bashgit log --oneline -20find . -name "*.lock" -mtime -1wc -l src/**/*.tsDecision tree
Looking for files by name/extension → Glob
Looking for text/code and know the pattern → Grep
Want to read an identified file → Read (with offset/limit for long files)
Do not know where to look, broad scope → Task (sub-agent)
None of the 4 tools is sufficient → BashCore principle: Glob and Grep before opening files with Read. Task only when the scope is unknown.
Enter your email to read the full card and get the complete PDF bundle.
All content is free and open-source. We just ask for your email.