Use Cases
- Code reviews - Compare original vs. modified code
- Document versioning - Track changes between drafts
- Configuration audits - Compare production vs. staging configs
- Debugging - Identify unintended changes in output
- Patch generation - Create unified diff patches for version control
- API response comparison - Validate API changes between versions
How It Works
The tool uses thediff library (same algorithm as Unix diff) to perform line-by-line comparison:
- Left Input: Original text (“before”)
- Right Input: Modified text (“after”)
- Output: Color-coded diff showing additions, deletions, and unchanged lines
The tool compares text line-by-line, not character-by-character. For single-line changes, use a character-level diff tool or inspect the output carefully.
Actions
Default (Line Diff)
Shows a simplified diff with markers:+prefix: Lines added in the right input-prefix: Lines removed from the left input(space) prefix: Unchanged lines
Patch (Unified Diff)
Generates a unified diff patch compatible withgit apply, patch, and version control systems:
Input Format
Left Input (Original):Output Format
Line Diff (Default)
Unified Patch
Examples
Technical Details
Located in
lib/tools/engine.ts:486-495diff package (v8.0.3) with two functions:
diffLines (Default Mode)
Performs line-by-line comparison and returns an array of change objects:
createPatch (Patch Mode)
Generates a unified diff patch:
Performance
- Algorithm: Myers’ diff algorithm (O(ND) complexity, where N is input size and D is edit distance)
- Line-based comparison: Fast for large files with localized changes
- Synchronous processing: All operations run client-side
Understanding Diff Output
Hunk Headers (Patch Mode)
The@@ lines indicate line ranges:
-1,3: Original text starts at line 1, spans 3 lines+1,4: Modified text starts at line 1, spans 4 lines
Context Lines
Both modes show 3 lines of context around changes by default (unchanged lines before/after the diff).Common Patterns
Before/After Code Review
Environment Config Comparison
Git Patch Application
- Generate patch with Patch action
- Save output to
changes.patch - Apply with
git apply changes.patchorpatch < changes.patch
Comparison with Other Tools
| Feature | Text Diff | git diff | List Compare |
|---|---|---|---|
| Line-by-line | ✅ | ✅ | ❌ |
| Patch generation | ✅ | ✅ | ❌ |
| Set operations | ❌ | ❌ | ✅ |
| Fuzzy matching | ❌ | ❌ | ✅ |
| Word-level diff | ❌ | ✅ (—word-diff) | ❌ |
Use Text Diff for code and structured text. Use List Compare for comparing lists of items (emails, IDs, etc.) with set operations.
Related Tools
- List Compare - Compare lists with intersection/union/diff
- JSON Format/Validate - Format JSON before diffing
- Line Sort/Dedupe - Sort lines before comparison