claude-mergetool 0.1.1

AI-powered merge conflict resolution using Claude Code
claude-mergetool-0.1.1 is not a library.

claude-mergetool

AI-powered merge conflict resolution using Claude Code. When git or jj hits a merge conflict, claude-mergetool launches Claude to read the three versions of the file, resolve the conflict, and write the result — fully automatically.

[!WARNING]

Note that claude is launched with --permission-mode=acceptEdits to the various conflicted files. With jj, these are in a temporary directory, but with git I'm not sure. There is, as always with AI tools that can touch files on your disk, some risk of unintended changes!

Install

cargo install --path .

Prerequisites

Claude Code (claude CLI) must be installed and available in PATH.

Setup

jj

Add to ~/.config/jj/config.toml:

[merge-tools.claude]
program = "claude-mergetool"
merge-args = ["merge", "$base", "$left", "$right", "-o", "$output", "-p", "$path"]

Then resolve conflicts with:

jj resolve -r <revision> --tool claude

git

Add to ~/.config/git/config (or ~/.gitconfig):

[merge "claude-mergetool"]
    name = claude-mergetool
    driver = claude-mergetool merge --git %O %A %B -s %S -x %X -y %Y -p %P -l %L

Then add a .gitattributes to your repo (or ~/.config/git/attributes for global use):

* merge=claude-mergetool

Conflicts during git merge, git rebase, git cherry-pick, etc. will automatically launch Claude.

Usage

claude-mergetool is normally invoked by git or jj, but you can also run it directly:

claude-mergetool merge base.txt left.txt right.txt -o resolved.txt

CLI reference

claude-mergetool merge [OPTIONS] <BASE> <LEFT> <RIGHT>

Arguments:
  <BASE>   Base version (common ancestor)
  <LEFT>   Left version (ours / current branch)
  <RIGHT>  Right version (theirs / incoming)

Options:
      --git              Git merge driver mode (writes result to <LEFT>)
  -o, --output <PATH>    Output file path (jj mode)
  -s <LABEL>             Ancestor conflict label
  -x <LABEL>             Left/ours conflict label [default: ours]
  -y <LABEL>             Right/theirs conflict label [default: theirs]
  -p <NAME>              Original file path (for display in prompts) [default: "unknown file"]
  -l <SIZE>              Conflict marker size

How it works

claude-mergetool runs claude in non-interactive mode (--print) with --permission-mode=acceptEdits, so tool calls (Read, Edit, Write) are auto-approved with no user interaction required. Claude's reasoning and tool calls are streamed to stderr as dimmed text so you can follow along. When Claude finishes, the merge continues automatically.