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
claudeis launched with--permission-mode=acceptEditsto the various conflicted files. Withjj, these are in a temporary directory, but withgitI'm not sure. There is, as always with AI tools that can touch files on your disk, some risk of unintended changes!
Install
Prerequisites
Claude Code (claude CLI) must be installed and available in PATH.
Setup
jj
Add to ~/.config/jj/config.toml:
[]
= "claude-mergetool"
= ["merge", "$base", "$left", "$right", "-o", "$output", "-p", "$path"]
Then resolve conflicts with:
git
Add to ~/.config/git/config (or ~/.gitconfig):
[mergetool "claude"]
cmd = claude-mergetool merge "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"
trustExitCode = true
Then resolve conflicts with:
Usage
claude-mergetool is normally invoked by git or jj, but you can also run it directly:
CLI reference
Usage: 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-merge-driver Git merge driver mode (writes result to `<left>` path)
-o, --output <OUTPUT> Output file path (jj mode)
-s <ANCESTOR_LABEL> Ancestor conflict label
-x <LEFT_LABEL> Left/ours conflict label [default: ours]
-y <RIGHT_LABEL> Right/theirs conflict label [default: theirs]
-p <FILEPATH> Original file path [default: "unknown file"]
-l <MARKER_SIZE> Conflict marker size
-h, --help Print help
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.