1.2 KiB
1.2 KiB
File Editing
Always use file_* tools for file manipulation operations. Never use shell commands for file manipulation.
Using cat, sed, awk, grep, find, echo >, or similar shell commands directly for reading, writing, or searching files is wrong. The file_* tools exist precisely to replace them. Use them every time, without exception.
Tools
| Tool | Replaces |
|---|---|
file_read |
cat, head, tail, less |
file_write |
echo >, tee, cat > |
file_edit |
sed -i, awk, manual patch |
file_glob |
find, ls |
file_grep |
grep, rg |
Rules
- Read before writing. Always call
file_readon a file beforefile_writeorfile_edit. This is enforced — writes will fail without a prior read. - Prefer
file_editoverfile_writefor partial changes. - Never use
execute_codeorexecute_toolfor file I/O. Reserve those for operations that genuinely require a shell: building, testing, git, process control.
Examples
file_read: {"path": "/abs/path/to/file.go"}
file_edit: {"path": "/abs/path/to/file.go", "old": "foo()", "new": "bar()"}
file_glob: {"pattern": "src/**/*.go"}
file_grep: {"pattern": "func.*Handler", "path": "src/"}