/forge:fg-mergefrom forge
Integrates a feature branch's namespaced .forge/ state into the default branch's .forge/, with optional git merge and commit. Runs via deterministic script in CI.
Ships in forge. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
.forge/ (outside the loop)This is not a stage of the forge loop. It is the integration step for branch isolation (ADR-0011): when a feature branch has been run with its forge state under .forge/branch/<branch>/ (a git-tracked, namespaced mini-root — see ../fg-run/FORGE-ROOT.md), fg-merge folds that branch's permanent forge docs into the default-branch .forge/.
Language: This skill file is authored in English, but you MUST write every message shown to the user — questions, menus, status/next-step lines, and handoff text — in the user's language (detect it from the user's own messages), never mirroring this file's English. The integration summary and any conflict question are written in the user's language.
Explaining forge: forge's vocabulary is not the user's — verified: failed, unsealed tail, a pillar or gate name means nothing unread. Always, never gated on eco: gloss a forge-specific term on first use in a message (a few words, not a paragraph), put the purpose before the mechanism, and lead with the answer, closing on what it means for the user. A gloss is not filler — with eco on, ECO.md's terse rules govern form (length, padding) while these govern vocabulary, so terseness never deletes a gloss.
Evidence and candor: every claim you make about code, state, or results — in a message or in a document you write (plan, run notes, retro, ADR) — carries its evidence in the same sentence (a file:line, a command and its output) or a label: Measured (you checked it this session), Inferred (reasoned from what you checked), Guess (a prediction or an unseen cause), rendered in the user's language. A label is not a license to skip a check — if a cheap check would settle it, run it; never hand the user a check you could run. Agreement is not the default: when asked whether to do something, invited to add scope, or shown an approach, give your real judgment first — the strongest objection, and "don't do it" when that is true. Change a recommendation only for a new fact or argument, never for repetition; the decision stays the user's — state the objection once, then follow their call without re-arguing or silently deviating. Output a deterministic script printed is already measured and needs no label.
tofg-merge has three modes, chosen by the argument (ADR 260717-10a, ADR 261006-102435):
fg-merge (no argument) — integrate only. The default-branch .forge/ already has the branch root .forge/branch/<branch>/ present (you ran git merge <branch> yourself, or CI did). fg-merge just integrates it. This is the original behavior, and the only mode CI uses.fg-merge <branch> — merge, then integrate. For convenience, the skill runs git merge <branch> for you first, then integrates that branch's root. This runs only on the default branch (the integration target is the top-level .forge/).fg-merge to [<target>] — ship the current branch. Run from the feature branch when its work is finished: the skill commits your work, checks out the default branch, merges the feature branch, integrates its forge root, and commits the integration. The literal keyword to fixes the direction, so this mode never collides with the two above (it means "send this branch to the target", where fg-merge <branch> means "pull <branch> into where I stand"). See "The to mode" below.Every git operation runs in this skill (a Bash step), never in the core script. The deterministic forge-merge.sh/.js that does the integration never runs git — that is what keeps it usable AI-free in CI (CI does its own merge, then calls the script). Only the interactive skill runs git — git merge in the <branch> mode, and commit/checkout/merge in the to mode. This is the bounded relaxation of ADR-0011's "fg-merge does not run git" (ADR 260717-10a, extended by ADR 261006-102435); the core script's git-abstinence is unchanged.
<branch> argument is given)Before integrating, run git merge <branch> and route on the result:
<branch> was merged already → skip straight to integrate (smart routing).git commit the merge, then run fg-merge (no argument) to integrate. Do not git merge --abort — that discards their merge and forces a redo.<branch> is not a valid git ref (e.g. the branch was deleted after a PR merge) but .forge/branch/<branch>/ is present → the work is already merged; skip the git step and integrate that root, noting the branch ref is gone (smart routing)..forge/, so it runs only on the default branch.In this mode fg-merge does not commit the integration and does not push — exactly as in integrate-only mode (only the to mode below commits). git merge makes its own merge commit; the integration changes are left uncommitted for you to review and commit (see the handoff).
If .forge/branch/<branch>/ is not present on the default branch after the merge step (or in integrate-only mode with no root at all), the script reports nothing to integrate (exit 2).
to mode — ship the current branch (fg-merge to [<target>])Run from the feature branch whose work is done. The point is the sequence you would otherwise type by hand — commit, checkout, merge, fg-merge, commit — as one command, without ever leaving the default branch half-merged with unfinished forge state on it.
Preconditions (stop before touching anything):
defaultBranch in the top-level .forge/config.json, else main — resolve per ../fg-run/FORGE-ROOT.md). Omitted target = the default branch. Any other target → stop and say why: integration folds into the top-level .forge/, which only the default branch owns, so a forge root would have nowhere to go.<target> — to pull a branch in, use fg-merge <branch>".--gate-only against the current branch's root — bash "${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT}}/scripts/forge-merge.sh" <feature> --gate-only (no bash → node …/forge-merge.js <feature> --gate-only). It judges only the in-flight gate and moves nothing:
GATE_INFLIGHT) → stop here, nothing changed. Unfinished forge work (an active plan, executed/, a loop.md, a pending quick) must be finished on the branch first — point to fg-done / fg-run / fg-loop.EMPTY) → the branch has no forge root. Not a blocker: continue, and say steps 4–5 will be skipped.GATE_OK) → continue.
This is why the gate runs before step 1: run at step 4, an in-flight refusal would come after the merge commit already landed on the default branch, recoverable only with git reset. A genuine conflict (exit 4) is not pre-checked — it needs the up-to-date target .forge/, which the feature branch does not have — so it can still surface at step 4, exactly as in the <branch> mode.One confirmation, before step 1 — then no more questions. Show, once (in the user's language):
git status --short), with untracked files listed separately so an unintended file (.env, build output) is caught by a human before it is committed;<feature> → <target>;git rev-list --count <target>..origin/<target>, no fetch (omit the line when there is no origin/<target> ref). Behind → warn only, never block: merging into a stale target makes the later push fail, and it is better to know now.Steps 3 onward are the hard-to-reverse ones, which is why the single confirmation sits before step 1 rather than between steps: a mid-flow question would leave the work half-done exactly where stopping is most awkward.
The five steps (stop at the first failure; never undo a finished step):
git status --porcelain is empty, skip and say so. Otherwise git add -A and commit with the confirmed message. A refused commit (a hook) → stop on the feature branch, show the hook output.git checkout <target>. Failure → stop on the feature branch (the step-1 commit stands).git merge <feature>. "Already up to date" → continue. Conflict → leave it in place and stop on the target, exactly as the <branch> mode does: resolve, git commit, then run fg-merge (no argument) to integrate. Never git merge --abort.<feature> (no --gate-only) and route its exit code per the table below. Skipped when the pre-check returned exit 2. Exit 4 → the conflict conversation in "Behavior" step 3, then re-run.git status --porcelain shows changes: git add -A and commit as chore(forge): integrate <feature> forge records.This is the one mode that commits — the other two still leave the integration uncommitted. It never pushes and never deletes the branch: in this repo a push to the default branch is a release (installs pull main), and the release procedure puts the push after the CHANGELOG and version bump; a merge tool must not route around that. The handoff names git push origin <target> and git branch -d <feature> as next steps instead.
Re-running is safe — the same command resumes from where it stopped: step 1 skips when nothing is uncommitted, step 3 reports "Already up to date", and the script is gate-first. The one exception is a step-3 conflict: once it is resolved and committed you are on the target, so finish with fg-merge (no argument).
The mechanical integration — resolving the branch root, moving ADRs (time-based IDs; an exact-ID clash takes the next free letter, no cascade renumber), folding retros/done/backlog, merging CONTEXT terms, remapping task numbers, rewriting bumped cross-references, removing the branch folder — is done by a deterministic script, not by an LLM hand-running a dozen mv/sed steps and reasoning the conflict guards in tokens (the same problem ADR-0020 fixed for fg-status and ADR-0030 for fg-done). This skill runs the script and routes on its exit code; the judgment (deciding a genuine semantic conflict, the conflict conversation, the handoff) stays here.
The script exists so the integration also works AI-free in CI (see "CI usage" below): a pipeline can run forge-merge.sh after a merge, and a non-zero exit fails the build so a human resolves it locally. Like forge-done.sh it is gate-first, non-destructive-on-refuse: it detects blocking conditions and exits non-zero before moving anything. Guarded by scripts/forge-merge.test.sh + scripts/forge-merge.parity.test.sh.
Dual dispatch (ADR-0022): prefer bash, fall back to node.
bash "${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT}}/scripts/forge-merge.sh" [<branch>]node "${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT}}/scripts/forge-merge.js" [<branch>] — identical behavior (exit codes, resulting .forge/ tree), guarded by the parity test.Argument: passing <branch> selects that branch root and triggers the merge step above (git merge → integrate). Omitting it means integrate-only, letting the script resolve the root — exactly one leaf root → that one; several → it exits 6 with the list, and you ask the user which, then re-invoke. (Because merge-and-integrate always names the branch, exit 6's ambiguity only arises in integrate-only mode.)
Exit codes → routing (this is the skill's job):
| Exit | Meaning | Route |
|---|---|---|
| 0 | integrated OK (branch folder removed) | relay the integration summary + commit reminder |
| 2 | nothing to integrate (no branch root / named branch absent / empty) | say so; in integrate-only mode remind that git merge (or fg-merge <branch>) must bring the branch root in first |
| 3 | in-flight branch state (active slot · executed/ · pending quick · loop.md) | tell the human to seal/recover/resume on the branch first (fg-done / fg-run / fg-loop), then re-run |
| 4 | genuine conflict needs a human | resolve it conversationally, then re-run (see below) |
| 6 | ambiguous (several branch roots, no <branch>) | list them, ask which, re-invoke with that branch |
The script emits language-neutral tokens (SEALED … / EMPTY … / GATE_INFLIGHT … / GATE_CONFLICT … / AMBIGUOUS …) — read the token to route; write the user-facing prose in the user's language.
It integrates the branch root's permanent docs into the top-level .forge/:
adr/*) — time-based IDs (YYMMDD-HHMMSS, or grandfathered YYMMDD-HH+letter — ADR-FORMAT.md) move as-is; an exact-ID collision with the target takes the next free letter (no cascade renumber — the #77 scheme), and the bumped ADR's cross-references are rewritten inside the moved incoming docs — both the ADR-<id> form and the backticked ADR `<id>` form, the former only when the next character is not [a-z0-9] (so an already-bumped <id>a or a prefix-sharing <id>b is untouched); a bare backticked <id> is never rewritten, because it cannot be told apart from a same-second retro ID. retired/ moves as-is.followups.md) — preserve candidate IDs, dates, source slugs and states; remap source/taken task numbers with the same incoming-task mapping. Identical IDs deduplicate only when the remapped entries agree; conflicting entries stop before mutation. See ../fg-learn/FOLLOWUPS-FORMAT.md.retro/*) — moved; -2 suffix on a filename collision.Then it removes .forge/branch/<branch>/ (and prunes an empty slashed parent, e.g. .forge/branch/feature/).
Warn-only, never rewritten: after re-lettering a bumped ADR (its collision bump), the script greps the merge-changed non-.forge/ project files (git diff --name-only ORIG_HEAD..HEAD, best-effort) for citations of the bumped ID by its old value and warns — outside .forge/ an ADR-<id> citation can't be safely disambiguated, so the human rewrites it.
Not integrated (persistent global exemptions — never branch-local; see ../fg-run/FORGE-ROOT.md): .forge/config.json, .forge/codebase/, and .forge/rules/. Rules remain ordinary git-versioned project files, not branch-root task state.
Gate-first: the script checks these before any mutation, so a refusal leaves the tree untouched.
plan.md (active slot), a non-empty executed/, a loop.md (unfinished goal contract), or a quick/LOG.md whose latest result still reads pending. A sealed branch has moved its work into done/; unfinished state must be resolved on the branch first (fg-done to seal, fg-run to recover a failed task, fg-loop to finish/abandon a goal loop) — never silently discarded. Route the human there, then re-run.**Name**: entry — ## X is a grouping subheading, so two glossaries sharing ## Language is not a conflict); (b) an incoming grandfathered NNNN ADR colliding with a frozen target NNNN (the letter rule only resolves time-based IDs; a NNNN clash has no cascade to fall back on by design). (c) the branch's CONTEXT.md is in an unrecognized shape — ## headings but zero **Term**: entries — which the term-wise merge would silently skip, losing the incoming terms; stopping is safer than a no-op merge. (d) malformed follow-up markers or conflicting records with the same candidate ID, in the ledger or incoming run/retro snapshots. Ledger and snapshot task references are remapped together; references without an incoming plan mapping are preserved. Show both sides and let the human reconcile (edit the branch's doc, or the target's), then re-run. Since the script is gate-first, nothing was moved.Because the mechanical integration is a deterministic script with a clean exit-code contract, a CI job can run it after a merge with no AI:
bash scripts/forge-merge.sh "$BRANCH" # exit 0 = integrated; non-zero = a human is needed
A non-zero exit fails the build: exit 3 (in-flight) / 4 (conflict) / 6 (ambiguous) all mean "resolve locally with fg-merge, then re-push." CI never auto-resolves a semantic conflict — that is the human/PR-review boundary above. (The example workflow that wires this as a gate lives in the team-ci-workflow-merge-policy-docs task.)
1) Decide the mode, then (if merging) run the merge step, then run the script. If the argument starts with the keyword to, follow "The to mode" above end to end instead — its pre-check, confirmation, and five steps own the whole run, and its step 4 is the script call described here. If a <branch> argument was given, first run the merge step above — git merge <branch>, routing on clean / already-up-to-date / conflict / deleted-ref / not-default-branch. Only a clean or already-merged result proceeds; a conflict stops here (leave it in place, do not integrate) and a not-default-branch stops here. With no argument, skip straight to integrate-only. Then resolve the branch root (explicit, or let the script enumerate and route its exit 6) and invoke the integration via dual dispatch (bash, else node). Do not hand-move files or hand-sed IDs — the script owns the integration; you own only the git merge orchestration.
2) Route on the exit code (judgment). Exit 0 → the integration summary below. Non-zero → route per the table / conflict section above and stop (nothing was moved — the script refused before mutating).
3) On a genuine conflict (exit 4), resolve conversationally — a merge-time mini fg-learn. Show the two sides (the redefined term's two bodies, or the colliding NNNN and what occupies it), ask the human how to reconcile, apply their choice to the branch/target doc, then re-run the script. Plan/doc edits are human-approved — never auto-pick a term's winning definition.
4) On success (exit 0), summarize + remind to commit. Relay what the script integrated (N ADRs, any letter bumps, retros moved, terms merged, done/backlog folded with the task-number remap, dropped preserved, branch folder removed) in the user's language, then remind the user to commit the integration result (the moved docs — any collision-bumped ADR re-lettered — plus the branch-folder deletion). In the to mode the integration is already committed (step 5) — instead name the next steps: git push origin <target> and git branch -d <feature>, which fg-merge does not run. In merge-and-integrate mode, note that git merge already made its merge commit, but the integration is still uncommitted — that mode never commits the integration, so remind them to commit it (the merge commit + the integration land as two commits, or squash them by hand). If the script printed any WARN external ref … lines, surface them: those are non-.forge/ citations of a bumped ADR the human must rewrite by hand.
fg-merge [<branch>] | fg-merge to [<target>]
│
├── to [<target>] ─▶ (on the feature branch) target must be default · current must not be default
│ ▼
│ forge-merge --gate-only <feature>
│ ├── exit 3 ──▶ STOP, nothing changed → finish forge work on the branch
│ └── exit 0 / 2 ──▶ ONE confirmation (files · untracked · message · direction · behind?)
│ ▼
│ 1 commit (skip if clean) → 2 checkout <target> → 3 git merge <feature>
│ (conflict → leave in place, STOP → "resolve, commit, then fg-merge")
│ ▼
│ 4 integrate (script below; skipped if pre-check was exit 2) → 5 commit integration
│ ▼
│ handoff: git push origin <target> · git branch -d <feature> (never run)
│
├── no <branch> ──▶ integrate-only (branch root already merged in)
│ │ (let the script resolve the root; exit 6 if several)
│ ▼
└── <branch> given ─▶ merge step (default branch only): git merge <branch>
├── clean / already up to date ──▶ integrate
├── conflict ──▶ LEAVE in place, STOP → "resolve, commit, then fg-merge (no arg)"
├── ref gone but branch root present ──▶ skip git, integrate + note
├── nothing to merge/integrate ──▶ error
└── not on default branch ──▶ stop
▼
run forge-merge.sh (bash) | forge-merge.js (no bash) ← git-free integration, unchanged
├── exit 0 ──▶ relay integration summary → remind to commit (+ surface WARN external refs)
├── exit 2 ──▶ "nothing to integrate" (integrate-only: git merge / fg-merge <branch> first?)
├── exit 3 ──▶ in-flight on the branch → seal/recover/resume there (fg-done/fg-run/fg-loop) → re-run
├── exit 4 ──▶ genuine conflict → show both sides, human reconciles → re-run
└── exit 6 ──▶ (integrate-only) several branch roots → ask which → re-invoke with that branch
.forge/adr/, .forge/retro/, .forge/followups.md, .forge/CONTEXT.md, .forge/done/, .forge/backlog/, .forge/dropped/ (the integrated docs), and removes .forge/branch/<branch>/ — all done by the script..forge/config.json or .forge/codebase/ (global exemptions). The core script does not run git (except a best-effort read-only git diff for the warn-only external-ref grep). The skill runs git merge in merge-and-integrate mode (fg-merge <branch>, default branch) without committing the integration, and commit/checkout/merge/commit in the to mode (fg-merge to [<target>], from a feature branch) — never the script, and never a push in any mode (ADR 260717-10a, ADR 261006-102435).scripts/forge-merge.sh / .js — this skill invokes it and routes; it does not hand-move files.For the ADR/CONTEXT formats, read ${PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT}}/skills/fg-ask/ADR-FORMAT.md / CONTEXT-FORMAT.md (skill-relative ../fg-ask/) — do not copy them here.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub gyuha/forge --plugin forge25 skills in this plugin
/fg-adversarial-reviewOptional adversarial review between fg-run and the seal (fg-done) — a reviewer assumes the result is WRONG and hunts for evidence across six lenses (failure points, hidden assumptions, misread requirements, security/perf/data-loss, unexpected misuse, weak decisions), fanning out as parallel subagents; fix-needed findings become a fix-forward plan on your approval. Outside the loop, never a seal gate, always skipped in fg-next all / fg-loop. Use in contexts like 'adversarial review', '적대적 리뷰', '이 결과 공격적으로 검토', '허점 찾아줘', 'red team this'./fg-agendaA decision queue for foggy work — outside the forge loop. Settles the destination with you, grills breadth-first to surface what must be decided, and keeps it in .forge/agenda.md (destination · decided · open questions · fog · out of scope), resolving one question at a time via fg-ask until the way is clear, then deleting itself. The agent finds the decisions; you answer them. Use in contexts like 'forge agenda', '의제', '결정 대기열', '뭘 결정해야 하는지 정리해줘', '어디서 시작할지 모르겠다'./fg-agentsGenerates a project's domain agents — conversational grilling derives the recurring roles, then writes standard Claude Code subagent cards to .claude/agents/<role>.md (each `description` carrying a "when to use" so fg-run can dispatch a matching role as agentType). Cards load only at session start, so RESTART the session after generating them before fg-run can use them. On-demand utility outside the loop. Use in contexts like 'forge agents', '도메인 에이전트 만들어', '에이전트 팀 구성', 'create project agents', 'domain agents', 'agent roles'.Other plugins' skills for the same job