> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cowagent.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# edit - File Edit

> The edit tool changes files by exact text replacement, sending only the changed part. Matches must be unique unless replaceAll is set; it can append to the end and runs safety checks first.

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

| 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.

> [!NOTE]
>
> 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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.