← All tools

Code Engineering

File Edit (exact-string)

The small-diff alternative to file_write — exact-string replace with a single-match safety rule.

file_edit

Overview

Most agent edits are tiny — fix this line, rename this token here. file_edit makes that the cheap path: send the old slice and the new slice, get a guaranteed targeted change.

How it works

WORKSPACE_WRITE permission. Refuses to edit outside the optional projectRoot. Refuses files matching sensitive-content patterns (.env, credentials, secret, password, private_key, .pem, .key, .p12, .jks, .keystore, id_rsa, id_ed25519). Complement to file_write — use file_edit for targeted modifications, file_write for new files or full rewrites.

Example

When a user asks:

In UserService.java, change MAX_RETRIES from 3 to 5.

the agent calls the tool:

file_edit(file="src/main/java/.../UserService.java", old_string="MAX_RETRIES = 3", new_string="MAX_RETRIES = 5")

and gets back: 1 replacement in UserService.java (line 42)

What it's good for

Real scenarios where agents put this tool to work.

Iterative refactor: edit, run test_runner, observe, edit again
Patch a single config value without rewriting the whole file

Source

Implementation lives at swarmai-tools/src/main/java/ai/intelliswarm/swarmai/tool/code/edit/FileEditTool.java in the swarm-ai repository.

Open file_edit on GitHub →