Home

File Tools

The file tools give agents the ability to read, write, and search files within the workspace. Each tool call is evaluated by the file guard before execution.

read_file

Reads the contents of a file with line-number annotations. Supports partial reads via offset and limit parameters.

ParameterTypeRequiredDescription
file_pathstringAbsolute path to the file to read
offsetinteger (min: 1)Line number to start reading from (1-based). Defaults to 1
limitinteger (min: 1)Maximum number of lines to read. Defaults to 2000

Output is formatted with line numbers: each line is prefixed with its number and a | separator. Image files are returned as inline image data if under the size limit, or as a text placeholder otherwise.

write_file

Creates or overwrites a file, creating any parent directories as needed.

ParameterTypeRequiredDescription
file_pathstringAbsolute path to the file to write
contentstringThe content to write to the file

edit_file

Performs an exact string replacement in a file. By default the old_string must appear exactly once; set replace_all to true for multiple replacements.

ParameterTypeRequiredDescription
file_pathstringAbsolute path to the file to edit
old_stringstringThe exact string to find and replace
new_stringstringThe replacement string
replace_allbooleanIf true, replace all occurrences. Defaults to false

Returns an error if the file does not exist, the old_string is not found, or there are multiple matches without replace_all.

apply_patch

Parses and applies a patch in the v4a format, supporting file creation, deletion, update, and rename in a single operation.

ParameterTypeRequiredDescription
patchstringThe patch content in v4a format

The patch format uses markers like *** Add File:, *** Delete File:, *** Update File:, and *** Move to: to describe operations. Update hunks use @@ context hints for positioning and support fuzzy matching (whitespace normalization, smart quote normalization) when exact matches fail.

Info

This tool is only available when using models that support the v4a patch format.

grep

Searches file contents using a regular expression pattern, returning matching lines with file paths and line numbers.

ParameterTypeRequiredDescription
patternstringRegular expression pattern to search for
pathstringDirectory or file to search in. Defaults to the working directory
glob_filterstringGlob pattern to filter files (e.g., "*.rs", "*.py")
case_insensitivebooleanIf true, perform case-insensitive matching. Defaults to false
max_resultsinteger (min: 1)Maximum number of matching lines to return. Defaults to 100

glob

Finds files matching a glob pattern, sorted by modification time (newest first).

ParameterTypeRequiredDescription
patternstringGlob pattern to match files (e.g., "**/*.rs", "src/*.py")
pathstringBase directory for the search. Defaults to the working directory

Guard Rules

The file guard normalizes every path (tilde expansion, .. resolution, relative to absolute) and then checks it against a set of rules. For tools that operate on multiple paths (e.g., apply_patch), each path is evaluated and the strictest verdict wins.

Rule IDApplies toReasonSuggestionLowMediumHigh
file.system_path_readReadReading virtual/device filesystem paths can expose kernel state, process internals, and credentialsUse specific inspection commands instead (e.g., uname for system info, env for environment)DenyDenyDeny
file.sensitive_path_readReadReading credential and key files can leak secrets into the agent's context windowUse targeted commands that don't expose raw secrets (e.g., ssh-keygen -l -f to check a key fingerprint)DenyDenyWarn
file.outside_workspace_readReadRead target is outside the session workspace rootVerify the path is intended, or copy the file into the workspace firstDenyWarnAllow
file.system_path_writeWriteWriting to system paths can break OS configuration and stabilityUse application-level config files in the project directory insteadDenyDenyDeny
file.sensitive_path_writeWriteWriting to credential files or shell startup files is a persistence and credential-tampering vectorModify project-local configuration instead of user-level dotfilesDenyDenyDeny
file.outside_workspace_writeWriteWrite target is outside the session workspace rootWrite to a path within the project workspace, or verify the target path is intendedDenyWarnAllow
file.protected_file_overwriteWriteWriting to .git/ internals can corrupt repository stateEdit hooks or config via git config or manual review outside the agentDenyDenyWarn
file.apply_patch_delete_manyPatchBulk file deletion in a single patch may indicate a hallucinated cleanup (≥5 files)Break the patch into smaller steps deleting fewer than 5 files each, or verify the file list is correctDenyWarnWarn

Path Lists

System read paths

These paths trigger file.system_path_read (prefix match):

  • /proc/

  • /sys/

  • /dev/

Sensitive paths (read)

These paths trigger file.sensitive_path_read:

  • /etc/shadow (exact)

  • /etc/gshadow (exact)

  • /etc/sudoers (exact)

  • ~/.ssh/ (prefix)

  • ~/.gnupg/ (prefix)

  • ~/.aws/ (prefix)

  • ~/.config/gcloud/ (prefix)

  • .env (basename)

  • .netrc (basename)

Sensitive paths (write)

These paths trigger file.sensitive_path_write (superset of read-sensitive paths):

  • ~/.ssh/ (prefix)

  • ~/.gnupg/ (prefix)

  • ~/.aws/ (prefix)

  • ~/.config/gcloud/ (prefix)

  • .env (basename)

  • .netrc (basename)

  • ~/.bashrc (exact)

  • ~/.bash_profile (exact)

  • ~/.profile (exact)

  • ~/.zshrc (exact)

  • ~/.zprofile (exact)

System write paths

These paths trigger file.system_path_write (prefix match):

  • /etc/

  • /usr/

  • /boot/

  • /sbin/

  • /bin/

  • /lib/

  • /proc/

  • /sys/

  • /dev/

Protected directory components

These directory names trigger file.protected_file_overwrite when they appear as a path component:

  • .git

© 2026 Stencila