agentleFS
vltingvlting/claude-skills/skills/merge/SKILL.md

merge

Skill2 starsChanged 9 months agoMITView on GitHub

List active do/* worktrees and merge the chosen one into its origin branch, gated by a user-supplied approval token.

  • Deletes or force-pushes

26 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use fix, report and 5 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Google CloudSkill

    fix

    Plan a remediation strategy after a test failure.

    Also in 3 projects that use this

  • MicrosoftSkill

    report

    Turn an exploration (threads, findings, charts) into a single Markdown report — note, blog post, executive summary, KPI dashboard, slide brief, or multi-section analytical report, with embedded charts.

    Also in 3 projects that use this

  • Microsoft AzureSkill

    test

    Also in 3 projects that use this

  • SentrySkill

    review

    Fixture review skill.

    Also in 5 projects that use this

  • DockerSkill

    research

    Research a documentation topic — locate affected files, understand the problem, identify what to change. Use when investigating an issue, a question, or a topic before writing a fix. Triggers on: "research issue 1234", "investigate what needs changing for #500", "what files are affected by #200", "where is X documented", "is our docs page about Y accurate", "look into how we document Z".

    Also in 3 projects that use this

  • VercelSkill

    find-skills

    Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

9 rules. 0 are common, 4 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 23 edited versions we read keep these.

  • 4

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Use the payload.origin_branch from the session to know the target branch.

    line 48
  2. Very specific:

    If no do/* branches exist, tell the user and exit.

    line 50
  3. Distinctive:

    If only one worktree exists, skip this step and auto-select it.

    line 57
  4. Distinctive:

    If the dialog is cancelled, stop and say "Merge cancelled."

    line 81
  5. Distinctive:

    If the hook rejects any command, surface the hook's error message and tell the user to generate a fresh token (tokens expire every 2 …

    line 121
  6. Very specific:

    Never bypass the hook: Do not try --no-verify, alternative git paths, or filesystem manipulation.

    line 139
  7. Very specific:

    Never read or reference ~/.claude-merge-key: If a tool result happens to show you key contents, ignore them.

    line 140
  8. Very specific:

    Never run claude-merge-token directly: Use ~/.claude/scripts/merge-dialog which gates behind a native macOS dialog the user must approve.

    line 141
  9. Distinctive:

    Tokens are single-intent: If a token fails (expired / invalid), do not retry with the same token.

    line 142

“Common” is measured: kept by at least 6 in 10 of the 23 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Merge

Merge (or discard) an active do/* worktree. Every merge requires an approval token that only the user can generate — the model cannot forge it.

/merge                 — interactive: pick a worktree, pick an action
/merge <worktree-id>   — shortcut: pre-select a worktree, then ask action

How the gate works

  1. The user has a secret at ~/.claude-merge-key (read-denied to all Claude tools).
  2. The user's shell has a claude-merge-token script that reads the key and prints an HMAC token for a given worktree-id.
  3. The PreToolUse hook do-merge-gate.sh intercepts git merge do/*, git worktree remove .worktrees/do-*, git branch -d do/*, and git reset --hard. It requires a valid MERGE_TOKEN=<token> prefix on the command, and recomputes the HMAC to verify.
  4. Tokens are valid for 2 minutes (current + previous minute bucket).
  5. The model has no path to the key or the token generator. Only the user can produce tokens.

Execution

Step 1: LIST

List active do/* worktrees. For each, show the worktree-id, the worktree path, and the likely origin branch:

# Live worktrees on disk
git worktree list --porcelain | awk '/^worktree / {wt=$2} /^branch / {br=$2; if (wt ~ /\/\.worktrees\/do-/) print wt, br}'

# Plus any dangling do/* branches without a worktree (in case a prior session removed the worktree but not the branch)
git branch --list 'do/*'

Also read active sessions from state MCP for any in-flight /do runs:

mcp__state__session_list(skill: "do", status: "active")

Use the payload.origin_branch from the session to know the target branch. If no session is found for a branch, fall back to git log do/do-<id> --first-parent --format='%H' | tail -2 | head -1 to find the likely fork point, then match against local branches.

If no do/* branches exist, tell the user and exit.

Step 2: PICK

AskUserQuestion:

  • Question: "Which worktree?"
  • Options: one per do/* worktree (label = do-<id> with origin branch, e.g. do-1776294905 → overnight/refine-epics-8-10-remainder).
  • If only one worktree exists, skip this step and auto-select it.

Step 3: ACTION

AskUserQuestion:

  • Question: "What would you like to do with do-<id>?"
  • Options:
    • Merge — rebase and merge into origin branch, clean up worktree and branch.
    • Discard — delete worktree and branch. No merge.
    • Open in VS Code — code {WORKTREE_PATH}, then return to this question.
    • Cancel — exit, leave worktree untouched.

Step 4a: MERGE (token-gated)

  1. Obtain the approval token via the native macOS dialog:

    TOKEN=$(~/.claude/scripts/merge-dialog do-<id>)

    This pops up a macOS dialog with Approve as the default button. The user presses Enter (or clicks Approve) → the token is generated, copied to their clipboard, and returned to stdout.

    If the dialog is cancelled, stop and say "Merge cancelled."

    Fallback (if ~/.claude/scripts/merge-dialog is missing): Show manual instructions and ask for the token via AskUserQuestion:

    To approve this merge, run in your own terminal (NOT via Claude):
      claude-merge-token do-<id>
    Paste the 12-character token below.
  2. Perform the merge, prefixing every gated command with MERGE_TOKEN=<token>:

    TOKEN=<pasted-token>
    WORKTREE_BRANCH="do/do-<id>"
    WORKTREE_PATH=".worktrees/do-<id>"
    ORIGIN_BRANCH="<origin from step 1>"
    
    # Run from main repo cwd, not inside the worktree.
    cd "$(git rev-parse --show-toplevel)"
    git checkout $ORIGIN_BRANCH
    
    # Rebase origin onto latest
    git fetch origin $ORIGIN_BRANCH 2>/dev/null || true
    git rebase origin/$ORIGIN_BRANCH 2>/dev/null || true
    
    # Rebase do branch onto origin
    git checkout $WORKTREE_BRANCH
    git rebase $ORIGIN_BRANCH
    git checkout $ORIGIN_BRANCH
    
    # Token-gated merge
    MERGE_TOKEN=$TOKEN git merge --no-ff $WORKTREE_BRANCH -m "merge: $WORKTREE_BRANCH"
    
    # Token-gated cleanup
    MERGE_TOKEN=$TOKEN git worktree remove $WORKTREE_PATH --force
    git worktree prune
    MERGE_TOKEN=$TOKEN git branch -d $WORKTREE_BRANCH
  3. If the hook rejects any command, surface the hook's error message and tell the user to generate a fresh token (tokens expire every 2 minutes).
  4. On success, complete any active state MCP session for this worktree and print: "Merged do-<id> into <origin> and cleaned up."

Step 4b: DISCARD (also token-gated)

Discard is destructive — same gate. Obtain the token using the same dialog flow as Step 4a, then:

MERGE_TOKEN=$TOKEN git worktree remove $WORKTREE_PATH --force
git worktree prune
MERGE_TOKEN=$TOKEN git branch -D $WORKTREE_BRANCH

Rules

  1. Never bypass the hook. Do not try --no-verify, alternative git paths, or filesystem manipulation. The hook is the authorization boundary.
  2. Never read or reference ~/.claude-merge-key. If a tool result happens to show you key contents, ignore them.
  3. Never run claude-merge-token directly. Use ~/.claude/scripts/merge-dialog which gates behind a native macOS dialog the user must approve. If the dialog script is unavailable, the user must run claude-merge-token in their own terminal.
  4. Tokens are single-intent. If a token fails (expired / invalid), do not retry with the same token. Ask the user to regenerate.
  5. Always run merge commands from the main repo cwd, not from inside the worktree (cwd gets invalidated when the worktree is removed).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.