Skip to main content
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.

Dependencies

No extra dependencies, available by default.

Parameters

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.
Each line returned by read carries a line-number prefix like 12|. Those are display aids, not file content - do not include them in oldText / newText.

Safety checks

A few checks run before writing, and report back in the result:
  • Modified elsewhere: if the file changed after the Agent last read it, the result carries a warning so another program’s changes are not silently overwritten.
  • Syntax check: if the edited content is JSON / YAML / TOML and fails to parse, the write is refused and the file is left untouched - these formats are corrupt when half-written. Source files (.py, for example) only warn, and only when this edit introduced a new syntax error. JSON with comments and trailing commas is accepted in tsconfig*.json, jsconfig*.json, .eslintrc.json, .vscode/*.json and devcontainer.json, and a Helm chart template (YAML with Go template syntax under templates/) is not refused, since it is only YAML once rendered. An existing file that already uses comments or template syntax is checked the same lenient way, whatever its name.
  • Credential protection: ~/.cow/.env, which holds API keys, cannot be modified through this tool. Use the env_config tool instead.

Use Cases

  • Modify specific parameters in configuration files
  • Fix bugs in code
  • Insert content at specific positions in files