Write a whole file
write_fileCreate or overwrite a complete file in an Overleaf project's local clone, adding missing parent directories; optionally guard overwrites with an expected revision.
Instructions
Write a whole file: create it, with any missing parent directories, or overwrite it entirely. Use it to add a new file; for an existing one prefer replace_text or edit_section, which cannot drop text you did not mean to rewrite. content is written exactly as given, as UTF-8, with no trailing newline added. expectedRevision makes the call a guarded overwrite, refused if the file changed since that read or no longer exists, so leave it out when creating a file. path must be relative and stay inside the project; absolute paths, .. escapes and the .git directory are refused. Pulls from Overleaf first, then writes only the local clone; push_changes publishes it. Returns whether the file was created or overwritten.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path relative to the project root, e.g. sections/related-work.tex. Must stay inside the project. | |
| content | Yes | The complete new contents of the file, not a fragment to append. | |
| project | No | Which project to use: its Overleaf address, its 24-character id, or a registered project name. Omit to use the default project. | |
| expectedRevision | No | 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. |