Working with Files and Tools
Master the 5 core tools Claude uses to interact with your codebase. After this lesson, you will know exactly which tool does what.
LEARNING OBJECTIVES
- 1. Understand how Claude reads and navigates your codebase
- 2. Know the 5 core tools: Read, Write, Edit, Grep, Bash
- 3. Choose the right tool for each situation
- 4. Practice the read-then-edit workflow pattern
How Claude Sees Your Code
Claude Code does not magically know your codebase. It uses the Read tool to open specific files and the Glob tool to find files by pattern. When you ask a question about your code, Claude first searches for the relevant files, reads them, then responds with full context.
This means Claude only sees what it actively looks at. If your answer lives in a file Claude has not read, point it there: "Check src/lib/auth.ts for the token logic." Specificity saves time and context window space.
The 5 Core Tools
Opens a file and returns its contents with line numbers. Claude reads files to understand your code before making changes.
Best for: understanding code, checking current state, reviewing configs
Creates a new file or completely rewrites an existing one. Writes the entire file contents in one shot.
Best for: new components, config files, boilerplate, complete rewrites
Finds a specific string in a file and replaces it. Preserves everything else. The safest way to modify existing code.
Best for: bug fixes, adding a function, updating imports, small refactors
Searches file contents using regex patterns across your entire codebase. Finds every usage, import, or pattern match instantly.
Best for: finding imports, API calls, error handlers, TODO comments
Executes shell commands: tests, builds, linters, git operations, package installs, scripts. The agent's hands.
Best for: running tests, building projects, git operations, system commands
Try This: Search Your Codebase
Claude shows a list of files with React imports, using Grep to search and Read to verify.
The Read-Then-Edit Pattern
The most important pattern in Claude Code: always read before editing. Claude reads a file to understand its current state, then uses Edit to make targeted changes. This prevents blind overwrites and catches context you might have forgotten about.
When you say "fix the bug in auth.ts," Claude internally does: Grep (find the file) → Read (understand it) → Edit (fix the specific issue) → Bash (run tests to verify).
Try This: Make a Surgical Edit
Claude reads the file, checks if a description exists, and uses Edit to add one without touching anything else.
Running and Fixing
The Bash tool runs shell commands: tests, builds, linters, git operations. The killer workflow: "Run my tests, find any failures, and fix them." Claude runs the suite, reads the error output, finds the failing code, and edits the fix — all in one flow.
Try This: Run and Fix
Claude uses Bash to run commands, then reads the output and explains the results.
Quick Reference: Which Tool When?
| I want to... | Use this tool |
|---|---|
| Find files by name | Glob |
| Find code by content | Grep |
| Read a known file | Read |
| Create something new | Write |
| Change existing code | Edit |
| Run tests/builds/scripts | Bash |
Knowledge Check
1 of 3You need to change one line in a 500-line file. Which tool should Claude use?
Key Takeaways
- ✓Claude uses 5 core tools: Read, Write, Edit, Grep, Bash
- ✓Claude only sees files it actively reads — point it to the right file
- ✓Edit is safer than Write for existing files (surgical vs full rewrite)
- ✓The read-then-edit pattern prevents blind overwrites
- ✓Bash enables the "run tests → find failures → fix them" workflow