Skip to Content
GuidesWork with files

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

ToNeeds the class
list, stat, search, readread
write and editwrite
deletedestructive

Paths are absolute, or relative to the user’s home folder; ~ is the home folder.

Find and read

  1. List a folder with fs_list (500 entries by default), or search under one with fs_search by name (*.rs) and plain-text content.
  2. 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; when truncated is true, read on with offset.

Change a file safely

  1. Get the file’s hash: fs_stat with "hash": true returns sha256. After your own write, the sha256 that fs_write or fs_edit returned is the hash of the new version.
  2. Change it:
    • a few exact lines: fs_edit with old, new and expect_sha256. old must occur exactly once, whitespace included, unless you set replace_all. Text files up to 4 MiB.
    • the whole file: fs_write with data and expect_sha256. Up to 8 MiB, text or base64; the file is replaced atomically and keeps its permissions.
  3. Create a new file with fs_write and "create_only": true; "mkdirs": true creates 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": true in ceiling.json lifts 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 .git folder and .mcp.json file, /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.

Set the ceiling · Risk classes · Security model