Edit a file in the local clone
edit_fileEdit one file in an Overleaf project's local clone: replace an exact snippet, swap a whole LaTeX section by title, write a new file, or append to the end, then review and publish.
Instructions
Change one file in the project's local clone; action picks how. replace_text replaces an exact snippet, findText, with replaceWith: findText must match exactly, whitespace and newlines included, and occur once unless replaceAll is set, and replaceWith is inserted literally, so $$, $& and $1 stay as written. Prefer it for a targeted change, since nothing outside the snippet is touched. replace_section replaces one whole section of a .tex file, found by sectionTitle as read_file finds it, from its heading to the next heading of the same or a shallower level, never swallowing trailing matter such as \end{document} or the bibliography; content replaces that range line for line, so it must start with the sectioning command itself or the heading is lost, and should end with a newline to keep the blank line before the next heading. write creates the file, with any missing parent directories, or overwrites it entirely with content, exactly as given, as UTF-8, with no trailing newline added; use it for a new file, since for an existing one the other actions cannot drop text you did not mean to rewrite. append adds content at the end of an existing file and leaves every line above it untouched: content starts on a new line and is written exactly as given, so end it with a newline to keep one at the end of the file. A missing file is refused, since write is the action that creates one. expectedRevision makes any action a guarded edit, refused if the file changed since that read or, for write, no longer exists. path must be relative and stay inside the project; absolute paths, .. escapes and the .git directory are refused. Pulls from Overleaf first, then edits only the local clone: review the result with read_project (view changes) and publish it with push_changes. If the snippet or the section is not found, or the snippet occurs several times without replaceAll, nothing changes and the reply gives the count or lists the section titles. Returns what was replaced, written or appended.
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": {
"action": "<action>",
"path": "<path>"
},
"name": "edit_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Every action: path of the file relative to the project root, e.g. sections/intro.tex. Must stay inside the project. | |
| action | Yes | How to edit: replace_text (an exact snippet), replace_section (a whole section, by title), write (the whole file) or append (add to the end of the file). | |
| content | No | replace_section, write and append, required. For replace_section, the section's full replacement, starting with its own sectioning command, e.g. \section{Introduction} followed by the new body. For write, the complete new contents of the file. For append, the text to add after the file's last line. | |
| project | No | Which project to use: its Overleaf address, its 24-character id, or a registered project name. Omit to use the default project. | |
| findText | No | replace_text, required: exact text to find, matched literally including whitespace and newlines. Not a regular expression. | |
| replaceAll | No | replace_text only: replace every occurrence instead of requiring exactly one match (default false). Only set this when replacing all of them is intended. | |
| replaceWith | No | replace_text, required: text to put in its place. An empty string deletes the snippet. | |
| sectionTitle | No | replace_section, required: title of the section to replace, as it appears in the sectioning command. Matched case-insensitively, with a substring fallback; read_project (view outline) lists the titles. | |
| expectedRevision | No | Every action, optional guard: the 64-character revision hash returned by read_file with mode=full or mode=smart for this same file. When given, the edit is refused if the file changed since that read, for example because pulling from Overleaf brought in a collaborator's version. Pass it whenever the edit depends on content you read earlier; leave it out when creating a file. |