Token Efficiency Encyclopedia

Diff-Based Tool Output

When a tool edits a file, return only the changed lines or a unified diff instead of the full file content. The model does not need to re-read the entire file to understand the modification.

How It Works

The tool computes the diff between the original and modified file states and returns that diff in a standard format (unified diff, git diff, or structured patch). The model receives a compact representation that highlights exactly what changed.

Benefits

Example

Instead of returning 500 lines of file content after an edit:

{
  "file": "file.py",
  "diff": "@@ -10,3 +10,4 @@\n def foo():\n+    pass\n"
}

See Also

Tools