{"slug": "annotate-git-diff-with-explanation-generated-by-ai-for-easier-reviews", "title": "Annotate Git diff with explanation generated by AI for easier reviews", "summary": "A new open-source Git diff filter uses Claude AI to annotate every changed line with a one-sentence explanation inline in the terminal, helping developers understand code changes during interactive staging. The tool integrates with `git add -p` and can be installed via a script or manual setup, supporting models like Haiku and Sonnet for speed or quality.", "body_md": "A Git diff filter that uses Claude AI to annotate every changed line with a concise, one-sentence explanation — inline, right in your terminal.\n\n```\n-    return user.age >= 18;\n+    return user.age >= 21;   <-- 🤖 Raised the legal age threshold from 18 to 21\n```\n\nDesigned to work seamlessly with `git add -p`\n\n(interactive staging), so you understand exactly what each hunk does before you stage it.\n\nAI coding tools (Copilot, Cursor, Claude) are fast — but they generate code you didn't write and may not fully understand. When you run `git add -p`\n\nto selectively stage that output, it's easy to rubber-stamp hunks you only half-read.\n\nThis filter puts a second AI in the loop at exactly that moment. Before you decide to stage a hunk, every changed line already has a plain-English explanation attached to it — what changed, and why it matters. You stay in control without having to context-switch to read the diff cold.\n\nIt's also useful outside AI workflows: reviewing a colleague's PR locally, digging into an unfamiliar codebase, or just double-checking your own changes before a commit.\n\nThe script reads a Git diff stream from stdin, strips ANSI color codes so Claude can parse the raw text, sends the numbered diff to Claude (via the `claude`\n\nCLI), and weaves the AI-generated explanations back into the original colored output — appended inline to each changed line.\n\n[Claude Code CLI](https://claude.ai/code)— must be installed and authenticated (`claude`\n\navailable in your PATH)`bash`\n\n(v3.2+)`perl`\n\n(for ANSI stripping)`awk`\n\n(for line weaving)\n\nAll three shell tools are pre-installed on macOS and most Linux distributions.\n\n```\ncurl -fsSL https://raw.githubusercontent.com/kooskoos20/git-diff-ai-explainer-interactive-filter/main/install.sh | bash\n# Clone the repo\ngit clone https://github.com/kooskoos20/git-diff-ai-explainer-interactive-filter.git\ncd git-diff-ai-explainer-interactive-filter\n\n# Run the installer\nbash install.sh\n```\n\nOr install just the script to your PATH:\n\n```\nchmod +x git-diff-ai-explainer-interactive-filter\nsudo cp git-diff-ai-explainer-interactive-filter /usr/local/bin/\n```\n\nConfigure Git to run the filter automatically whenever you use interactive staging:\n\n```\ngit config --global interactive.diffFilter git-diff-ai-explainer-interactive-filter\n```\n\nNow every `git add -p`\n\nsession will show AI annotations inline as you step through hunks. Git passes the diff with colors already intact, so no extra flags are needed.\n\nTo apply it to a single repo only, omit `--global`\n\n.\n\nGit disables colors when stdout is a pipe, so pass `--color=always`\n\nto preserve them:\n\n```\ngit diff --color=always | git-diff-ai-explainer-interactive-filter\ngit diff --color=always HEAD~1 | git-diff-ai-explainer-interactive-filter\ngit show --color=always abc1234 | git-diff-ai-explainer-interactive-filter\n```\n\nUseful aliases to add to `~/.bashrc`\n\nor `~/.zshrc`\n\n:\n\n```\nalias gda='git diff --color=always | git-diff-ai-explainer-interactive-filter | less -R'\nalias gdca='git diff --cached --color=always | git-diff-ai-explainer-interactive-filter | less -R'\n```\n\nThe script uses Claude's `haiku`\n\nmodel by default for speed and cost efficiency. To change the model, edit line 34 in the script:\n\n```\n# Default (fast, cheap)\nCLAUDE_OUT=$(echo \"$CLAUDE_PROMPT\" | claude --model haiku)\n\n# Higher quality explanations\nCLAUDE_OUT=$(echo \"$CLAUDE_PROMPT\" | claude --model sonnet)\nrm /usr/local/bin/git-diff-ai-explainer-interactive-filter\n\n# If you configured the interactive diff filter, remove it:\ngit config --global --unset interactive.diffFilter\n```\n\nContributions are welcome! See [CONTRIBUTING.md](/kooskoos20/git-diff-ai-explainer-interactive-filter/blob/main/CONTRIBUTING.md) for guidelines.", "url": "https://wpnews.pro/news/annotate-git-diff-with-explanation-generated-by-ai-for-easier-reviews", "canonical_source": "https://github.com/kooskoos20/git-diff-ai-explainer-interactive-filter", "published_at": "2026-06-18 14:44:18+00:00", "updated_at": "2026-06-18 14:53:46.422797+00:00", "lang": "en", "topics": ["developer-tools", "large-language-models", "ai-tools", "generative-ai"], "entities": ["Claude AI", "Git", "Claude Code CLI", "Copilot", "Cursor", "Haiku", "Sonnet"], "alternates": {"html": "https://wpnews.pro/news/annotate-git-diff-with-explanation-generated-by-ai-for-easier-reviews", "markdown": "https://wpnews.pro/news/annotate-git-diff-with-explanation-generated-by-ai-for-easier-reviews.md", "text": "https://wpnews.pro/news/annotate-git-diff-with-explanation-generated-by-ai-for-easier-reviews.txt", "jsonld": "https://wpnews.pro/news/annotate-git-diff-with-explanation-generated-by-ai-for-easier-reviews.jsonld"}}