Work with files
Read and change files on a machine with the file tools. A change to an existing file names the hash of the version you read, so a file someone changed in between is never overwritten.
Before you start
| To | Needs the class |
|---|---|
| list, stat, search, read | read |
| write and edit | write |
| delete | destructive |
Paths are absolute, or relative to the user’s home folder; ~ is the home folder.
Find and read
- List a folder with
fs_list(500 entries by default), or search under one withfs_searchbyname(*.rs) and plain-textcontent. - Read with
fs_read: text comes back as text, anything else as base64. Up to 256 KiB per call by default, 4 MiB at most; whentruncatedis true, read on withoffset.
Change a file safely
- Get the file’s hash:
fs_statwith"hash": truereturnssha256. After your own write, thesha256thatfs_writeorfs_editreturned is the hash of the new version. - Change it:
- a few exact lines:
fs_editwithold,newandexpect_sha256.oldmust occur exactly once, whitespace included, unless you setreplace_all. Text files up to 4 MiB. - the whole file:
fs_writewithdataandexpect_sha256. Up to 8 MiB, text or base64; the file is replaced atomically and keeps its permissions.
- a few exact lines:
- Create a new file with
fs_writeand"create_only": true;"mkdirs": truecreates missing parent folders.
Replacing an existing file without expect_sha256 returns
hash_required and writes nothing. When the file changed since
you read it, the write is refused: read it again, then decide.
Remove a file
fs_delete moves the file or folder to the user’s trash, so the
owner can put it back; the answer says where (trashed_to). A folder that is not empty needs
"recursive": true. "permanent": true removes for good and cannot be undone: use it only where
the trash cannot take the file.
What the file tools never reach
- Keys and credentials, for reading and writing:
~/.ssh,~/.gnupg,~/.aws,~/.azure,~/.kube,~/.docker,~/.netrc,~/.password-store,~/.git-credentials,~/Library/Keychains,~/.claude,~/.codex, the credential folders under~/.config(gh,gcloud,op,cmdop*), and the machine program’s own folder."secrets": trueinceiling.jsonlifts this list; it does not lift the next one. - Files no tool may change, whatever the grant and the ceiling say: shell start files
(
.bashrc,.bash_profile,.zshrc,.zprofile,.zshenv,.profile),.gitconfig,.claude.json,~/.ssh,~/.claude,~/.codex, the keychains, any.gitfolder and.mcp.jsonfile,/etc, and the machine program’s own folder. - Folders outside the machine’s roots, when its ceiling lists
roots.
A refusal returns denied with the reason. exec_run is not limited
by these folders: an agent with exec can do anything the user can.
Check
fs_stat on the path shows the new size and modified time, and with "hash": true the same
sha256 your write returned.