Edit File Skill
Make targeted edits to a file by finding and replacing specific text.
When to Use
Use the edit_file skill for:
- Modifying code: Change function implementations, fix bugs
- Updating configs: Change values in configuration files
- Refactoring: Rename variables, update imports
- Precise edits: Make specific changes without rewriting entire file
Input Format
{
"path": "src/config.ts",
"old_string": "const DEBUG = false;",
"new_string": "const DEBUG = true;"
}
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
path |
string | Yes | - | Path to file (relative to workspace) |
old_string |
string | Yes | - | Exact text to find |
new_string |
string | Yes | - | Replacement text |
replace_all |
boolean | No | false | Replace all occurrences |
Output Format
{
"success": true,
"output": "Edited file: src/config.ts (1 replacement made)",
"exitCode": 0
}
Important Notes
- Exact match required:
old_stringmust match exactly (including whitespace) - Unique match: For single replacement,
old_stringshould be unique in the file - Include context: If text isn't unique, include surrounding lines for context
Examples
Simple replacement
{
"path": "src/app.ts",
"old_string": "const version = '1.0.0';",
"new_string": "const version = '1.0.1';"
}
Replace all occurrences
{
"path": "src/utils.ts",
"old_string": "oldFunctionName",
"new_string": "newFunctionName",
"replace_all": true
}
Multi-line replacement
{
"path": "src/component.tsx",
"old_string": "function Button() {\n return <button>Click</button>;\n}",
"new_string": "function Button({ label }: { label: string }) {\n return <button>{label}</button>;\n}"
}
Security
- Paths are validated to stay within workspace
- Cannot edit system files
- File must exist (use write_file to create new files)