File Operations
When to Use
Invoke this skill for any task involving the file system:
- Creating or writing new files with specific content
- Reading or viewing existing file contents
- Editing, updating, or overwriting existing files
- Renaming, moving, or copying files and directories
- Deleting files or directories (with confirmation for destructive ops)
- Finding files by name pattern or content
- Listing and exploring directory structures
- Batch file operations across multiple files
Procedures
Creating a File
- Confirm the target path (absolute or workspace-relative).
- Check if the file already exists — warn before overwriting.
- Write the content using the
create_filetool. - Verify the file was created with a follow-up read or directory listing.
Editing an Existing File
- Read first: Always read the file before editing to understand context.
- Use
replace_string_in_filefor targeted edits (include 3–5 lines of context around the change). - Use
multi_replace_string_in_filewhen making multiple independent changes at once. - After editing, validate the result (re-read the changed section or check for errors).
Finding Files
- Use
file_searchwith a glob pattern when you know the filename pattern (e.g.**/*.json). - Use
grep_searchwhen searching by file content or a string inside files. - Use
list_dirto explore a specific directory's contents. - Combine glob + grep for pattern-based content searches across matched files.
Moving / Renaming Files
- Use the terminal with
mv <source> <destination>(reversible within the workspace). - For renames that affect imports or references, search for all usages first.
- Confirm with the user before moving files outside the workspace.
Deleting Files
Requires confirmation — deletion is not easily reversible.
- List the files to be deleted and present them to the user for review.
- Use
rm(file) orrm -rf(directory) ONLY after explicit user confirmation. - Prefer moving to a backup location over permanent deletion when in doubt.
Organizing a Directory
- Use
list_dirto audit the current structure. - Propose a new structure to the user before making changes.
- Use
mvcommands in the terminal, batched where possible. - Update any references (imports, configs, paths) affected by the reorganization.
Key Principles
- Read before write: Never edit a file without reading it first.
- Reversibility: Prefer edits and moves over deletions. Ask before destructive ops.
- Absolute paths: Always use absolute paths in tool calls.
- Batch parallel reads: When checking multiple files, read them in parallel.
- Validate after write: After creating or editing, confirm the result is correct.
Examples
Create a config file:
/file create a .env.example with DATABASE_URL, API_KEY, and DEBUG vars
Find all test files:
/file find all test files under workspace/
Reorganize a directory:
/file move all *.log files in /tmp into /tmp/logs/
Bulk edit:
/file replace all occurrences of "localhost:8080" with "localhost:3000" in config files