Lesson 7Tools
Search & Navigation
Glob, Grep, patterns
Glob
Pattern-based file search. Quickly finds files by name, extension, path.
Grep
Content search in files. Supports regex, filters, context.
Glob — File Search
Glob uses patterns to find files. Results are sorted by modification time:
| Pattern | Description |
|---|---|
**/*.ts | All TypeScript files |
src/**/*.tsx | All TSX files in src/ |
**/test/*.spec.ts | All spec files in test folders |
*.config.{js,ts} | All config files at root |
!**/node_modules/** | Exclude node_modules |
> Find all React components
Glob: src/**/*.tsx
Found 47 files:
src/components/Button.tsx
src/components/Header.tsx
src/pages/Home.tsx
...
src/components/Button.tsx
src/components/Header.tsx
src/pages/Home.tsx
...
Grep — Content Search
Grep searches text or regex inside files. Built on ripgrep (rg) for speed:
function.*asyncFind async functionsregexTODO|FIXME|HACKFind marker commentsregeximport.*from.*reactFind React importsregexconsole\.logFind debug logsliteral> Find all TODO comments
Grep: pattern="TODO", output_mode="content"
src/auth.ts:42: // TODO: add rate limiting
src/api.ts:15: // TODO: handle errors
src/utils.ts:88: // TODO: refactor this
src/api.ts:15: // TODO: handle errors
src/utils.ts:88: // TODO: refactor this
Output Modes
content— matching linesfiles_with_matches— file paths onlycount— match counts
Useful Options
-i— case insensitive-C 3— 3 lines of contextglob="*.ts"— file filter
Combining Tools
Claude automatically combines Glob and Grep for complex queries:
> Find where useState is used in components
1. Glob: src/components/**/*.tsx
2. Grep: pattern="useState", glob="*.tsx"
2. Grep: pattern="useState", glob="*.tsx"
Found in 12 components:
src/components/Form.tsx:8
src/components/Modal.tsx:5
...
src/components/Form.tsx:8
src/components/Modal.tsx:5
...
Search Strategies
Find file by name
Glob> Find all files named auth
Pattern: **/auth*
Find function usage
Grep> Where is validateUser function used?
Pattern: validateUser
Find class definition
Grep> Find where UserService class is defined
Pattern: class UserService
Explore structure
Task + Explore> Show project architecture
Pattern: Uses sub-agent
Search Tips
- •For exploring unfamiliar codebase, use Task with Explore agent
- •Grep with output_mode="files_with_matches" is faster for initial search
- •Use -C for context around found lines
- •Escape special chars in regex: \{\} for literals
This lesson is part of a structured LLM course.
My Learning Path