Built-in Tools: Read, Write, Edit, Bash, Grep, Glob
Understanding Claude Code's six built-in tools and when to use each one. Grep for content search, Glob for file path matching, Read/Write for full file operations, Edit for targeted modifications, and Bash for shell commands. Includes the incremental codebase exploration pattern: Grep entry points, Read imports, trace flows.
Quick Reference
- →Grep: Search file CONTENTS for patterns (regex). Use to find function callers, string references, imports
- →Glob: Search file PATHS by pattern. Use to find files by name/extension (e.g., **/*.test.tsx)
- →Read: Read full file contents. Use after Grep/Glob to inspect specific files you identified
- →Write: Write entire file contents (overwrites). Use for new files or complete file rewrites
- →Edit: Targeted string replacement within a file. Use for precise changes without rewriting the whole file
- →Bash: Run shell commands. Use for git, npm, builds, tests -- anything the other 5 tools don't cover
- →When Edit fails on non-unique match, fall back to Read + Write (read the file, modify content, write back)
- →Incremental exploration: Grep to find entry points -> Read to inspect -> trace imports/calls -> repeat
- →Start with Grep, not Read -- searching first prevents reading irrelevant files
- →Use Glob when you need file paths, Grep when you need file contents
The Six Built-in Tools at a Glance
Claude Code ships with six built-in tools that handle all file system operations, code exploration, and shell interactions. Every task Claude performs in a codebase uses these tools. Understanding when to use each one -- and when NOT to -- is the difference between efficient exploration and wasted context window.
| Tool | Purpose | When to use | Example |
|---|---|---|---|
| Grep | Search file contents by regex pattern | Finding function callers, string references, error messages, imports | Grep for 'handleSubmit' to find all components that call it |
| Glob | Find files by path/name pattern | Finding files by extension, name pattern, or directory structure | Glob '**/*.test.tsx' to find all React test files |
| Read | Read file contents (with line numbers) | Inspecting a specific file you already identified via Grep/Glob | Read src/api/handler.ts to see the full implementation |
| Write | Write/overwrite entire file | Creating new files or complete rewrites | Write a new config file or completely rewrite a module |
| Edit | Targeted string replacement | Changing specific lines without rewriting the whole file | Replace a function call, update an import, fix a typo |
| Bash | Run shell commands | Git, npm, builds, tests, any CLI operation | Run npm test, git status, or curl an API |
These tools cover all interactions with a codebase: finding files (Glob), searching contents (Grep), reading (Read), writing (Write), precisely editing (Edit), and running commands (Bash). Together they form a complete toolkit for code exploration, modification, and validation.