Language: Always interact with the user in 日本語.
resolve-conflicts-en
Resolve PR conflicts safely in an isolated worktree.
Prerequisites
- Claude Code environment
git,ghCLI
Arguments
- PR number (e.g.,
/resolve-conflicts-en #123or/resolve-conflicts-en 123) - PR URL (e.g.,
/resolve-conflicts-en https://github.com/owner/repo/pull/123) - No arguments: Ask user for PR number
Phase 1: Retrieve PR Info and Create Worktree
- Identify the PR from arguments
gh pr view <number-or-URL> --json number,title,baseRefName,headRefName,headRepository,headRepositoryOwner,mergeable,url- No arguments: Ask user for PR number
- Display and confirm PR info
- PR title, base branch, head branch, conflict status
- If mergeable is not
CONFLICTING: Report no conflicts and exit
- Record base branch and head branch
- Confirm resolution strategy with user (AskUserQuestion)
- rebase (recommended): Rebase head branch onto base branch. Clean history. Requires
--force-with-leaseon push - merge: Merge base branch into head branch. Adds a merge commit. Regular push
- rebase (recommended): Rebase head branch onto base branch. Clean history. Requires
- Create git worktree (see
references/worktree-setup.md)- Branch name:
resolve/<PR-number>(e.g.,resolve/#123) - After worktree creation, checkout head branch content:
cd <worktree-path> git fetch origin git reset --hard origin/<head-branch>
- Branch name:
Phase 2: Resolve Conflicts
IMPORTANT: All operations must be inside the worktree directory.
Rebase Strategy
- Start rebase inside worktree
git rebase origin/<base-branch> - Check conflicting files
git diff --name-only --diff-filter=U - For each conflicting file:
a. Read the full file with Read (including conflict markers)
b. Understand base branch change intent (
git log origin/<base-branch> -- <file>for recent changes) c. Understand head branch change intent (git log HEAD -- <file>for recent changes) d. Resolve by preserving both change intents. Ask user when uncertain e. Resolve conflict markers with Edit f. Stage withgit add <file> - After all conflicts resolved:
git rebase --continue - If new conflicts arise, repeat steps 2-4
- Repeat until rebase is complete
Merge Strategy
- Start merge inside worktree
git merge origin/<base-branch> - Check conflicting files (same as rebase steps 2-3)
- Resolve each conflict (same as rebase steps 3a-3f)
- After all conflicts resolved:
git add . git commit # Create merge commit
Resolution Guidelines
- Preserve both changes: Integrate both sides whenever possible
- Prioritize intent: Understand change intent, not just line-level differences
- Ask user when uncertain: Always ask when business logic judgment is needed
- Run tests/type checks: Verify tests and type checks pass after resolution
Phase 3: Verify and Push
- Run build/tests (inside worktree directory)
- Run test command if project has one
- If failures, fix and commit
- Push (inside worktree directory)
- Rebase strategy:
git push origin HEAD:<head-branch> --force-with-lease - Merge strategy:
git push origin HEAD:<head-branch>
- Rebase strategy:
- Confirm PR conflict status
- Verify MERGEABLE with
gh pr view <number> --json mergeable
- Verify MERGEABLE with
- Report resolution summary and worktree path to user
Report example:
## Done
- PR: <URL>
- Strategy: rebase / merge
- Resolved files: N
- path/to/file1.ts: Integrated both changes
- path/to/file2.ts: Added new imports from base
- Worktree: <path> (run `git worktree remove <path>` after verification)
Rules
- Make no changes beyond conflict resolution
- Ask user when business logic judgment is needed
- Use
--force-with-leaseto avoid overwriting others' commits - All git/file operations must be inside the worktree directory. Never modify the main working tree.
- Get user confirmation before pushing (especially for rebase + force push)