How to Use Diffs in Openclaw: A Step-by-Step Guide

Quick Start
The diffs plugin in Openclaw lets you view and apply code changes using unified diff format. This is essential for reviewing patches, comparing file versions, and understanding code modifications at a glance.
For developers working with apply_patch tool, the diffs plugin provides a visual way to inspect changes before applying them.
Enable the Plugin
Because it is an optional plugin, you must explicitly enable it in your ~/.openclaw/openclaw.json configuration file:
{ "plugins": { "entries": { "diffs": { "enabled": true } } } }
Using Diffs: Two Methods
Option A: Before and After Text
Required fields are before (original text) and after (updated text).
{ "before": "# Hello\n\nOne", "after": "# Hello\n\nTwo", "path": "docs/example.md", "mode": "view" }
Option B: Unified Patch
Required field is patch (the unified diff text).
{ "patch": "diff --git a/src/example.ts b/src/example.ts\n--- a/src/example.ts\n+++ b/src/example.ts\n@@ -1 +1 @@\n-const x = 1;\n+const x = 2;\n", "mode": "both" }
Mode Options
- view — Display the diff only
- both — Show both the patch and a side-by-side comparison
If you are automating workflows with Lobster tool, diffs can help validate changes before committing them to your repository.
Best Practices & Troubleshooting
- Always verify paths: The path field helps Openclaw locate the file context for better diff rendering.
- Handle line endings: Unified diffs are sensitive to \n vs \r\n. Normalize line endings in your before and after text.
- Large diffs: For files over 1000 lines, consider splitting into smaller chunks to improve readability.
- JSON escaping: When embedding diffs in JSON configs, properly escape backslashes and newlines.
The diffs plugin works seamlessly with Openclaw's other file tools, making it a powerful addition to your development workflow.