FileTools
Claude Code-style file operations with read-before-edit tracking and permission control.
Quick Start
Key Features
1. Read-Before-Edit Validation
FileTools tracks which files have been read and prevents edits without prior reads:
2. Stale Read Detection (MD5 Snapshots)
Detects external file changes between read and edit:
3. write() for NEW Files Only
write() prevents overwriting existing files:
4. Permission Modes
API Reference
read_file(path, offset=None, limit=None)
Read file with line numbers. Automatically tracks MD5 snapshot.
edit(file_path, old_string, new_string, replace_all=False)
Replace string in file. Validates read-before-edit and detects stale reads.
multi_edit(file_path, edits)
Apply multiple edits atomically. All succeed or none applied.
write(path, content)
Create NEW files only. Returns error if file exists.
glob(pattern, path=None)
Search files by glob pattern. Returns max 100 results.
grep(pattern, path=None, ...)
Search file contents with regex. Supports multiple output modes.
Usage Examples
File editing agent with safety
Read-only documentation agent
Code generation agent
Backward Compatibility
Individual functions still available without FileTools wrapper:
Implementation Details
Snapshot Tracking (MD5)
- •Hash calculated on
read_file() - •Validated before
edit()andmulti_edit() - •Updated after successful edits
- •More reliable than timestamps
Why write() Enforces New-File-Only
Old behavior (removed): Used DiffWriter, showed diff, asked for approval
Problem: Over-complicated, required agent.io, didn't make sense for new files
New behavior: Simple create-only function
- •New files → no diff to show, just create
- •Existing files → error, forces agent to use
edit()with validation
See Also
- •DiffWriter — Alternative file editing with visual diffs (legacy)
- •Shell — Execute shell commands
ConnectOnion