docs/tools/edit.mdx
Edit files via precise text replacement. Unlike write, which replaces the whole file, edit only sends the part being changed - faster, and less likely to disturb the rest of the file, so prefer it when modifying an existing file. If oldText is empty, appends to the end of the file.
No extra dependencies, available by default.
| Parameter | Type | Required | Description |
|---|---|---|---|
path | string | Yes | File path |
oldText | string | Yes | Original text to replace, must match the file exactly including whitespace (empty to append) |
newText | string | Yes | Replacement text |
replaceAll | boolean | No | Replace every occurrence, default false |
By default oldText must be unique in the file: if it occurs more than once the edit fails and asks for more surrounding context, so the wrong spot is not changed. Set replaceAll=true when every occurrence really should be replaced.
A few checks run before writing, and report back in the result:
.py, for example) only warn, and only when this edit introduced a new syntax error.~/.cow/.env, which holds API keys, cannot be modified through this tool. Use the env_config tool instead.