Description
Finds and replaces exact string occurrences in a file. Because this tool operates on exact string matches, it's suited for simple renames, value updates, or repetitive text changes where the target string is unambiguous.
Replace vs Edit
btw's two file-editing tools serve different use cases:
btw_tool_files_replace()is best for exact text substitutions: renaming a variable, updating a URL, or changing a value. It does not require a priorbtw_tool_files_read()call. By default, it requires the match to be unique to prevent unintended changes.btw_tool_files_edit()is best for structural, line-based edits: inserting new lines, deleting lines, replacing a range of lines, or making several edits at once. It requires hashline references from a priorbtw_tool_files_read()call and validates them against the current file state.
Arguments
- path
Path to the file to edit. The
pathmust be in the current working directory.- old_string
The exact string to find in the file. Must match character-for-character, including whitespace and indentation. Must be unique unless
replace_allisTRUE.- new_string
The replacement string. Must differ from
old_string. Use an empty string ("") to delete the matched text.- replace_all
If
TRUE, replace all occurrences ofold_string. Defaults toFALSE, which requires exactly one occurrence.- _intent
An optional string describing the intent of the tool use. When the tool is used by an LLM, the model will use this argument to explain why it called the tool.
Value
Returns a message confirming the replacement was applied, including the number of occurrences replaced.
See also
btw_tool_files_edit() for line-based structural edits using
hashline references, btw_tool_files_read() for reading files.
Other files tools:
btw_tool_files_edit(),
btw_tool_files_list(),
btw_tool_files_read(),
btw_tool_files_search(),
btw_tool_files_write()
