1Edits files by replacing text, creating new files, or deleting content. For moving/renaming use Bash 'mv'. For large edits use Write tool.
41. Use View tool to understand file contents and context
52. For new files: Use LS tool to verify parent directory exists
63. **CRITICAL**: Note exact whitespace, indentation, and formatting from View output
101. file_path: Absolute path to file (required)
112. old_string: Text to replace (must match exactly including whitespace/indentation)
123. new_string: Replacement text
134. replace_all: Replace all occurrences (default false)
18- Create file: provide file_path + new_string, leave old_string empty
19- Delete content: provide file_path + old_string, leave new_string empty
22<critical_requirements>
23EXACT MATCHING: The tool is extremely literal. Text must match **EXACTLY**
25- Every space and tab character
27- Every newline character
28- Indentation level (count the spaces/tabs)
29- Comment spacing (`// comment` vs `//comment`)
30- Brace positioning (`func() {` vs `func(){`)
35Expected: " func foo() {" (4 spaces)
36Provided: " func foo() {" (2 spaces) ❌ FAILS
38Expected: "}\n\nfunc bar() {" (2 newlines)
39Provided: "}\nfunc bar() {" (1 newline) ❌ FAILS
41Expected: "// Comment" (space after //)
42Provided: "//Comment" (no space) ❌ FAILS
45UNIQUENESS (when replace_all=false): old_string MUST uniquely identify target instance
47- Include 3-5 lines context BEFORE and AFTER change point
48- Include exact whitespace, indentation, surrounding code
49- If text appears multiple times, add more context to make it unique
51SINGLE INSTANCE: Tool changes ONE instance when replace_all=false
53- For multiple instances: set replace_all=true OR make separate calls with unique context
54- Plan calls carefully to avoid conflicts
56VERIFICATION BEFORE USING: Before every edit
581. View the file and locate exact target location
592. Check how many instances of target text exist
603. Copy the EXACT text including all whitespace
614. Verify you have enough context for unique identification
625. Double-check indentation matches (count spaces/tabs)
636. Plan separate calls or use replace_all for multiple changes
64 </critical_requirements>
68- old_string matches multiple locations and replace_all=false
69- old_string doesn't match exactly (including whitespace)
70- Insufficient context causes wrong instance change
71- Indentation is off by even one space
72- Missing or extra blank lines
77If you get "old_string not found in file":
791. **View the file again** at the specific location
802. **Copy more context** - include entire function if needed
813. **Check whitespace**:
82 - Count indentation spaces/tabs
83 - Look for blank lines
84 - Check for trailing spaces
854. **Verify character-by-character** that your old_string matches
865. **Never guess** - always View the file to get exact text
91- Ensure edits result in correct, idiomatic code
92- Don't leave code in broken state
93- Use absolute file paths (starting with /)
94- Use forward slashes (/) for cross-platform compatibility
95- Multiple edits to same file: send all in single message with multiple tool calls
96- **When in doubt, include MORE context rather than less**
97- Match the existing code style exactly (spaces, tabs, blank lines)
100<whitespace_checklist>
101Before submitting an edit, verify:
103- [ ] Viewed the file first
104- [ ] Counted indentation spaces/tabs
105- [ ] Included blank lines if they exist
106- [ ] Matched brace/bracket positioning
107- [ ] Included 3-5 lines of surrounding context
108- [ ] Verified text appears exactly once (or using replace_all)
109- [ ] Copied text character-for-character, not approximated
110 </whitespace_checklist>
113✅ Correct: Exact match with context
116old_string: "func ProcessData(input string) error {\n if input == \"\" {\n return errors.New(\"empty input\")\n }\n return nil\n}"
118new_string: "func ProcessData(input string) error {\n if input == \"\" {\n return errors.New(\"empty input\")\n }\n // New validation\n if len(input) > 1000 {\n return errors.New(\"input too long\")\n }\n return nil\n}"
121❌ Incorrect: Not enough context
124old_string: "return nil" // Appears many times!
127❌ Incorrect: Wrong indentation
130old_string: " if input == \"\" {" // 2 spaces
131// But file actually has: " if input == \"\" {" // 4 spaces
134✅ Correct: Including context to make unique
137old_string: "func ProcessData(input string) error {\n if input == \"\" {\n return errors.New(\"empty input\")\n }\n return nil"
144- Forward slashes work throughout (C:/path/file)
145- File permissions handled automatically
146- Line endings converted automatically (\n ↔ \r\n)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list