replace_in_file tool. Make targeted changes to specific functions, variables, or code sections without rewriting entire files.

How It Works
Inline Editing uses a SEARCH/REPLACE block pattern for precise modifications:- Searches for the exact code block in the file
- Replaces it with the modified version
- Preserves surrounding code untouched
- Handles auto-formatting automatically
Inline Editing is powered by the
replace_in_file tool, designed for efficiency and precision.When to Use Inline Editing
Inline Editing excels at:Function Updates
Modify function implementations, signatures, or logic
Variable Renames
Change variable names throughout a file
Import Statements
Add, remove, or modify imports
Type Annotations
Add TypeScript types to existing code
Bug Fixes
Fix specific issues without touching working code
Refactoring
Update patterns across a file
SEARCH/REPLACE Syntax
Single Block
Modify one section of code:Multiple Blocks
Make several changes in one operation:src/core/prompts/system-prompt/components/editing_files.ts:75
Inline Editing vs write_to_file
- replace_in_file (Inline)
- write_to_file (Full Rewrite)
Use when:
- Making small, localized changes
- Updating specific functions or sections
- File content is mostly unchanged
- You need surgical precision
- More efficient (no need to send full file)
- Lower chance of errors
- Preserves unchanged sections perfectly
- Safer for large files
- Fix a bug in one function
- Add a new import
- Update variable names
- Modify configuration values
src/core/prompts/system-prompt/components/editing_files.ts:59
Auto-Formatting Handling
Inline Editing intelligently handles editor auto-formatting:Editor Formats
Your editor (Prettier, ESLint, etc.) auto-formats the file:
- Adjusts indentation
- Converts quotes
- Organizes imports
- Adds/removes semicolons
Critical: The AI must use the post-formatting content for subsequent SEARCH blocks. This is especially important when making multiple edits to the same file.
src/core/prompts/system-prompt/components/editing_files.ts:5
Auto-Formatting Examples
Common transformations your editor might apply:Indentation
Indentation
Before (AI writes):After (Editor formats with 2 spaces):
Quote Style
Quote Style
Before:After (Prettier with single quotes):
Import Organization
Import Organization
Before:After (Sorted and grouped):
Trailing Commas
Trailing Commas
Before:After (With trailing commas):
Best Practices
Be Specific in SEARCH Blocks
- ❌ Too Generic
- ✅ Specific
Include Surrounding Context
- ❌ Minimal Context
- ✅ Rich Context
Handle Edge Cases
Multiple Similar Sections
Multiple Similar Sections
If a file has similar code blocks, include unique identifiers:The comment makes it unique from other
validate functions.Dynamic Content
Dynamic Content
Avoid SEARCH blocks with timestamps or IDs:❌
<SEARCH>const id = 12345</SEARCH>✅ <SEARCH>const id = userId // Current user</SEARCH>Whitespace Sensitivity
Whitespace Sensitivity
Match exact whitespace in SEARCH blocks:
Workflow Tips
See:
src/core/prompts/system-prompt/components/editing_files.ts:71
Advanced Techniques
Multi-Line Replacements
Replace entire blocks while preserving structure:Conditional Logic Updates
Modify complex conditional statements:Pattern Replacements
Change recurring patterns:Common Use Cases
Add TypeScript Types
Update Imports
Fix ESLint Issues
Refactor Function Names
Error Handling
Search Block Not Found
Error:SEARCH block not found in file
Causes:
- Whitespace mismatch
- File was auto-formatted since last read
- Searching for old content
- Read the file again to get current state
- Copy exact content including whitespace
- Use more surrounding context
Multiple Matches Found
Error:SEARCH block matches multiple locations
Solution:
- Add more context to make the match unique
- Include function name, comments, or surrounding code
- Use variable names or string literals as anchors
File Changed Externally
Error:File modified externally during operation
Solution:
- Refresh file content
- Retry the operation
- Use version control to resolve conflicts
Performance Considerations
- Efficiency
- Accuracy
Inline Editing is faster because:
- Sends only SEARCH/REPLACE blocks
- Doesn’t need full file content
- Less token usage
- Faster processing
- Full file: 500 lines = ~15,000 tokens
- Inline edit: 20 lines = ~600 tokens
- 25x reduction in tokens
Configuration
Editor Settings
Configure your editor for optimal inline editing:Ignore Formatting
For CLI environments with no auto-formatting:src/core/prompts/system-prompt/components/editing_files.ts:84
Troubleshooting
Edits not applying
Edits not applying
- Verify file isn’t read-only
- Check file permissions
- Ensure no syntax errors in REPLACE block
- Confirm SEARCH block exactly matches file content
Wrong section replaced
Wrong section replaced
- Add more context to SEARCH block
- Include unique identifiers (comments, variable names)
- Read file first to verify current state
- Use function/class names as anchors
Formatting conflicts
Formatting conflicts
- Disable auto-format temporarily
- Match current file formatting in SEARCH blocks
- Use the post-format content from tool responses
- Configure consistent formatting rules
Next Steps
AI-Powered Coding
Learn how the AI decides when to use inline editing
File Identification
Discover files to edit with smart search
Auto Approve
Auto-approve safe inline edits for faster workflows
Checkpoints
Roll back inline edits if needed