Skip to main content
Glama

Edit a file

edit_file
Destructive

Replace exact quoted text in an existing file to modify documents while preserving live typing in open files.

Instructions

Replace exact quoted text inside an existing file — the default way to change a document, and the only safe way to change one a person has open (edits merge with their live typing; write_file would discard it). Each quote: ≥8 characters, copied verbatim from a read, matching exactly one place (or set occurrence). Nothing is applied on any error result. {error:"stale_anchor"}: the quote is not in the file — re-read it, re-anchor from the candidates, retry; at most 2 retries, then tell the user what you tried and ask. {error:"ambiguous_anchor"}: the quote matches several places — the candidates carry the occurrence that picks each; resend with it, no re-read needed. {error:"user_editing"}: a person's cursor is inside that edit's quote (editors names them) — they are typing there; edit other parts first or wait a moment and retry, at most twice, then ask the user whether you should hold off. {error:"version_conflict"}: this file changed after the read that base_version came from (writes to other files never conflict, so parallel tools on different files are safe) — re-read this file, then re-apply once. Committed as author Claude before the tool answers, under message (the intent, imperative — "Tighten the abstract"); without one the commit is titled "Edit ". The result's commit and head are that commit; an edit that leaves the file as it was makes no commit and answers commit:null with unchanged:true (nothing is pending).

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "path": "<path>",
      "edits": "<edits>"
    },
    "name": "edit_file"
  }
}

Input Schema

NameRequiredDescriptionDefault
pathYesFile path relative to the project root, e.g. "main.tex" or "sections/intro.tex" — no leading "/", no "..", and hidden folders (.git, .aldine-out) are off limits.
editsYes
branchNoBranch name (defaults to 'main'). Every result, error results included, echoes {branch, head} — head is the branch's current commit (after a write, the commit that write made). Pass the branch explicitly whenever you are not on main.
messageNoCommit message stating the intent of this change, imperative ("Tighten the abstract"), at most 200 characters. It titles the commit in the History panel; every call is one commit.
projectNoProject id. Optional when the access token is scoped to exactly one project.
base_versionNocontentVersion (or fileVersion) from your read of this file, or contentVersion from project_structure for a file you are creating. Refused with {error:"version_conflict", reason, currentVersion, fileVersion} when this file changed after that read (changes to other files on the branch do not count), or when base_version is newer than the branch's contentVersion (a server restart or another node issued it) — either way re-read the file and use the contentVersion that read returns.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations declare destructiveHint=true, non-idempotent, non-readOnly, and the description substantiates those hints with real behavior: all-or-nothing application ("nothing is applied on any error result"), live-merge semantics with a human's cursor, per-file rather than per-project conflict detection, and the commit created as author Claude. It also pre-empts the destructive hint by explaining that the no-op case produces commit:null rather than a spurious commit. The one gap is that "destructive" is never reconciled explicitly — an agent must infer that overwriting quoted text is the intended, reviewed mutation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Purpose and the write_file contrast are front-loaded in the first sentence, and the error catalog is organized by literal error key so an agent can pattern-match on the response it received. It is dense to the point of being a wall of text, and the {error:...} notation is packed inline, but almost every clause carries decision-relevant information rather than filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a destructive 6-parameter mutation with no output schema, this covers the essential burden: atomicity, concurrency, live-editing conflicts, commit authorship, and the commit:null/unchanged:true success variant that an agent would otherwise misread as failure. The remaining ambiguity is how multiple entries in the edits array compose — whether each quote is matched against the original or the progressively edited text — which matters for a batch of up to 50 edits.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 83% schema description coverage the schema already documents path, quote, occurrence, replacement, branch, message, and base_version in detail, so the description's restatements of the 8-character minimum, single-match rule, and imperative message style add little. What it does add is behavioral linkage — which error key corresponds to which parameter going stale (stale_anchor → quote, version_conflict → base_version, ambiguous_anchor → occurrence) — which is genuinely beyond the schema. The ordering semantics of multiple edits in the array remain unstated.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

"Replace exact quoted text inside an existing file" is a precise verb+resource pair, and it immediately frames itself as "the default way to change a document" while naming the sibling it beats (write_file would discard live typing). An agent can distinguish it from write_file, batch_write, and commit without opening any schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives an explicit default (use this to change a document), an explicit exclusion (write_file discards a person's open edits), and prescribes alternative actions per failure mode — edit other parts first, re-read, or stop and ask the user after bounded retries. Retry budgets (at most 2, at most twice) turn guidance into actionable policy rather than vague advice.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.