Skip to main content
The Text Diff Checker compares two text inputs and highlights the differences between them. It’s essential for code reviews, content comparison, debugging changes, and generating patches.

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 the diff 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 with git apply, patch, and version control systems:
--- input
+++ input
@@ -1,3 +1,3 @@
 Line 1
-Old line
+New line
 Line 3

Input Format

Left Input (Original):
Hello World
This is line 2
Line 3 remains
Right Input (Modified):
Hello World
This is line 2 (edited)
Line 3 remains
New line 4

Output Format

Line Diff (Default)

  Hello World
- This is line 2
+ This is line 2 (edited)
  Line 3 remains
+ New line 4

Unified Patch

--- input
+++ input
@@ -1,3 +1,4 @@
 Hello World
-This is line 2
+This is line 2 (edited)
 Line 3 remains
+New line 4

Examples

Left Input:
function greet(name) {
  console.log("Hello " + name);
}

Right Input:
function greet(name) {
  console.log(`Hello ${name}`);
}

Output (Line Diff):
  function greet(name) {
-   console.log("Hello " + name);
+   console.log(`Hello ${name}`);
  }

Technical Details

Located in lib/tools/engine.ts:486-495
The tool uses the diff package (v8.0.3) with two functions:

diffLines (Default Mode)

Performs line-by-line comparison and returns an array of change objects:
import { diffLines } from 'diff';

const changes = diffLines(leftInput, rightInput);
// Each change has: { value: string, added?: boolean, removed?: boolean }

createPatch (Patch Mode)

Generates a unified diff patch:
import { createPatch } from 'diff';

const patch = createPatch('input', leftInput, rightInput);
// Returns a unified diff string compatible with `patch` command

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
Large inputs (10,000+ lines) may cause brief UI freezes. For massive files, consider chunking or using a dedicated diff service.

Understanding Diff Output

Hunk Headers (Patch Mode)

The @@ lines indicate line ranges:
@@ -1,3 +1,4 @@
  • -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

// Before
const sum = (a, b) => a + b;
const result = sum(2, 3);

// After
const sum = (a, b) => a + b;
const multiply = (a, b) => a * b;
const result = multiply(2, 3);

// Diff shows added `multiply` function and changed `sum` to `multiply` call

Environment Config Comparison

# .env.development
DATABASE_URL=localhost
API_TIMEOUT=5000

# .env.production
DATABASE_URL=prod-db.example.com
API_TIMEOUT=30000
CACHE_TTL=3600

Git Patch Application

  1. Generate patch with Patch action
  2. Save output to changes.patch
  3. Apply with git apply changes.patch or patch < changes.patch

Comparison with Other Tools

FeatureText Diffgit diffList 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.

Build docs developers (and LLMs) love