File Writer
by @ykaixu
Safely write or update large files over 5000 bytes by reading, incrementally editing small sections, verifying each change, and using fallback recovery methods.
Example 1: Adding Section to Large File
Step 1: Read file to find insertion point
read /path/to/large-file.md --offset 50 --limit 10Step 2: Use edit to add new section
edit:
file_path: /path/to/large-file.md
oldText: "## Existing Section\n\nContent here"
newText: "## Existing Section\n\nContent here\n\n## New Section\n\nNew content"
Step 3: Verify
read /path/to/large-file.md --offset 50 --limit 20
Example 2: Creating Large New File
Step 1: Create basic structure
write:
file_path: /path/to/new-file.md
content: "# Title\n\n## Section 1\n\nContent 1"Step 2: Add sections incrementally
edit:
file_path: /path/to/new-file.md
oldText: "Content 1"
newText: "Content 1\n\n## Section 2\n\nContent 2"
Step 3: Verify
wc -l /path/to/new-file.md
Example 3: Replacing Large Section
Step 1: Read file to find exact text
read /path/to/file.mdStep 2: Use unique markers
edit:
file_path: /path/to/file.md
oldText: "\n[old content]\n"
newText: "\n[new content]\n"
Step 3: Verify
read /path/to/file.md | grep "new content"
1. Always read before editing - Understand current state 2. Use edit for modifications - More precise than write 3. Keep changes small - Under 500 bytes per edit 4. Verify after each operation - Don't batch operations 5. Use unique markers - For complex modifications 6. Create backups - For critical files 7. Handle errors gracefully - Provide recovery strategies 8. Test incrementally - Verify each step
clawhub install file-writer