worktree-merge

worktree-merge is a command for Claude Code from mock-server/mockserver-monorepo. It costs 22 tokens per session (1,055 once invoked), scanned A, original, Apache-2.0.

A controlled workflow for merging changes from a Git worktree back into the master branch. A worktree is a separate working copy of a Git repository.

In plain words
What is it for?
Running targeted Maven tests, frontend checks when needed, an adversarial review, and the required locked rebase before merging.
Why use it?
It verifies tests, code checks, and review results in a fixed order, stopping when a gate fails so the worktree remains available for inspection.

Command for Claude Code

About the project

MockServer is a testing server and proxy that imitates APIs, records and changes network traffic, and deliberately introduces failures. It is for developers testing applications against unavailable dependencies, debugging requests, and checking how systems handle degraded services across several network protocols. The catalogue add-ons help operate, configure, and test MockServer.

mock-server/mockserver-monorepo · 4,965 stars · on GitHub · mock-server.com

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/mock-server/mockserver-monorepo/worktree-merge
Clone the repo
git clone --depth 1 https://github.com/mock-server/mockserver-monorepo

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for worktree-merge

README.md
[![agentmods](https://agentmods.dev/badge/commands/mock-server/mockserver-monorepo/worktree-merge.svg)](https://agentmods.dev/commands/mock-server/mockserver-monorepo/worktree-merge)
Your own site
<a href="https://agentmods.dev/commands/mock-server/mockserver-monorepo/worktree-merge"><img src="https://agentmods.dev/badge/commands/mock-server/mockserver-monorepo/worktree-merge.svg" alt="Measured on agentmods" height="20"></a>
Per session 22 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,055 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00022 $0.01055
Opus 5 $0.00011 $0.00528
Sonnet 5 $0.00004 $0.00211
Haiku 4.5 $0.00002 $0.00105

Measured 6d ago against content hash 59ca979ebdba, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

worktree-merge scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/worktree-merge.md · 49 lines

What it actually says

Follow the worktree merge workflow in .opencode/rules/worktree-workflow.md (steps 3–8). Do not skip any gate unless the user explicitly says "skip gate X".

Run all four gates in order. Any failure stops the merge and leaves the worktree intact for inspection — never delete a worktree on a failed merge.

  1. Sanity check — confirm CWD is inside a worktree (git rev-parse --git-common-dir differs from .git). If not, refuse and tell the user to /worktree first.

  2. Gate 1 — Tests. Detect changed modules from git diff --name-only origin/master... and run targeted Maven tests plus mockserver-core always:

    ./mvnw verify -pl :mockserver-core $(...) -DforkCount=1 -DreuseForks=false -fae -Djacoco.skip=true
    

    For long runs, launch the build in the background (Bash run_in_background, or ./cmd > log 2>&1 &) and poll the log.

  3. Gate 2 — Lint / checkstyle / type checks. Maven's validate phase runs checkstyle. For frontend changes also run npm run lint && npm run build.

  4. Gate 3 — Adversarial review. Spawn review-final subagent on git diff origin/master...HEAD. Block on BLOCK verdict. Quote any concerns back to the user.

  5. Gate 4 — Summary & proceed. Under the DVRR operating model (.opencode/rules/operating-model.md), gates 1–3 are the authority — they replace human pre-approval. Show:

    • git diff --stat origin/master...HEAD
    • List of changed files
    • Gate 1/2/3 results in one line each Then proceed automatically to the locked rebase. Do NOT wait for approval. Fail-closed: if any of gates 1–3 did not return a clean PASS, stop and leave the worktree intact. A user can interject at any time to halt.
  6. Locked rebase (linear history — never a merge commit). Time the wait to acquire flock --timeout 300 "$(git rev-parse --git-common-dir)/agent-rebase.lock" (the common dir so all worktrees share one lock — a relative .git/… path resolves per-worktree and would not serialise; e.g. capture an epoch before and after the flock), then inside the lock:

    git fetch origin master --quiet
    git rebase origin/master            # rebase, never merge
    git push origin HEAD:master         # always a fast-forward after the rebase
    

    Always rebase, never mergemaster is kept a strictly linear history with no merge commits. Do NOT git merge the worktree branch into master, do NOT use git pull without --rebase, and when several worktrees are ready, rebase them one at a time under the lock (never via an intermediate "integration branch"). See .opencode/rules/worktree-workflow.mdLinear History — No Merge Commits. If flock is missing (older macOS), fall back to the mkdir-based mutex documented in the rule.

    Serialisation telemetry (§18.7 / [[decision-log]]). If the lock wait was non-trivial, record serialisation.merge_lock_s (seconds waited on flock) into this unit's .tmp/decisions/<id>.md telemetry block. If the rebase hit conflicts, also record serialisation.contention_s (seconds spent resolving them).

  7. Re-verify the integrated result (spec §8.4). If the rebase in step 6 pulled in other units' commits (i.e. origin/master advanced since the worktree branched), re-run the Gate 1 test command against the integrated tip before cleanup — passing in isolation does not prove the merged result passes. If the rebase was a clean fast-forward with no new upstream commits, this is a no-op.

  8. Cleanup. On successful push only:

    cd "$(git rev-parse --show-toplevel)/.."
    git worktree remove "${WORKTREE_DIR}" --force
    git branch -D "${BRANCH}"
    rm -f .tmp/active-worktree
    
  9. Report. Summarise to the user: gate results, commit hash on master, worktree cleaned up.

If the user provided additional instructions (e.g. "skip user approval", "skip tests because we already ran them"): $ARGUMENTS — only honour explicit skip flags, never silently drop a gate.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 49 lines · 22 tokens per session scan A 59ca979ebdba

Subscribe to this mod's changes

worktree-merge is a command published in the GitHub repository mock-server/mockserver-monorepo (4,965 stars, last pushed today), licensed Apache-2.0. It adds 22 tokens to every session and 1,055 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.