diff
Files
SKILL.mdagentsreferencesscripts
Install
Install the containing plugin
/plugin install shared-skills@llm-skills
Invoke this skill after installation
/shared-skills:diff
This skill is bundled inside shared-skills. Install the plugin once, then Claude Code can use any of its included skills. Browse the full plugin repository at github.com/alisonaquinas/llm-shared-skills.
SKILL.md
name: diff description: Compare files and directories line-by-line with diff for detecting changes, generating patches, and reviewing modifications. Use when the agent needs to show differences between versions, generate unified diffs for version control, or verify file identity.
diff
Compare files and directories line-by-line to detect changes and generate patches.
Quick Start
- Verify
diffis available:diff --versionorman diff - Establish the command surface:
man diffordiff --help - Start with a read-only comparison:
diff file1.txt file2.txt
Intent Router
Load only the reference file needed for the active request.
references/install-and-setup.md— Installing diff (GNU, BSD) on macOS, Linux, Windowsreferences/cheatsheet.md— Common flags, unified diffs, context diffs, side-by-side output, patch generationreferences/advanced-usage.md— Recursive directory comparison, ignore patterns, patch application, three-way merge, performancereferences/troubleshooting.md— Binary file detection, line ending differences (CRLF vs LF), encoding issues, exit codes
Core Workflow
- Verify diff variant (GNU or BSD):
diff --versionorman diff - Choose comparison format: unified (
-u), context (-c), or normal output - Run read-only comparison first:
diff file1 file2to see changes - For patches, use unified format:
diff -u original modified > changes.patch - Verify patch applies cleanly before merging:
patch --dry-run < changes.patch
Quick Command Reference
diff --version # Check version (GNU vs BSD)
diff file1 file2 # Show line-by-line differences
diff -u file1 file2 # Unified format (readable, useful for patches)
diff -c file1 file2 # Context format (3 lines of context)
diff -y file1 file2 # Side-by-side comparison
diff -u file1 file2 > changes.patch # Generate patch file
diff -r dir1 dir2 # Recursively compare directories
diff -i file1 file2 # Ignore case differences
diff --ignore-all-space file1 file2 # Ignore whitespace
man diff # Full manual and options
Safety Notes
| Area | Guardrail |
|---|---|
| Line endings | Windows (CRLF) vs Unix (LF) differences can obscure real changes. Use --ignore-all-space or normalize with dos2unix first. |
| Binary files | diff marks binary files as "Binary files ... differ" and does not show content. Use xxd, hexdump, or cmp for binary inspection. |
| Large files | Comparing very large files (>100 MB) can be slow. Use cmp for byte-level checking or diff -q for existence check. |
| Patch direction | Patches are directional: diff -u original modified (old → new). Reversed order creates inverting patch (-R). |
| Character encoding | diff may produce garbled output for non-UTF-8 files. Convert with iconv or check with file. |
| Exit codes | Exit 0 (identical), 1 (differ), 2 (error). Scripts must check $? carefully. |
Source Policy
- Treat the installed
diffbehavior andman diffas runtime truth. - Use GNU Coreutils documentation (gnu.org/software/diffutils) for GNU-specific features.
- Use BSD diff manual for BSD variant behavior differences.
Resource Index
scripts/install.sh— Install diff (GNU diffutils) on macOS or Linux.scripts/install.ps1— Install diff on Windows or any platform via PowerShell.