This document describes Windsurf Cascade's file editing mechanism using the replace_file_content tool and its distinctive ReplacementChunks architecture. This system enables precise, multi-location edits within a single file through one atomic tool call, optimizing performance while maintaining edit safety.
For broader file operation context within Windsurf, see Tool Ecosystem and Categories. For file creation operations, see the write_to_file tool documented in the same section. For validation of edits, see Memory and Context Management.
The replace_file_content tool implements a chunk-based editing strategy that differs fundamentally from line-based or full-file replacement approaches used by other AI assistants. Instead of replacing entire files or requiring sequential edits, ReplacementChunks allow multiple non-adjacent modifications in a single atomic operation.
Sources: Windsurf/Tools Wave 11.txt231-260
The replace_file_content tool is the primary mechanism for modifying existing files in Windsurf Cascade. It accepts a target file path and an array of replacement chunks that specify exact string matches and their replacements.
| Parameter | Type | Required | Description |
|---|---|---|---|
toolSummary | string | Yes | Brief 2-5 word summary (MUST be first argument) |
TargetFile | string | Yes | Absolute path to file (MUST be second argument) |
ReplacementChunks | Array | Yes | JSON array of edits (not a string) |
Instruction | string | Yes | Description of changes being made |
CodeMarkdownLanguage | string | Yes | Language identifier (e.g., 'python', 'javascript') |
TargetLintErrorIds | string[] | No | IDs of lint errors this edit aims to fix |
The tool enforces strict argument ordering to optimize streaming and memory usage:
toolSummary - enables immediate UI feedbackTargetFile - allows early file access and validationSources: Windsurf/Tools Wave 11.txt231-260
Each ReplacementChunk represents a single edit operation within the target file. Multiple chunks enable non-contiguous edits without retransmitting unchanged portions.
| Field | Type | Purpose | Critical Notes |
|---|---|---|---|
TargetContent | string | Exact substring to find and replace | Must include ALL whitespace, including leading spaces/tabs |
ReplacementContent | string | New content to insert | Complete replacement, not a diff |
AllowMultiple | boolean | Whether to replace multiple occurrences | If false and multiple matches exist, returns error |
The TargetContent field requires character-perfect matching:
AllowMultiple is false, the substring must be unique within the fileSources: Windsurf/Tools Wave 11.txt244-253
No Parallel Calls for Same File
Single Call for Multiple Edits
ReplacementChunks in one arrayExact Target Matching
TargetContent must be verbatim from fileComplete Replacement Content
ReplacementContent is drop-in replacement, not a patchMultiple Chunks for Non-Adjacent Edits
ReplacementChunk for each edit locationNo Full File Replacement
Cannot edit files with extension: .ipynb (Jupyter notebooks)
For notebook editing, use specialized tools or manual procedures.
Sources: Windsurf/Tools Wave 11.txt231-236
Sources: Windsurf/Tools Wave 11.txt244-253
The replace_file_content tool integrates with Windsurf's broader validation and error correction system through the optional TargetLintErrorIds parameter.
| Scenario | Include Lint IDs? | Rationale |
|---|---|---|
| Edit fixes reported syntax error | Yes | Direct relationship to lint feedback |
| Edit addresses type mismatch warning | Yes | Influenced by lint output |
| Refactoring for performance | No | Unrelated to linting |
| Adding new feature | No | No existing errors being fixed |
| Edit influenced by error message | Yes | "Rule of thumb: if edit was influenced by lint feedback, include" |
Guidance from specification: "Exercise honest judgement here."
Sources: Windsurf/Tools Wave 11.txt256-257
| System | Primary Tool | Strategy | Key Constraint |
|---|---|---|---|
| Windsurf | replace_file_content | ReplacementChunks (multiple non-adjacent) | No parallel calls to same file |
| Qoder | search_replace | String search and replace (preferred) | $100M penalty for using edit_file when search_replace works |
| Same.dev | edit_file / string_replace | Line threshold: 2500 lines | Must read file first (except small appends) |
| Lovable | lov-line-replace | Line-based with ellipsis | Read with lov-view first |
| VSCode Agent | insert_edit_into_file | Minimal code repetition | Mandatory read-before-edit |
| v0 | Quick edit comments | // ... existing code ... placeholders | Minimal transmission philosophy |
| Approach | Round Trips | Token Efficiency | Error Surface | Best For |
|---|---|---|---|---|
| ReplacementChunks | 1 | High (only changed sections) | Low (exact matching) | Multiple scattered edits |
| Full file replacement | 1 | Low (entire file) | High (must regenerate all) | Complete rewrites |
| Sequential edits | N | Medium | Medium (cumulative state) | Dependent changes |
| Line-based | 1-N | High | Medium | Targeted line changes |
Sources: Windsurf/Tools Wave 11.txt231-260 High-level architecture diagrams (Diagram 7)
When replace_file_content fails:
view_file tool to verify exact contentSources: Windsurf/Tools Wave 11.txt231-260
write_to_file instead)view_file to capture exact contentTargetContentReplacementContent is complete, compilable codeAllowMultiple appropriately based on expected matchesDO:
TargetContent that uniquely identifies locationTargetLintErrorIds when fixing reported issuesInstruction for future referenceDON'T:
TargetContentThe ReplacementChunks approach provides atomicity:
Sources: Windsurf/Tools Wave 11.txt231-260
The replace_file_content tool operates within a broader file operation ecosystem:
| Tool | Purpose | Relationship |
|---|---|---|
view_file | Read file sections | Use before replace_file_content to get exact content |
write_to_file | Create new files | Use instead of replace_file_content for new files |
list_dir | Directory contents | Discover files before editing |
codebase_search | Semantic code search | Find code locations before editing |
grep_search | Exact pattern matching | Identify edit targets precisely |
view_code_item | View specific symbols | Get exact function/class content for replacement |
For terminal-related operations after editing, see Command Execution and Background Processes.
Sources: Windsurf/Tools Wave 11.txt1-368
Windsurf's replace_file_content tool with ReplacementChunks represents an optimized file editing strategy that balances:
The ReplacementChunks architecture distinguishes Windsurf from other systems by enabling multiple non-adjacent edits in one atomic operation, avoiding both the latency of sequential edits and the expense of full-file replacement.
Sources: Windsurf/Tools Wave 11.txt231-260
Refresh this wiki