Write app file
write_fileCreate or edit a file in a space. Only app/ files are writable (Genesis app source code).
IMPORTANT: Always read the file with inspect_space before editing. Edits to a stale view may fail or corrupt content.
Commands:
"create" — Create a new file. Provide fileText with the full content.
"str_replace" — Replace a substring. Provide oldStr (must match exactly once in the file) and newStr.
"insert" — Insert text at a line number. Provide insertLine and fileText.
"str_diff_patch" — Apply a unified diff patch. Provide diffPatch.
"delete" — Delete an app file. No other fields are needed. Refused while any app source still imports the file, so remove or repoint those imports first. A deleted file can be brought back from the app's Version History. A successful write is COMMITTED, not staged: it redeploys and, on apps using the default automatic publish strategy, typically republishes to the live app on its own. Do not tell the user to publish afterwards, and do not report the change as pending - it is already on its way out.
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": {
"spaceId": "<spaceId>",
"path": "<path>",
"command": "<command>"
},
"name": "write_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | File path to write. Example: "app/src/App.tsx" | |
| appId | No | App ID. When omitted, resolves the default (first-created) app in the space. | |
| newStr | No | The replacement string. Required for "str_replace". | |
| oldStr | No | The exact string to find and replace. Required for "str_replace". Must appear exactly once in the file. | |
| command | Yes | Write operation. One of: create, str_replace, insert, str_diff_patch, delete. | |
| spaceId | Yes | Space ID | |
| fileText | No | File content. Required for "create" and "insert". | |
| diffPatch | No | Unified diff patch to apply. Required for "str_diff_patch". | |
| insertLine | No | Line number to insert before. Required for "insert". |