Documentation Index
Fetch the complete documentation index at: https://mintlify.com/virsanghavi/axis/llms.txt
Use this file to discover all available pages before exploring further.
guarded_write is the safest way to persist file changes in a multi-agent environment. It combines the tamper check of verify_file_lock and the file write into a single atomic operation — eliminating the race window that exists when an agent checks separately and then writes. The server only writes if two conditions are both true: you hold the lock on the file, and the file’s content matches the fingerprint recorded when the lock was granted.
guarded_write is available on the local stdio server only. The hosted MCP server at useaxis.dev/api/mcp does not have filesystem access. Hosted callers get tamper detection via verify_file_lock and write through their own editor.Parameters
The agent performing the write. Must match the agent that holds the lock on
filePath. If the lock belongs to a different agent, the call returns DENIED.Path to the locked file to write, relative to the repo root or absolute. Must be a file (not a directory) inside the project root.
Full file content to write.
guarded_write writes the complete file — it is not a patch or a diff operation.The Axis project scope. Defaults to the auto-detected project name.
Return values
| Status | Meaning |
|---|---|
WRITTEN | File written successfully. The lock’s content hash is refreshed to reflect the new content. Response also includes filePath and bytes written. |
NO_LOCK | No active lock exists for this file under any agent. Call propose_file_access first. |
DENIED | A lock exists on this file but it belongs to a different agent. You are not authorized to write it. |
CONFLICT | You hold the lock, but the file’s current content no longer matches the hash recorded at lock-grant time. Another process wrote the file under your advisory lock. Re-read and reconcile before retrying. |
How it works
Lock ownership check
guarded_write looks up the lock for filePath and confirms agentId is the recorded holder. Returns NO_LOCK or DENIED immediately if not.Content fingerprint comparison
The file on disk is hashed and compared to the
contentHash stored when propose_file_access was called. If the hashes differ, CONFLICT is returned — no write occurs.Atomic write
If both checks pass, the server writes the file. When
AXIS_ENFORCE_LOCKS=1 is set, the file was chmod’d read-only at lock-grant time; guarded_write briefly restores write permissions, performs the write, then re-applies read-only mode.Why prefer guarded_write over verify-then-write
The manual alternative is:
guarded_write closes that window entirely because the check and the write happen inside the same mutex-protected operation on the server.
Example
Handling CONFLICT
A CONFLICT result means the file was modified by something outside your lock after the lock was granted. The right response is always to reconcile, never to retry blindly:
Re-read the file from disk
The current on-disk version may include work from another agent or an external process that must be preserved.
Merge your changes into the current version
Identify what you changed and apply those changes to the current file content. Do not simply overwrite with your original
content.Re-lock if your lock has expired
If significant time has passed, call
propose_file_access again before retrying the write.AXIS_ENFORCE_LOCKS mode
When the environment variable AXIS_ENFORCE_LOCKS=1 is set, Axis chmods a locked file to read-only at lock-grant time. Any process — including one that does not use Axis at all — will receive EACCES on a direct write attempt. guarded_write is the only safe path to write the file while it is locked, because it handles the permission restore-and-re-apply cycle internally.