Write file
write_fileCreate, overwrite, or append files in a locked workspace with optional parent directory creation and SHA-256 conflict checks that refuse writes if the file changed since you read it.
Instructions
Write a file. mode=create (fails if it exists), overwrite, or append. create_dirs=true creates parent folders. Use when: you create a file, replace one entirely, or append. expected_sha256 refuses the write if the file changed since you read it. Avoid when: you change a few lines (edit_file). overwrite is immediate and not undoable: snapshot first when the file is not in git. Output: action (created|overwritten|appended), bytes_written, sha256_after. mode=create on an existing path gives conflict.
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": {
"relative_path": "<relative_path>",
"content": "<content>"
},
"name": "write_file"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mode | No | Default overwrite. create fails if the path exists; append adds to the end. | |
| reason | No | Optional why (max 400 chars), audit-logged. | |
| content | Yes | Full file content to write. | |
| create_dirs | No | true creates missing parent directories (default false). | |
| relative_path | Yes | Workspace-relative ('.' = root); absolute/.. outside it rejected. | |
| expected_sha256 | No | Hex SHA-256 of the file's current full content. The write is refused if the file on disk differs. Use sha256_after from your last write/edit of this file; read_file's sha256 only matches when the whole file was returned. |