cat, grep, find, sed) because they carry better permission semantics and produce a clearer activity trail.
Read
Reads a file from the local filesystem. Supports text files, images (PNG, JPG, GIF, WebP), PDF documents, and Jupyter notebooks (.ipynb).
Parameters
Absolute path to the file to read. Relative paths are not accepted.
Line number to start reading from (1-indexed). Only provide when the file is too large to read at once.
Number of lines to read. Only provide when the file is too large to read at once.
Page range for PDF files (e.g.,
"1-5", "3", "10-20"). Only applicable to PDF files. Maximum 20 pages per request.Output
The output format depends on the file type.Usage notes
- By default, reads up to 2000 lines from the beginning of the file.
- For large files, use
offsetandlimitto read specific sections. - Images are automatically resized if they would exceed the token budget.
- For PDFs with more than 10 pages, you must provide the
pagesparameter. - If the same file is read again without modification, Claude Code returns a
file_unchangedstub to avoid duplicating content in context.
Examples
Reading a source file
Reading 100–150 of a large file
Reading pages 1–5 of a PDF
Edit
Performs an exact string replacement in an existing file. The file must have been read withRead before it can be edited.
Parameters
Absolute path to the file to modify.
The exact text to find and replace. Must be unique in the file unless
replace_all is true.The replacement text. Must differ from
old_string.When
true, replaces every occurrence of old_string. Useful for renaming variables or symbols across a file.Output
Path to the file that was updated.
The actual string that was replaced (may differ from input after quote normalization).
The replacement string.
Diff patch showing the changes as hunks.
Whether all occurrences were replaced.
Usage notes
- You must call
Readon the file before callingEdit. - The edit fails if
old_stringappears more than once in the file andreplace_allisfalse. Provide more surrounding context to make the match unique. - Preserve exact indentation from the
Readoutput. The line number prefix (e.g.,1→) is not part of the file content and must not be included inold_stringornew_string. - Use
replace_all: truefor renames and find-and-replace operations across the entire file. - Cannot edit Jupyter notebooks (
.ipynb); use theNotebookEdittool instead.
Example
Rename a function
Write
Creates a new file or completely overwrites an existing file. For modifying existing files, preferEdit — it sends only the diff and is more efficient.
Parameters
Absolute path to the file to write. Must be an absolute path.
The full content to write to the file.
Output
"create" for new files, "update" for overwritten files.Path to the file that was written.
The content that was written.
Diff patch for updates (empty for new file creation).
The original file content before the write.
null for new files.Usage notes
- If the file already exists, it must have been read first with
Read. - The tool creates any missing parent directories automatically.
- Use
Editwhen only modifying part of an existing file —Writesends the entire file content every time.
Do not use
Write to create documentation files (.md, README) unless explicitly requested.Example
Create a new configuration file
Glob
Finds files matching a glob pattern. Results are sorted by modification time (most recently modified first).Parameters
Glob pattern to match files against (e.g.,
"**/*.ts", "src/**/*.{ts,tsx}").Directory to search in. Defaults to the current working directory. Omit entirely to use the default — do not pass
"undefined" or "null".Output
Array of matching file paths (relative to cwd).
Total number of files found.
Time taken to execute the search in milliseconds.
Whether results were capped at 100 files. Use a more specific pattern or path if truncated.
Usage notes
- Supports standard glob syntax:
*,**,?,{a,b},[abc]. - Use
Globinstead of runningfindorlsviaBash. - Results are capped at 100 files. Narrow the pattern or set
pathto a subdirectory if you hit the limit.
Examples
Find all TypeScript files
Find test files in a specific directory
Grep
Searches file contents using regular expressions. Powered by ripgrep for fast, accurate searches across large codebases.Parameters
Regular expression pattern to search for in file contents. Uses ripgrep syntax — literal braces must be escaped (e.g., use
interface\{\} to match interface{}).File or directory to search in. Defaults to the current working directory.
Glob pattern to filter which files are searched (e.g.,
"*.js", "*.{ts,tsx}"). Maps to ripgrep’s --glob flag.Controls output format:
"files_with_matches"— returns file paths only (default)"content"— returns matching lines with context"count"— returns match counts per file
Lines of context to show before each match. Requires
output_mode: "content".Lines of context to show after each match. Requires
output_mode: "content".Lines of context to show both before and after each match (alias for
context). Requires output_mode: "content".Lines to show before and after each match. Equivalent to
-C. Requires output_mode: "content".Show line numbers in output. Requires
output_mode: "content".Case-insensitive search.
File type filter using ripgrep type names (e.g.,
"js", "py", "rust", "go"). More efficient than glob for standard language types.Limit output to the first N results, equivalent to piping through
head -N. Pass 0 for unlimited results (use sparingly).Skip the first N results before applying
head_limit. Useful for paginating through large result sets.Enable multiline mode where
. matches newlines and patterns can span multiple lines. Maps to ripgrep’s -U --multiline-dotall.Output
The output mode that was used.
Matching file paths (populated in
files_with_matches mode).Number of files with matches.
Matching lines or counts as a string (populated in
content and count modes).Number of output lines (content mode only).
Total match count across all files (count mode only).
The limit that was applied when results were truncated.
The offset that was applied.
Usage notes
- Always prefer
Grepover runninggreporrgviaBash. - VCS directories (
.git,.svn,.hg) are automatically excluded. - Lines longer than 500 characters are truncated to avoid base64 or minified content cluttering results.
- Results in
files_with_matchesmode are sorted by modification time (most recently modified first).
Examples
Find files containing a function name
Search TypeScript files with context
Case-insensitive search with line numbers
Count occurrences per file