Skip to content

write_file — create a new file

write_file creates a new file at path and writes content to it. Parent directories are created automatically. When write_guard is enforced, the call is refused if path already exists — the agent should use edit_file or apply_patch instead.

ArgTypeRequiredDescription
pathstringyesRelative or absolute path to the new file.
contentstringyesFile body. May be empty.
{"path": "src/new_module.py", "content": "def hello():\n return 'hi'\n"}
from chimera.tools.write import WriteFileTool
tool = WriteFileTool()
result = tool.execute(
{"path": "examples/note.txt", "content": "first line\n"},
env=local_env,
)
Wrote 11 bytes to examples/note.txt

On a guarded clobber attempt:

write_file invariant violated for 'examples/note.txt':
file already exists; use 'edit_file' or 'apply_patch'
...