Tools Overview
- list_files: List files and directories
- search_files: Regex search across files
- str_replace_editor: View, create, and edit files
list_files
List files and directories within the specified directory.Directory path to list
Whether to list files recursively
Response
List of files found
List of directories found
Total number of files found
Total number of directories found
Example
Lists contents alphabetically. Returns maximum 500 results to avoid overwhelming output.
search_files
Perform a regex search across files in a directory.Directory path to search
Regular expression pattern to search for
File pattern to filter (e.g., “.py”, “.js”)
Response
The search results as a string
Example
str_replace_editor
A text editor tool for viewing, creating, and editing files.Editor command to execute:
view: Show file contentscreate: Create a new filestr_replace: Replace text in fileinsert: Insert text after a lineundo_edit: Revert the last edit
Path to the file to edit
Required for
create command. The content of the file to be created.Optional for
view command. Line number range to view, e.g., [11, 12] will show lines 11 and 12. Setting [start_line, -1] shows all lines from start_line to end.Required for
str_replace command. The string in the file to replace.Required for
str_replace and insert commands. The new string to use.Required for
insert command. The new_str will be inserted AFTER this line number.Response
The result of the operation
Error message if operation failed
Examples
Viewing Files
Creating Files
Replacing Text
Inserting Text
Undoing Changes
Important Notes
Command Details
- view: Show file contents, optionally with line range. Indexing starts at 1.
- create: Create a new file with given content. Will fail if file already exists.
- str_replace: Replace old_str with new_str in file. Must match exactly.
- insert: Insert new_str AFTER the specified line number.
- undo_edit: Revert the last edit made to the file.
Best Practices
- Always view a file before editing to understand its structure
- Use specific, unique strings in str_replace to avoid ambiguity
- Include sufficient context in old_str to ensure correct replacement
- Test complex replacements on a small section first
- Use undo_edit if a change needs to be reverted