file_write
Create, overwrite or copy files and scaffold whole folders with automatic parent creation. Write batches, duplicate or migrate code safely, then verify with a build.
Instructions
Create or overwrite one or more files. Each entry has its own mode:
create: fails if the file already exists (safe default for new files)
overwrite: fails if the file does NOT exist (explicit replacement)
upsert: create or overwrite unconditionally Parent folders are created automatically. An existing file keeps its encoding and line endings; new files are UTF-8. BATCH: pass several entries to scaffold a feature in one call. COPY, DO NOT RETYPE: an entry may carry "from" instead of content. The server copies a whole file or a line range of a file (any enabled workspace), so you write none of it. "from": { "workspace": "Legacy" (default: this workspace), "file": "Services/A.cs" (required), "startLine": 40, "endLine": 80 (leave both out for the whole file), "expectFirstLine" / "expectLastLine": (trimmed; the copy is refused if the lines moved), "replace": [{"find": "Invoice", "with": "Order", "count": 12}] (literal text, the match count must equal count), "csharp": {"namespaces": {"Old.Ns": "New.Ns"}, "identifiers": {"OldName": "NewName"}} (C# files only, by syntax; strings and comments are never touched; use replace for other languages), "indent": -4 (shift every line) }
A copied new file keeps the encoding and line endings of its source. Use it to duplicate, migrate or split files; use mode create so nothing is overwritten by accident. Copied text that holds a secret is refused. Run the build after a copy: the build is the proof. BULK (migrations): an entry {"fromFolder": {"workspace": "Legacy", "folder": "src/Billing", "toFolder": "src/Orders", "glob": "**/*.cs" (below folder, optional), "pathRename": [{"find": "Invoice", "with": "Order"}] (literal, on the path below folder), "replace" / "csharp" / "indent": as above, applied to every file, "mode": "create" (default), "confirmCount": 37}} copies every file of a folder tree (at most 500 per call). Blocked folders, links and refused files are left out. Always run it with dryRun=true first: it lists every file and the count; then repeat without dryRun and pass that count as confirmCount (a changed tree is refused). A file that fails (binary, a secret, an existing target) fails alone; the rest are copied. Keep the result as the migration record. dryRun=true runs every check and copy and reports what would happen without writing. WHEN TO USE: new files, full rewrites, copies and folder migrations. For targeted edits use file_edit_lines; for the same change across many files file_replace; to move or rename file_move. RETURNS: per-file success or error, line count, size in bytes, last-modified time and, for copies, where the text came from.
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": {
"workspace": "<workspace>",
"filesJson": "<filesJson>"
},
"name": "file_write"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guide | No | true: put the files guide first in the result. Use on your first files call, or when told it changed. | |
| dryRun | No | true: check and report only, write nothing (default false) | |
| filesJson | Yes | JSON array of entries, at most 50 (a fromFolder entry counts as one). Three shapes: write: { "relativeFilePath": "Services/OrderService.cs", "content": "<full file content>", "mode": "create|overwrite|upsert" } copy: { "relativeFilePath": "Services/OrderService.cs", "from": { "file": "Services/InvoiceService.cs", ... }, "mode": "create" } bulk: { "fromFolder": { "folder": "src/Billing", "toFolder": "src/Orders", "confirmCount": 37, ... } } The keys of from and fromFolder are listed in the tool description. mode defaults to upsert for write and copy, and to create for bulk. | |
| workspace | Yes | Workspace name as shown in Waymark (a single workspace; '*' is not accepted) |