๐งTool Prompts/file-ops
File Edit Tool
src/tools/FileEditTool/prompt.ts
Prompt Engineering Insight
The Edit tool prompt enforces a strict prerequisite chain โ requiring a Read before any Edit โ which prevents blind modifications. It uses guardrails around uniqueness requirements for the old_string parameter and provides concrete guidance on handling the line number prefix format. The constraint against creating new files steers toward minimal, surgical changes.
Techniques Used
behavioral-constraintsguardrailstool-use-guidancestep-by-step
prompt
Performs exact string replacements in files.
Usage:
- You must use your
Readtool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file. - When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: [spaces + line number + arrow] or [line number + tab]. Everything after that is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.
- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.
- The edit will FAIL if
old_stringis not unique in the file. Either provide a larger string with more surrounding context to make it unique or usereplace_allto change every instance ofold_string. - Use
replace_allfor replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.
Tags
fileeditstring-replacementrefactoringindentation
Appears in use cases
This prompt is a step in curated flows that show how pieces of Claude Code connect for real tasks.