file_read
Reads a file and returns its contents formatted with line numbers.Path to the file relative to project root
Line number to start reading from (1-based). Use this to read specific sections of large files.
Maximum number of lines to return. Combine with
offset for pagination.Returns
Success response includes:- File path and total line count in header
- Line-numbered content (6-character padded line numbers)
- Count of lines shown
Error Cases
enoent
File not found at the specified path
eisdir
Path points to a directory, not a file
path_validation
Path attempts to access outside project directory
Usage Examples
file_write
Writes content to a file, creating parent directories if needed. Overwrites existing files.Path to the file relative to project root
The content to write to the file
Returns
Success response includes:- Number of bytes written
- Full path to the written file
Behavior
Directory Creation
Directory Creation
Parent directories are created automatically:
Overwrite Warning
Overwrite Warning
file_write always overwrites existing files without confirmation.For editing existing files, use
file_edit instead to make targeted changes.Usage Examples
file_edit
Performs exact string replacement in a file. Designed to prevent ambiguous edits.Path to the file relative to project root
The exact text to find and replace. Must match exactly including whitespace and indentation.
The text to replace it with. Must be different from
old_string.Replace all occurrences. When
false, old_string must appear exactly once to prevent ambiguous edits.Returns
Success response includes:- Number of occurrences replaced
- File path
Validation Rules
Usage Examples
Best Practices
Exact Matching
Whitespace matters. Copy the exact indentation and line endings from
file_read output.Include Context
When the string might appear multiple times, include surrounding lines to make it unique.
Use replace_all Wisely
Only use
replace_all: true when you’re certain you want to replace every occurrence (e.g., renaming a variable).Read First
Always use
file_read to see the current file state before editing.Implementation Details
All file operations are implemented inlib/loom/tools/:
file_read.ex- Source: lib/loom/tools/file_read.ex:1file_write.ex- Source: lib/loom/tools/file_write.ex:1file_edit.ex- Source: lib/loom/tools/file_edit.ex:1
Loom.Tool.safe_path!/2 for path validation.