cleanDiff
Compact git diff as structured JSON
Git diff output as structured JSON with only changed lines. No context padding by default. Use for token-efficient diff review in AI workflows.
Features
- Structured JSON output with changed lines grouped by file
- Zero context lines by default (configurable)
- Stat-only mode for file-level overview
- Filter by specific files
- Support for staged changes and commit ranges
Install
go install github.com/hegner123/cleanDiff@latestThe Problem: git diff is verbose and unstructured
$ git diff HEAD~1
diff --git a/main.go b/main.go
index abc1234..def5678 100644
--- a/main.go
+++ b/main.go
@@ -10,7 +10,7 @@ func main() {
ctx := context.Background()
cfg := loadConfig()
db := connectDB(cfg)
- srv := newServer(db)
+ srv := newServer(db, cfg.Logger)
srv.Start(ctx)
}
# 7 lines of context for 1 changed line.
# Multiply by 20 files = massive token waste.Solution
$ cleanDiff --cli --ref HEAD~1Output
{"summary":{"files_changed":1,"insertions":1,"deletions":1},"files":[{"path":"main.go","status":"modified","hunks":[{"old_start":13,"new_start":13,"lines":["- srv := newServer(db)","+ srv := newServer(db, cfg.Logger)"]}]}]}Comparison
| Metric | Value |
|---|---|
| Context reduction | Zero padding by default (git diff uses 3 lines) |
| Output format | Structured JSON vs raw unified diff |
| Filtering | By file path, staged only, commit range |