Search Tools Decision Tree
Choosing between Glob, Grep, Read, Agent and Bash based on context
PDF editions Β· Guide v3.44.1 Β· Updated
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 |
Agent | 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. Use it to narrow the file set before reading content.
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 suited to exact text searches. It reads files partially to extract only the matching lines, without loading the full content.
# Find a function by exact namerg "authenticate" --type ts
# Search with context (3 lines around)rg "validateJWT" -A 3Use Grep for exact text searches. Do not escalate to Agent 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=71)Always prefer a targeted Read with offset/limit over a full Read on a file with several hundred lines.
Agent: broad exploration
The Agent tool (formerly named Task) 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 β Agent (sub-agent)
None of the 4 tools is sufficient β BashCore principle: Glob and Grep before opening files with Read. Agent 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.