Overview
The file operations tools provide efficient ways to interact with the local filesystem, including reading files with advanced modes, listing directories, searching file contents, and applying patches.read_file
Reads a local file with 1-indexed line numbers, supporting slice and indentation-aware block modes.Parameters
Absolute path to the file.
The line number to start reading from. Must be 1 or greater.
The maximum number of lines to return.
Optional mode selector:
slice for simple ranges (default) or indentation to expand around an anchor line.Configuration for indentation mode.
Anchor line to center the indentation lookup on (defaults to offset).
How many parent indentation levels (smaller indents) to include.
When true, include additional blocks that share the anchor indentation.
Include doc comments or attributes directly above the selected block.
Hard cap on the number of lines returned when using indentation mode.
Usage Examples
Indentation Mode
Indentation mode is useful for reading code blocks intelligently:- anchor_line: The line number you’re interested in (e.g., line 42 inside a function)
- max_levels: How many parent scopes to include (0 = just the anchor block, 1 = anchor + parent class/function, etc.)
- include_siblings: Whether to include other methods/functions at the same indentation level
- include_header: Whether to include doc comments and decorators above the block
list_dir
Lists entries in a local directory with 1-indexed entry numbers and simple type labels.Parameters
Absolute path to the directory to list.
The entry number to start listing from. Must be 1 or greater.
The maximum number of entries to return.
The maximum directory depth to traverse. Must be 1 or greater.
Usage Example
Output Format
Entries are marked with suffixes:/- Directory@- Symlink?- Other (socket, pipe, etc.)- (no suffix) - Regular file
grep_files
Finds files whose contents match a regex pattern and lists them sorted by modification time.Parameters
Regular expression pattern to search for.
Optional glob that limits which files are searched (e.g.,
"*.rs" or "*.{ts,tsx}").Directory or file path to search. Defaults to the session’s working directory.
Maximum number of file paths to return (max 2000).
Usage Examples
Notes
- Uses ripgrep (
rg) for fast searching - Results are sorted by file modification time (most recent first)
- Supports full regex syntax
- Returns file paths with matches (not the match content itself)
apply_patch
Applies a structured patch to add, update, move, or delete files.Parameters
The entire contents of the apply_patch command, from
*** Begin Patch to *** End Patch.Patch Format
Patches must be wrapped in markers:Add File
Delete File
Update File
Move File
Change Context
Each update chunk should start with@@ followed by a context string that helps locate the change:
End of File
To mark changes at the end of a file, add*** End of File:
Usage Example
Matching Algorithm
The patch system tries multiple matching strategies in order:- Exact match - Character-for-character equality
- Trim end - Ignores trailing whitespace
- Trim - Ignores leading and trailing whitespace
- Normalize - Converts Unicode quotes, dashes, and spaces to ASCII equivalents