Skip to content

Write

Write a file to disk. Content is written atomically (tmp file + rename). Parent directories are created if needed.

ParamTypeRequiredNotes
file_pathstringyesAbsolute or workspace-relative path.
contentstringyesFile content. Empty string creates a zero-byte file.
  • Path goes through Workspace.Resolve first.
  • If the target file already exists, the canonical absolute path MUST have been Read first in the current session; otherwise the call is rejected with refusing to overwrite %s: Read it first.
  • Creating a new file: no prior Read required.
  • Writing to a path that resolves to a directory returns an error.
  • On success, the path is recorded in the read-tracker so subsequent Edit calls don’t need an intervening Read.

Content is written to <path>.tmp.<pid>.<nanos> with O_EXCL, then fsync’d, then Rename’d onto the target. A partial write is never visible. If the rename fails, the temp file is removed.

ConditionResult
Missing file_path or contentError result
Path outside workspaceError result
Target is a directoryError result
Target file exists but not Read’dError result
Parent directory creation failsError result
wrote 42 bytes to notes.md
  • Read — prerequisite for overwrite.
  • Edit — smaller-scoped in-place edits.