File Operations
How Claude Code reads, writes, and edits files with built-in safety and git awareness.
Core File Tools
Claude Code uses dedicated tools instead of shell commands for file operations.
| Tool | Purpose |
|---|---|
| Read | Read files (text, images, PDFs, notebooks). Supports offset/limit for large files. |
| Write | Create or overwrite files. Requires prior Read for existing files. |
| Edit | Exact string replacement. The old_string must be unique in the file. |
| MultiEdit | Multiple edits in one call. Same uniqueness rules as Edit. |
| NotebookEdit | Edit Jupyter notebook cells — replace, insert, or delete. |
| Glob | Fast file pattern matching (e.g., **/*.tsx). Returns paths sorted by modification time. |
| Grep | Content search with regex. Filter by file type or glob pattern. |
File Safety Mechanisms
Multiple safeguards prevent accidental file corruption or data loss.
Read Before Edit
Claude must Read a file before using Edit or Write. Prevents blind overwrites.
Unique String Match
Edit requires old_string to be unique in the file. Prevents wrong-location edits.
Permission Modes
Users approve non-auto-allowed tool calls. Control what Claude can do per session.
Never Commits Secrets
.env files, credentials, and API keys are excluded from git operations.
Git Awareness & Code Generation
Claude Code auto-detects git repositories and follows safe commit practices.
Git Integration
- Auto-detects git repos and shows status at session start
- Uses conventional commit format with focused, descriptive messages
- Never force-pushes, never skips hooks, never amends without asking
- Respects pre-commit hooks — fixes issues and creates new commits
- Warns before destructive operations like reset --hard or branch -D
Code Generation Patterns
Edit Over Create
Always prefers modifying existing files rather than creating new enhanced versions.
Kebab-Case Files
Uses kebab-case for JS/TS files with descriptive, self-documenting names.
Under 200 Lines
Keeps files under 200 lines. Splits larger files into focused modules.