str_replace_editor
Replace a specific string block in a file with new content using exact line matches. Use unique old_str to locate the target, preserving file state across edits.
Instructions
Custom editing tool for viewing, creating and editing files
State is persistent across command calls and discussions with the user
If
pathis a file,viewdisplays the result of applyingcat -n. Ifpathis a directory,viewlists non-hidden files and directories up to 2 levels deepThe
createcommand cannot be used if the specifiedpathalready exists as a fileIf a
commandgenerates a long output, it will be truncated and marked with<response clipped>
Notes for using the str_replace command:
The
old_strparameter should match EXACTLY one or more consecutive lines from the original file. Be mindful of whitespaces!If the
old_strparameter is not unique in the file, the replacement will not be performed. Make sure to include enough context inold_strto make it uniqueThe
new_strparameter should contain the edited lines that should replace theold_str
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to file or directory, e.g. `/repo/file.py` or `/repo`. | |
| command | Yes | The commands to run. Allowed options are: `view`, `create`, `str_replace`, `insert`. | |
| new_str | No | Optional parameter of `str_replace` command containing the new string (if not given, no string will be added). Required parameter of `insert` command containing the string to insert. | |
| old_str | No | Required parameter of `str_replace` command containing the string in `path` to replace. | |
| file_text | No | Required parameter of `create` command, with the content of the file to be created. | |
| view_range | No | Optional parameter of `view` command when `path` points to a file. If none is given, the full file is shown. If provided, the file will be shown in the indicated line number range, e.g. [11, 12] will show lines 11 and 12. Indexing at 1 to start. Setting `[start_line, -1]` shows all lines from `start_line` to the end of the file. | |
| insert_line | No | Required parameter of `insert` command. The `new_str` will be inserted AFTER the line `insert_line` of `path`. |