README.md

diff-review #

Review Claude Code file edits in your preferred diff tool before they are applied. Intercepts Edit and Write tool calls, constructs original/proposed temp files, and opens a configurable diff viewer.

Features #

  • Configurable diff tool with template tokens (defaults to nvim -d +{line} {path1} {path2}; works with meld, kdiff3, code --diff --wait, vimdiff, helix, etc.)
  • Jumps to the first changed line via a {line} token in the command
  • Context block: extracts Claude's reasoning from the transcript and shows it inline in the diff (top, bottom, or both), so you see why the change is being made
  • Smart decision mode: vim-family tools use exit code (:qa to accept, :cq to reject), GUI tools prompt for confirmation
  • Smart display mode: auto-detects tmux/zellij and opens terminal tools in a popup overlay
  • Opens diffs in the file's directory so you can navigate sibling files and the project tree
  • XDG-compliant JSON config file with environment variable overrides
  • Mid-session toggle via a sentinel file (no restart needed)
  • Secure temp file handling (random names, mode 0600, automatic cleanup)

Quick start #

# Install the plugin
/plugin install diff-review@jcmuller-plugins

# Seed a config file (optional, defaults work out of the box)
~/.claude/plugins/diff-review/scripts/diff-review.sh --init

Accept and reject #

How you accept or reject depends on your diff tool:

Tool Accept Reject
nvim / vim / vimdiff :qa (exit 0) :cq (exit 1)
helix :q (exit 0) :q! with error
meld, kdiff3, VS Code Close the window Claude Code prompts for confirmation

The plugin auto-detects which tools support exit-code rejection and falls back to a confirmation prompt for the rest.

Configuration #

Config file #

Location: ${XDG_CONFIG_HOME:-~/.config}/claude-diff-review/config.json

{
  "enabled": true,
  "command": "nvim -d +{line} {path1} {path2}",
  "context": "bottom",
  "decision": "auto",
  "display": "auto",
  "exclude": []
}

All fields are optional. Run --init to create a config file with defaults.

Command template tokens #

The command field takes placeholder tokens so you can shape it around your editor. Drop every path token and the two paths get appended at the end, which is what "nvim -d" already does.

Token Expands to
{line} 1-based line number of the change
{path1} left (read-only) pane path
{path1-with-line} {path1}:{line}
{path2} right (editable) pane path
{path2-with-line} {path2}:{line}

{line} is the first line where the Edit tool's old_string matches. For Write, new files, or no match, it is 1.

Examples:

nvim -d +{line} {path1} {path2}          # default: jump to that line in both panes
nvim -d {path1-with-line} {path2}        # editors that parse file:line on argv
code --diff --wait --goto {path2-with-line} {path1}

Environment variables #

Environment variables override the config file.

Variable Default Description
CLAUDE_DIFF_CMD nvim -d +{line} {path1} {path2} Diff command (supports token substitution)
CLAUDE_DIFF_CONFIG (XDG default) Alternate config file path
CLAUDE_DIFF_CONTEXT bottom Placement: top, bottom, both, none. Also accepts true/1 (top) and false/0 (none).
CLAUDE_DIFF_DECISION auto Decision mode: auto, ask, exit-code
CLAUDE_DIFF_DISPLAY auto Display strategy: auto, direct, tmux-popup, tmux-split, zellij-float
CLAUDE_DIFF_ENABLED 1 Set to 0 to disable the hook

Decision modes #

Mode Behavior
auto Detects tool: exit-code for vim-family/helix/kakoune, ask for everything else
ask Always prompts for confirmation in Claude Code after closing the diff tool
exit-code Diff tool exit 0 = allow, non-zero = deny

Display strategies #

All strategies set the working directory to the edited file's parent directory, so you can navigate sibling files and the project tree from inside the diff tool.

Strategy Behavior
auto tmux popup if $TMUX set, else zellij float if $ZELLIJ set, else direct
direct Run command directly (blocks terminal or opens GUI window)
tmux-popup tmux display-popup -E -w 90% -h 90%
tmux-split tmux split-window -h
zellij-float zellij run --floating --width=80% --height=80% --close-on-exit

Context #

The plugin grabs Claude's last transcript message, wraps it in sentinel-bracketed comment lines, and writes that block into the file under review. Both panes of the diff get the same bytes so the gutter stays lined up. When the diff tool exits, the block is stripped back out of the real file.

Comment prefix depends on extension: // for Go/JS/TS/Rust, # for Python/Ruby/Shell/Nix/Markdown, -- for Lua/SQL, and so on. In tmux-popup mode the same text doubles as the popup border title.

Set placement with context in the config or CLAUDE_DIFF_CONTEXT:

Value Behavior
bottom (default) Append the block to the end of both panes
top Prepend; cursor-jump line shifts to compensate
both Prepend and append
none Skip context entirely

Legacy booleans still work: "context": true maps to top, false to none. The env var accepts the same values as strings (1, true, 0, false).

Exclude #

Anything matching a pattern in exclude skips the hook outright. The diff tool does not open, the edit goes through as-is. Handy for lockfiles, generated code, or files you would rather not review every time.

{ "exclude": ["/home/you/repo/vendor/*", "*/generated/*.go"] }

Matching uses Go's filepath.Match against the full path. * does not cross a path separator and there is no **. For deeper matches, stack segments (*/*/*.pb.go).

Plan files under ~/.claude/plans/ are excluded automatically, regardless of what is in this list.

Mid-session toggle #

Disable or re-enable the hook during a live Claude Code session:

# Disable
touch ~/.config/claude-diff-review/disabled

# Re-enable
rm ~/.config/claude-diff-review/disabled

Dependencies #

Binary Purpose Required?
jq JSON parsing and string substitution Yes
Diff tool Configured via CLAUDE_DIFF_CMD Yes (default: nvim)
tmux Popup/split display Only if using tmux display
zellij Floating pane display Only if using zellij display

Installation #

/plugin install diff-review@jcmuller-plugins