[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M72T32J90XVZWABYAQZBF0MR":3,"skill-same:01M72T32J90XVZWABYAQZBF0MR":85},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":29,"commitSha":30,"skillDirectory":31,"forksCount":28,"repositoryHtmlUrl":32,"repositoryHomepageUrl":6,"ownerHtmlUrl":33,"ownerBlogUrl":34,"ownerDescription":6,"updatedAt":35,"install":36,"resources":49},"01M72T32J90XVZWABYAQZBF0MR","ywc-finish-branch",null,"(ywc) Use when delivering a single completed feature branch to the base branch — covers mark-PR-ready, CI wait + bot review polling, merge (PR\u002Flocal), post-merge verification, Mark Task Complete bookkeeping, and local branch cleanup. Triggers: \"finish branch\", \"deliver branch\", \"ywc-finish-branch\", \"merge feature branch\", \"branch 마무리\", \"ブランチ完了\", \"deliver task\", \"task 마감\". Do not use for branch creation (handled by upstream executor), committing alone (use `ywc-commit`), worktree management (use `ywc-worktrees`), draft PR creation alone (use `ywc-create-pr`), or PR review comment handling (use `ywc-handle-pr-reviews`).","yongwoon\u002Fywc-agent-toolkit","yongwoon","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F9317029?v=4","01M72SZSF6VKANKG5QTMV4V95S","01M72SZSG8HHC3W2CV5P7EJ5AH",8,"MIT","https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fclaude-code\u002Fskills\u002Fywc-finish-branch\u002FSKILL.md",[],[],"2026-11-10 22:39:42",false,"---\nname: ywc-finish-branch\nversion: 1.0.0\ndescription: >-\n  (ywc) Use when delivering a single completed feature branch to the base branch — covers mark-PR-ready, CI wait + bot review polling, merge (PR\u002Flocal), post-merge verification, Mark Task Complete bookkeeping, and local branch cleanup. Triggers: \"finish branch\", \"deliver branch\", \"ywc-finish-branch\", \"merge feature branch\", \"branch 마무리\", \"ブランチ完了\", \"deliver task\", \"task 마감\". Do not use for branch creation (handled by upstream executor), committing alone (use `ywc-commit`), worktree management (use `ywc-worktrees`), draft PR creation alone (use `ywc-create-pr`), or PR review comment handling (use `ywc-handle-pr-reviews`).\ncategory: delivery\nphase: execution\nrequires: [ywc-create-pr]\nadvisor_budget: 1\n---\n\n# ywc-finish-branch\n\n**Announce at start:** \"I'm using the ywc-finish-branch skill to deliver this feature branch.\"\n\nEncapsulates the post-implementation delivery flow that `ywc-sequential-executor` and `ywc-parallel-executor` previously inlined separately. One feature branch, one task — given a verified branch with passing local tests, this skill takes it the rest of the way to \"done\": optionally creates the PR, marks it ready, waits for CI, handles automated bot reviews, merges (PR or local), runs the post-merge hard gate, moves the task directory to `completed\u002F`, and deletes the local feature branch. Worktree-specific cleanup is intentionally **not** in scope — that stays with `ywc-parallel-executor` because the lifecycle differs.\n\n## Rationalization Defense\n\nWhen tempted to skip a step, check this table first:\n\n| Excuse | Reality |\n|---|---|\n| \"Step 4 (Merge) succeeded, that means we are done\" | The Definition of Done has 5 conditions. Merge is condition 2 of 5. Mark Task Complete (Step 7) and branch deletion (Step 8) are equally required — skipping them silently breaks dependency resolution for downstream tasks. |\n| \"Post-merge verification is just running `git log` — skip it for speed\" | The hard gate exists because `git merge` can silently no-op (already merged, nothing to do, fast-forward elided) and the caller cannot tell from exit code alone. Always verify. |\n| \"Bot review polling found 0 comments, skip the wait window\" | Polling the full window is the contract. Bots can post asynchronously after CI completes; cutting short the window misses real findings. |\n| \"Branch was already deleted by `gh pr merge --delete-branch`, skip the local cleanup\" | `--delete-branch` only removes the **remote** branch. The local copy persists and the next task's branch creation will conflict. Always run `git branch -d`. |\n| \"`git branch -r --merged HEAD` lists the branch, so deleting the remote is safe\" | `--merged HEAD` only proves the branch is in the *local* checkout, not in the PR's actual base. Deleting the remote head of an open PR auto-closes that PR. Before any remote deletion outside `gh pr merge --delete-branch`, follow the Step 5 Remote deletion guard in order — its open-PR check `env -u GH_HOST gh pr list --repo \"$repo\" --head \"$branch\" --state open --json number --jq length` must print exactly `0`. Command failure → `BLOCKED`; undeterminable repo or ambiguous output → `NEEDS_CONTEXT`; an open PR or tip mismatch → zero deletions, report the PR numbers or both SHAs. |\n| \"Mode flag conflict was already validated upstream, skip the check here\" | This skill is a callable unit and may be invoked outside the executors. Validate flag conflicts at every entry point, not just the upstream caller. |\n| \"Mark Task Complete is bookkeeping — defer it for after all wave tasks merge\" | `tasks\u002Fcompleted\u002F` is the contract that downstream tasks read for dependency resolution. Move-then-merge ordering is forbidden by the Definition of Done; merge-then-move within the same task cycle is required. |\n| \"If `git merge --no-ff` reports a conflict, abort and try again\" | An aborted merge loses the working state needed to debug the conflict. **Never** auto-abort — surface the conflict to the user so they can inspect it. |\n| \"`build-pr-title.py` exited 1 — I'll use just the slug as the title\" | Exit 1 means `TASK_NUMBER` was not detected. Stop and return `NEEDS_CONTEXT` — do not construct a title without `[TASK_NUMBER]`. A title without the task number cannot be traced back to the task in the audit trail. |\n| \"`ywc-create-pr` generates its own title from `git log`, so `--title` is optional\" | `ywc-create-pr`'s internal title generation does not know the task-number format. It silently produces a title without `[TASK_NUM]`. Always pass `--title` explicitly with `[TASK_NUMBER]` already included. |\n| \"CI failed twice — return BLOCKED and let the user fix it\" | Before returning BLOCKED, categorize the failure type. Lint\u002Fformat failures are auto-fixable without judgment. Type errors and build errors usually have a clear mechanical fix visible in the log. Only return BLOCKED when the root cause requires a design decision or all fix attempts are genuinely exhausted. |\n| \"CI is green, so `gh pr merge` will succeed\" | A PR can be `CONFLICTING` or `BEHIND` against the base even with green CI — a sibling task or another PR merged first. Check `gh pr view --json mergeable,mergeStateStatus` before merging instead of letting `gh pr merge` fail. If the branch is merely behind, merge the base into it (never rebase — it orphans review threads) and re-verify CI; if it is a real textual conflict, surface it and return BLOCKED. See `references\u002Fpr-conflict-resolution.md`. |\n| \"The UL update in Step 1.5 is optional bookkeeping — skip it to save time\" | The glossary is the shared vocabulary LLMs use in every subsequent prompt on this project. A branch that introduces new domain terms without updating the glossary silently pollutes downstream code generation and spec reviews. If `docs\u002Fubiquitous-language.md` does not exist, Step 1.5 skips automatically — there is no overhead in that case. |\n\n**Violating the letter of these rules is violating the spirit.** Delivery is the step where the user trusts the executor most — earning that trust requires honesty about partial completion.\n\n## Arguments\n\n| Parameter | Format | Example | Description |\n|---|---|---|---|\n| `--mode` | `\u003Cmode>` | `--mode local-merge` | One of `normal-pr`, `local-merge`, `draft`, `skip-ci-wait`, `per-task-pr`. See [Modes](#modes). |\n| `--branch` | `feature\u002F\u003Ctask-name>` | `--branch feature\u002Fyk-000001-010-db-create-users` | The feature branch to deliver. Must already exist locally. |\n| `--base-branch` | `\u003Cbranch-name>` | `--base-branch develop` | Target branch. Default: auto-detect (`develop` > `main` > `master`). |\n| `--task-name` | `\u003Ctask-name>` | `--task-name yk-000001-010-db-create-users` | Task directory name under `\u003Ctasks-dir>\u002F`, used for the Mark Complete commit. Accepts both the prefixed form and legacy unprefixed IDs (`000001-010-db-create-users`). |\n| `--tasks-dir` | `\u003Cpath>` | `--tasks-dir tasks\u002F` | Tasks directory root. Default: `tasks\u002F`. |\n| `--pr-lang` | `\u003Clang>` | `--pr-lang ja` | PR title\u002Fdescription language. Default: auto-detect from CLAUDE.md \u002F AGENTS.md \u002F recent PRs. |\n| `--bot-action` | `sequential` \\| `parallel` | `--bot-action sequential` | Post-bot polling behavior. Default: `sequential` (re-run CI after bot fixes). Use `parallel` when called from a wave loop where CI does not re-gate between bot iterations. |\n| `--defer-push` | flag | | Skip the push of the Mark Complete commit. Used by range-mode callers that batch pushes at the end of the range. |\n| `--keep-branch` | flag | | Skip the local feature branch deletion (`git branch -d`). Used by `ywc-parallel-executor`, where the branch is checked out in a worktree at the time of merge — `git branch -d` would fail until the worktree is removed. Caller takes responsibility for the eventual `git worktree remove` + `git branch -d`. |\n| `--worktree-path` | `\u003Cpath>` | `--worktree-path \u002Fabs\u002Frun-000024-010-000024-020` | Run every git operation in Steps 1 and 5–8 as `git -C \u003Cpath> …` so the delivery acts on the run worktree's HEAD instead of the main checkout. When unset, all git commands run against the repo root (current behavior — 100% backward compatible). Passed by `ywc-sequential-executor --worktree`; worktree creation and removal stay the caller's responsibility. See [Worktree-path mode](#worktree-path-mode). |\n\n**Mode-flag mutual exclusivity**: `--mode` is a single value; conflicts are impossible by construction. The caller is responsible for resolving ambiguity (e.g., the upstream executor's `--draft` and `--local-merge` flags must be collapsed into one `--mode` value before invoking this skill).\n\n## Worktree-path mode\n\nWhen `--worktree-path \u003Cpath>` is set, **every git command this skill issues** — the Step 1 `git branch --list` \u002F `git rev-parse` validations, the Step 5 merge\u002Fcheckout\u002Fpull\u002Fpush\u002Fbranch-delete sequence, the Step 6 post-merge `git log`, the Step 7 `git check-ignore` \u002F `git mv` \u002F `git commit` \u002F post-move check, and the Step 8 checkout\u002Fpull\u002Fbranch-delete — runs as `git -C \u003Cpath> …`. The delivery semantics are unchanged: CI wait, bot-review polling, the merge-readiness gate, and Mark Task Complete behave identically; only the working directory the git commands act on differs (the run worktree instead of the main checkout). `gh` commands (`gh pr ready` \u002F `gh pr checks` \u002F `gh pr merge` \u002F `gh pr view`) operate on the remote PR, not a working tree, so they are unaffected by `--worktree-path`.\n\n**HEAD invariant (per-task feature branch deletion is safe).** At the moment Step 5 runs, the run worktree's HEAD is on the **integration branch** (the worktree's permanent checkout). finish-branch creates\u002Fmerges `feature\u002F\u003Ctask-name>` and then checks out the integration branch *before* deleting `feature\u002F\u003Ctask-name>`, so the per-task branch is never the worktree's current checkout when `git branch -d` runs. The integration branch (and the trunk base branch) is **never** a deletion target here — finish-branch only deletes the per-task `feature\u002F\u003Ctask-name>`. This is why per-task branch deletion succeeds inside a worktree without needing `--keep-branch`: only a branch that is *checked out* in a worktree is undeletable, and the per-task branch is not.\n\n## Modes\n\n| Mode | PR? | CI wait? | Merge? | Mark Complete? | Cleanup? | Use case |\n|---|---|---|---|---|---|---|\n| `normal-pr` | yes (delegates to `ywc-create-pr`) | yes | yes (`gh pr merge --delete-branch`) | yes | yes (`git branch -d`) | Default upstream flow |\n| `local-merge` | no | no | yes (`git merge --no-ff` + push) | yes | yes | Personal repos, fast iteration |\n| `draft` | yes | no | no | **no** (task stays open until manually merged) | no | User wants PR for review without auto-merge |\n| `skip-ci-wait` | yes (mark ready) | no | no | **no** | no | User merges manually after offline review |\n| `per-task-pr` | yes | no (caller handles per-wave CI) | no (caller merges locally for wave progression) | no (caller marks complete in wave loop) | no | `ywc-parallel-executor` per-task PR delivery |\n\n`per-task-pr` is the special mode used inside `ywc-parallel-executor`'s wave loop — this skill creates and pushes the PR but stops short of merging or marking complete, because wave-level orchestration handles those steps. For all other modes, this skill executes the full lifecycle.\n\n## Definition of Done\n\nA `--mode normal-pr` or `--mode local-merge` invocation is **done** only when all of the following have happened, in this order:\n\n1. **Verification gate passed** (caller's responsibility — this skill does not re-run tests; the upstream executor must have completed its verification before invoking).\n2. **Merge succeeded**: either the PR was merged via `gh pr merge --delete-branch` (normal-pr) or `git merge --no-ff` succeeded locally and was pushed (local-merge).\n3. **Post-merge verification passed**: `git log -1 --format=\"%s\"` on the base branch begins with `Merge branch 'feature\u002F`.\n4. **Task directory moved**: `git mv \u003Ctasks-dir>\u002F\u003Ctask-name> \u003Ctasks-dir>\u002Fcompleted\u002F\u003Ctask-name>` and the `chore: mark \u003Ctask-name> as completed` commit was created.\n5. **Local feature branch deleted**: `git branch -d \"$BRANCH\"` (`BRANCH` as validated in Step 1) succeeded (refuses to delete an unmerged branch — that is the safety check).\n\nFor `--mode draft` and `--mode skip-ci-wait`, conditions 2–5 are intentionally not performed; the skill's responsibility ends at PR creation (and ready-marking for `skip-ci-wait`). For `--mode per-task-pr`, only the PR creation portion runs; the caller handles the rest within the wave loop.\n\n## Execution Steps\n\n### Step 1: Validate Inputs\n\n- Hold `--branch` in `BRANCH` and `--base-branch` in `BASE`, and validate both with step 1(a)–(b) of the Step 5 Remote deletion guard (the character allowlist and `check-ref-format`; its `HEAD` \u002F `$base` rejection applies only to a branch about to be deleted) before any git command below (on failure return `BLOCKED: invalid branch name`). Every later step reuses these validated variables.\n- Confirm `--branch` exists locally (`git branch --list \"$BRANCH\"` returns the branch).\n- Confirm `--base-branch` is reachable (`git rev-parse --verify \"$BASE\"` succeeds).\n- Confirm `--task-name` matches an entry under `\u003Ctasks-dir>\u002F` (not under `\u003Ctasks-dir>\u002Fcompleted\u002F`).\n- For PR-based modes: confirm `gh auth status` succeeds.\n\nWhen `--worktree-path \u003Cpath>` is set, run the `git branch --list` and `git rev-parse` validations as `git -C \u003Cpath> …` (see [Worktree-path mode](#worktree-path-mode)).\n\nIf any check fails, return `NEEDS_CONTEXT` with the specific missing input. Do not proceed with partial information.\n\n### Step 1.5: Ubiquitous Language Update (optional)\n\nCheck whether `docs\u002Fubiquitous-language.md` exists in the project root:\n\n```bash\ntest -f docs\u002Fubiquitous-language.md\n```\n\n- **Exists**: Invoke `ywc-ubiquitous-language --mode update`. This runs before PR creation so that any new domain terms introduced by this branch are captured in the glossary before the PR description is written.\n- **Not exists**: Skip silently — the project has not yet established a ubiquitous language document.\n\n`ywc-create-pr` is called in Step 2 with `--skip-ubiquitous-update` to prevent a second invocation of the same update.\n\n### Step 2: PR Creation (PR-based modes only)\n\nFor `--mode` ∈ {`normal-pr`, `draft`, `skip-ci-wait`, `per-task-pr`}: construct the PR title per the format below, then invoke `ywc-create-pr` passing:\n- `--title \"\u003Cconstructed-title>\"` — the `[task-number] description` string built from `--task-name` and `--pr-lang`\n- `--lang \u003Cpr-lang>` — so the description is written in the correct language\n- `--base-branch \u003Cbase-branch>` — the resolved target branch\n- `--skip-post-ci-check` — prevents `ywc-create-pr` from running its own post-PR CI + bot check; this skill handles CI verification in Step 4\n- `--skip-ubiquitous-update` — prevents `ywc-create-pr` from running the UL update a second time; Step 1.5 already ran it\n\n`ywc-create-pr` handles security check, CI pre-push validation, push, and PR creation as a draft. Because `--title` is provided explicitly, `ywc-create-pr` will use it verbatim and skip its own title-generation step.\n\n**PR title format**: `[\u003Ctask-number>] \u003Chuman-readable description in --pr-lang>`\n\nRun the bundled script to extract the task number and English slug without regex parsing:\n\n```bash\npython \"${CLAUDE_SKILL_DIR}\u002Fscripts\u002Fbuild-pr-title.py\" \u003Ctask-name>\n# TASK_NUMBER=yk-000001-010\n# SLUG_EN=Db Create Users Table\n```\n\n**If the script exits 1 (`TASK_NUMBER` is empty)**: stop immediately and return `NEEDS_CONTEXT` — report the task name that failed to parse. Do not construct a title with an empty task number.\n\nFor English PRs (`--pr-lang en`), use `--format title` to get the complete title directly:\n\n```bash\npython \"${CLAUDE_SKILL_DIR}\u002Fscripts\u002Fbuild-pr-title.py\" \u003Ctask-name> --format title\n# [yk-000001-010] Db Create Users Table\n```\n\nFor other languages, translate only `SLUG_EN` to `--pr-lang`, then compose: `[\u003CTASK_NUMBER>] \u003Ctranslated-slug>`.\n\nThe script supports the prefixed task-name format (`yk-000001-010-slug`) and both legacy formats (`000001-010-slug` and `001010-slug`). **The PR-title prefix carries the initials segment when the task name has one** (`[yk-000001-010]`) and is unchanged for legacy unprefixed IDs (`[000001-010]`). Examples of final titles: `[yk-000001-010] Create users table` (en) · `[yk-000001-010] ユーザーテーブル作成` (ja) · `[001010] DB 사용자 테이블 생성` (ko).\n\n**Before calling `ywc-create-pr`**: verify the constructed title string starts with `[`. If it does not, stop — the `[TASK_NUMBER]` prefix was lost somewhere in the construction. Do not call `ywc-create-pr` without a valid title.\n\nFor `--mode local-merge`: skip this step entirely. Local-merge does not produce a PR.\n\n### Step 3: Mark PR Ready (normal-pr only)\n\nInvoke `gh pr ready \u003Cpr-number>` to convert the draft into an open PR. Skip for `--mode draft`, `--mode skip-ci-wait`, `--mode per-task-pr` (those modes leave the PR as draft or hand control back to the caller).\n\n### Step 4: CI Verification + Bot Review Polling (normal-pr only)\n\n> **Action required**: Read [`..\u002Freferences\u002Fpr-bot-polling.md`](..\u002Freferences\u002Fpr-bot-polling.md) now before proceeding. The 60-second initial wait, the 300-second polling window, the `BOT_COUNT` jq query, and the merge condition are all defined there. Do not implement your own polling logic without reading it first.\n\nRun the CI wait + fix loop and the bot review polling per [..\u002Freferences\u002Fpr-bot-polling.md](..\u002Freferences\u002Fpr-bot-polling.md). The polling reference defines the canonical loop; this skill applies its `--bot-action` parameter to choose the post-bot behavior:\n\n- `--bot-action sequential`: after `ywc-handle-pr-reviews` runs, re-run the CI verification step before re-polling. Bot fixes may trigger a new CI run that must pass before merging.\n- `--bot-action parallel`: after `ywc-handle-pr-reviews` runs, re-poll without re-gating on CI. The wave loop in `ywc-parallel-executor` handles CI at the wave level.\n\n**CI failure handling (up to 2 fix attempts per failure cycle):**\n\n1. **Identify failing checks:**\n   ```bash\n   gh pr checks \u003Cpr-number>\n   ```\n\n2. **Get failure logs:**\n   ```bash\n   # Get the most recent failed run ID for the feature branch\n   gh run list --branch \u003Cfeature-branch> \\\n     --json databaseId,name,conclusion \\\n     --jq '.[] | select(.conclusion == \"failure\") | .databaseId' | head -1\n   gh run view \u003Crun-id> --log-failed\n   ```\n\n3. **Categorize and fix by failure type:**\n\n   | Failure type | Fix action |\n   |---|---|\n   | Lint \u002F format | Run the project's auto-fix command (`eslint --fix`, `prettier --write`, `ruff --fix`, `biome check --apply`), commit, push |\n   | Type errors | Read compiler output, fix type mismatches in affected files, commit, push |\n   | Test failures | Analyze failing test output, fix the implementation (never disable or weaken tests), commit, push |\n   | Build errors | Read compiler\u002Fbundler output, fix compilation or import errors, commit, push |\n\n4. After each push, re-run the CI wait and bot review polling loop (return to the top of Step 4).\n\n5. If CI still fails after **2 fix attempts**, return `BLOCKED` with: the failing check name(s), a log excerpt (last 30 lines), the PR URL, and the failure category so the user has enough context to resolve it manually.\n\n#### Step 4 final: Merge-Readiness Gate (normal-pr only)\n\nCI green is necessary but not sufficient — the base may have advanced into a conflict while CI ran. Before Step 5's `gh pr merge`, confirm the PR can actually merge:\n\n> **Action required before Step 5's `gh pr merge`**: Read [`..\u002Freferences\u002Fpr-conflict-resolution.md`](..\u002Freferences\u002Fpr-conflict-resolution.md) — it defines the `mergeable` \u002F `mergeStateStatus` table and the merge-not-rebase update procedure.\n\n```bash\ngh pr view \u003Cpr-number> --json mergeable,mergeStateStatus --jq '{mergeable, mergeStateStatus}'\n```\n\n- `MERGEABLE` \u002F `CLEAN` → proceed to Step 5.\n- `BEHIND` (branch protection requires up-to-date; no textual conflict) → merge the base into the feature branch (never rebase), push, and re-verify CI (counts as one CI cycle). Then re-check the gate.\n- `CONFLICTING` \u002F `DIRTY` that auto-resolves → merge the base into the feature branch (never rebase), push, and re-verify CI (counts as one CI cycle). Then re-check the gate.\n- `CONFLICTING` \u002F `DIRTY` with real textual conflicts → surface the conflicting files + PR URL and return `BLOCKED`. Do not auto-resolve or force-push.\n- `BLOCKED` (a required check or review is missing — not a conflict) → do not run the base-merge procedure; surface the outstanding required check\u002Freview and return `BLOCKED` so the user can resolve the gate.\n- `UNKNOWN` → poll briefly per the reference, then re-read.\n\nSkip this step entirely for `--mode local-merge`, `--mode draft`, `--mode skip-ci-wait`, `--mode per-task-pr`.\n\n### Step 5: Merge\n\n**Remote deletion guard**: normal delivery removes the remote branch through `gh pr merge --delete-branch`. Any other remote deletion — even when the user asks — runs only after every step below passes, in this order. `$branch` is the validated `BRANCH` and `$base` the validated `BASE` (the intended base) of the blocks below. This guard is prose-only; no hook enforces it.\n\n1. **Validate the branch** (the same rule as `ywc-worktrees --existing-branch`): (a) in-process, without interpolating it into any shell command, it must match `^[A-Za-z0-9._\u002F-]+$` over the whole string, must not start with `-`, and must not contain `..`; (b) only then `git check-ref-format \"refs\u002Fheads\u002F$branch\"` must succeed. On any failure return `BLOCKED: invalid branch name` and run no remote command. (c) Only for the branch to delete: it must also not be `HEAD` (which `check-ref-format` accepts) or equal `$base`; either returns `BLOCKED: refusing to delete \u003Cbranch>` with no remote command. Pass the branch only as a quoted variable — never splice a `--branch`-derived value unquoted into the command line.\n2. **Pin the push target**: `url` is `git remote get-url origin`; it must not start with `-`. `url` is the git remote URL (HTTPS or SSH, as `git remote get-url` prints it); `gh repo view` accepts both forms. `git remote get-url --push --all origin` must print exactly one line, equal to `url` (a `pushurl` or `pushInsteadOf` would send the delete somewhere the checks below never looked); otherwise return `NEEDS_CONTEXT` and delete nothing.\n3. **Bind the repository to `origin`**: run every `gh` call in this guard as `env -u GH_HOST gh …` with an explicit `--repo`. `env -u GH_HOST gh repo view --json url,isFork,parent,defaultBranchRef -- \"$url\"` (flags before `--`). `repo` is that `url` without its `https:\u002F\u002F` prefix (`\u003Chost>\u002F\u003Cowner>\u002F\u003Cname>`). Take `repo` from the `url` field of gh's JSON output (always `https:\u002F\u002F\u003Chost>\u002F\u003Cowner>\u002F\u003Cname>`), never from the git remote string: an SSH remote such as `git@github.com:o\u002Fr.git` has no `https:\u002F\u002F` prefix to strip and would fail the shape check below. When `isFork` is true, `parent` is `\u003Chost>\u002F\u003Cparent.owner.login>\u002F\u003Cparent.name>`, and `env -u GH_HOST gh repo view --json isFork -- \"$parent\"` must report `false` — a fork of a fork returns `NEEDS_CONTEXT`. Each value must match `^[A-Za-z0-9.-]+\u002F[A-Za-z0-9._-]+\u002F[A-Za-z0-9._-]+$`. Pass `--repo \"$repo\"` (and, for a fork, a second run with `--repo \"$parent\"`) to every `gh pr list` below — never rely on gh's implicit remote pick, where an upstream PR from this head can be invisible.\n4. **Read the tip**: `git ls-remote origin \"refs\u002Fheads\u002F$branch\"`. Patterns tail-match (`refs\u002Fheads\u002Fx\u002Frefs\u002Fheads\u002F$branch` may also print), so assign `tip` from the one line whose ref field is exactly `refs\u002Fheads\u002F$branch`; it must match `^[0-9a-f]{40}([0-9a-f]{24})?$`. No exact line means the branch is already absent — report it and delete nothing. Then refuse the repository's default branch and any protected branch: `$branch` must differ from `defaultBranchRef.name` of the step 3 JSON, and `env -u GH_HOST gh api --hostname \"\u003Chost>\" \"repos\u002F\u003Cowner>\u002F\u003Cname>\u002Fbranches\u002F$branch\" --jq .protected` (host, owner and name from `repo`) must print exactly `false`; `true` stops with zero deletions and reports `protected branch`.\n5. **Merged check**: `env -u GH_HOST gh pr list --repo \"$repo\" --head \"$branch\" --state merged --json number,baseRefName,headRefOid,headRepository,headRepositoryOwner` (plus the `$parent` run for a fork) must return a row whose `baseRefName` equals `$base` **and** whose `headRefOid` equals `$tip`; a differing tip means commits were pushed after the merge. The row's head repository must be `origin`: `headRepositoryOwner.login` and `headRepository.name` must equal the owner and name in `repo`, in the `$parent` run too, since `--head` filters by branch name only and a same-named branch from another fork is not evidence. Compare on the parsed JSON in-process (or with `jq --arg`) — never interpolate `$base` or `$tip` into a `--jq` filter. Never judge \"merged\" by `git branch -r --merged HEAD` on a local integration or work branch, nor by `gh pr view \u003Cbranch>` (it returns only one of possibly several PRs for that head).\n6. **Open-PR check** (last before the push, to shrink the race window): `env -u GH_HOST gh pr list --repo \"$repo\" --head \"$branch\" --state open --json number --jq length` must exit 0 and print exactly `0`; for a fork, the `--repo \"$parent\"` run must print `0` too.\n7. **Lease-delete**: `git push --force-with-lease=\"refs\u002Fheads\u002F$branch:$tip\" origin --delete \"refs\u002Fheads\u002F$branch\"` — a push landing after step 4 is rejected instead of lost. A small window remains between step 6 and this push: a PR opened in it is not seen and is auto-closed by the delete; the lease does not cover that.\n\nOutcomes: any command exiting non-zero (`gh`, `git ls-remote`, the push) → `BLOCKED`; an undeterminable repo, a value failing its shape check, or ambiguous output (unparseable JSON, a malformed `tip`) → `NEEDS_CONTEXT`; an open PR, no qualifying merged row, or a tip mismatch → stop with zero deletions and report the PR numbers or both SHAs.\n\nFor `--mode normal-pr`:\n```bash\n# Pin to the head Step 4 verified: read headRefOid when its CI gate passed (must match\n# ^[0-9a-f]{40}$, else BLOCKED: head unreadable) and write it here as a literal.\ngh pr merge \u003Cpr-number> --delete-branch --match-head-commit \"\u003CHEAD_SHA>\"\n```\n\nA refused pinned merge means the head moved after CI passed: re-run Step 4 on the new head and pin to it. Never retry the merge unpinned.\n\nFor `--mode local-merge`:\n```bash\n# Caller has already verified its Step 4 (Task Verification); this skill does not re-verify.\nBASE='\u003Cbase-branch>'                   # validated value only (Remote deletion guard rule above)\nBRANCH='feature\u002F\u003Ctask-name>'           # validated value only (same rule)\ngit checkout \"$BASE\"\ngit pull origin \"$BASE\"\ngit merge --no-ff \"$BRANCH\" -m \"Merge branch '$BRANCH'\"\ngit push origin \"$BASE\"                # omit when --defer-push is set\ngit branch -d \"$BRANCH\"                # omit when --keep-branch is set (parallel wave loop case)\n```\n\nBoth `BASE` and `BRANCH` must pass the validation order from the Remote deletion guard rule above before the block runs (on failure return `BLOCKED: invalid branch name` and run no git command); quote every use.\n\nWhen `--worktree-path \u003Cpath>` is set, prefix every git command above with `-C \u003Cpath>` (e.g. `git -C \u003Cpath> checkout \"$BASE\"`, `git -C \u003Cpath> merge --no-ff \"$BRANCH\" …`, `git -C \u003Cpath> branch -d \"$BRANCH\"`); here `\u003Cbase-branch>` is the run's integration branch (the worktree's checkout). Per the [Worktree-path mode](#worktree-path-mode) HEAD invariant, the integration branch is checked out before the per-task `feature\u002F\u003Ctask-name>` is deleted, so the delete succeeds.\n\nFor all other modes: skip — merge happens later (manual for `draft`, caller for `skip-ci-wait` and `per-task-pr`).\n\n**Why `git merge --no-ff` specifically** (not cherry-pick, not direct commit on main): preserves original commit SHAs, marks the task boundary in `git log --graph`, and lets `git branch -d` act as a built-in safety check that refuses to delete an unmerged branch. Full rationale lives in the upstream executor's `references\u002Fbranch-lifecycle.md`.\n\n**Error handling**: `git merge` conflict → stop and ask the user to resolve manually (do not auto-abort; the user may want to inspect). `gh pr merge` failure due to conflict\u002Fout-of-date → apply the Step 4 final Merge-Readiness Gate (`references\u002Fpr-conflict-resolution.md`): merge the base into the feature branch and re-verify, or return `BLOCKED` on a real textual conflict. Other `gh pr merge` failures → stop and report. Push rejected (remote moved) → stop; never force-push.\n\n### Step 6: Post-Merge Verification (hard gate)\n\nFor `--mode normal-pr` and `--mode local-merge`:\n```bash\ngit log -1 --format=\"%s\"\n```\nThe output **must** begin with `Merge branch 'feature\u002F`. If not, the merge did not execute correctly — investigate and retry before proceeding to Step 7. Do not write a completion marker for a merge that did not happen; downstream tasks would resolve dependencies against a broken contract. When `--worktree-path \u003Cpath>` is set, run this check as `git -C \u003Cpath> log -1 --format=\"%s\"`.\n\n### Step 7: Mark Task Complete\n\nFor `--mode normal-pr` and `--mode local-merge`:\n\nUse the shared marker script — it handles the `.gitignore` branch, the mandatory marker commit, and the post-move verification in one deterministic step (exits non-zero if anything failed):\n\n```bash\nbash \"${CLAUDE_SKILL_DIR}\u002F..\u002Fscripts\u002Fmark-complete.sh\" \u003Ctasks-dir> \u003Ctask-name> [--push | --defer-push]\n```\n\nThe marker script runs `\"${CLAUDE_SKILL_DIR}\u002F..\u002Fywc-task-generator\u002Fscripts\u002Fcompact-dependency-graph.py\"` between the move and marker commit, using the same resolved `\u003Ctasks-dir>`, and stages the resulting graph when it is tracked. The heading-based compactor retroactively handles existing graphs: completed phases become `## Phase NNNNNN — done` plus a `- Completed: ...` bullet, while fully completed Parallel Execution Notes and Visual Dependency Graph sections are removed. In worktree mode, the script path may come from the main checkout, but `\u003Ctasks-dir>` must resolve inside `\u003Cpath>`.\n\nWhy a script, not inline git: `git mv` cannot stage a path inside a gitignored `\u003Ctasks-dir>` (the move produces no diff), so that case needs a plain `mv` plus an `--allow-empty` marker commit, while a tracked `\u003Ctasks-dir>` uses `git mv`. The script detects which applies. The `chore: mark \u003Ctask-name> as completed` commit is **mandatory in both cases** — it is the `git log` audit boundary that humans, audit tooling, downstream skills, the Completion Report, and resume \u002F replay all rely on to verify task completion at a specific commit. The script then verifies the move (destination exists, source gone, marker commit at HEAD) and exits non-zero if any check fails; **do not declare `DONE` on a non-zero exit** — investigate and retry.\n\nWhen `--worktree-path \u003Cpath>` is set, run `mark-complete.sh` so its `git check-ignore` \u002F `git mv` \u002F `git commit` and post-move `git log` operate on the worktree (invoke it with the worktree as the working directory, e.g. `cd \u003Cpath> && bash \"${CLAUDE_SKILL_DIR}\u002F..\u002Fscripts\u002Fmark-complete.sh\" …`); the `\u003Ctasks-dir>` move acts on `\u003Cpath>\u002F\u003Ctasks-dir>\u002F…` directly, and the verification checks resolve against the worktree's HEAD (see [Worktree-path mode](#worktree-path-mode)).\n\n**Push strategy**: pass `--push` to `mark-complete.sh` for `--mode local-merge` and for `--mode normal-pr` when `--defer-push` is **not** set. Otherwise pass `--defer-push` (the script's default) so the caller can batch completion-marker commits and push them once at the end of the range. The caller is responsible for the eventual push when deferral is requested.\n\nFor `--mode draft`, `--mode skip-ci-wait`, `--mode per-task-pr`: skip Step 7 entirely. The task is not yet merged; marking it complete would be incorrect.\n\n### Step 8: Local Branch Cleanup\n\nFor `--mode normal-pr`:\n```bash\nBASE='\u003Cbase-branch>'                   # validated value only (Remote deletion guard rule, Step 5)\nBRANCH='feature\u002F\u003Ctask-name>'           # validated value only (same rule)\ngit checkout \"$BASE\"\ngit pull origin \"$BASE\"\ngit branch -d \"$BRANCH\"                # omit when --keep-branch is set\n```\nValidate `BASE` and `BRANCH` per the Step 5 Remote deletion guard rule before this block (on failure return `BLOCKED: invalid branch name` and run no git command); quote every use.\n\nThe local branch must be deleted explicitly because `gh pr merge --delete-branch` only removes the remote. Skip the deletion when `--keep-branch` is set — the caller (typically `ywc-parallel-executor`) will release the worktree and delete the branch in its own cleanup step. When `--worktree-path \u003Cpath>` is set, run all three commands as `git -C \u003Cpath> …` (here `\u003Cbase-branch>` is the run's integration branch); the per-task `feature\u002F\u003Ctask-name>` deletion is safe because the worktree HEAD is on the integration branch per the [Worktree-path mode](#worktree-path-mode) invariant.\n\nFor `--mode local-merge`: already handled inside Step 5's command sequence (which honors `--keep-branch` likewise).\n\nFor all other modes: skip. The branch stays alive for the user or caller to handle.\n\n**Worktree prune (when caller used a worktree)** — if the caller created a per-task worktree (`ywc-parallel-executor` does this), the post-cleanup prune is delegated to the [`ywc-worktrees`](..\u002Fywc-worktrees\u002F) skill:\n\n```bash\nywc-worktrees --mode prune --task-name \u003Ctask-name>\n```\n\n`ywc-worktrees --mode prune` runs the bundled `cleanup-worktree.sh` against the resolved worktree path — `git worktree remove` + local `git branch -d` + `git worktree prune` + post-removal verification, refusing to operate on dirty worktrees without `--force`. This skill does not inline the prune logic; the worktree priority chain (`.worktrees\u002F` > CLAUDE.md `worktree_root` > `--root` fallback) and the dirty-tree safety check live in one place. Skip this delegation when no worktree was created (the typical `--mode local-merge` \u002F `--mode normal-pr` flow that ran inside the main checkout).\n\n## Output Format\n\n```text\n## Finish Branch Result: \u003Ctask-name>\n\n### Mode\n\u003Cmode>\n\n### Outcome\n- PR: \u003Cpr-url-or-\"none-local-merge\">\n- Merge: \u003Ccommit-sha-or-\"deferred\">\n- Mark Complete commit: \u003Ccommit-sha-or-\"skipped\">\n- Local branch: \u003C\"deleted\"|\"preserved\">\n\n### Verification\n- Post-merge gate: \u003Cpassed|skipped|failed>\n- Post-move gate: \u003Cpassed|skipped|failed>\n\n### Completion Status\n\u003CDONE | DONE_WITH_CONCERNS | BLOCKED | NEEDS_CONTEXT>\n```\n\n**Completion Status rules:**\n\n| Status | When to use |\n|---|---|\n| `DONE` | All applicable steps for the chosen mode succeeded; verification gates passed |\n| `DONE_WITH_CONCERNS` | Delivery succeeded but with caveats (e.g., advisor budget exceeded for the bot-polling loop, or `--defer-push` was set and the caller now owns the push) |\n| `BLOCKED` | Cannot proceed — merge conflict, CI failure unfixable in 2 attempts, push rejected, or post-merge verification failed |\n| `NEEDS_CONTEXT` | One of `--branch`, `--base-branch`, `--task-name`, `--tasks-dir`, or `--mode` was missing or invalid; no work was performed |\n\n## Banned Output Patterns\n\nThis skill produces operational side effects (commits, pushes, merges), not source code. The \"Banned Output Patterns\" idea applied here means: **never** declare `DONE` while leaving any of the following:\n\n- A merge commit that the post-merge verification step did not confirm\n- A `chore: mark \u003Ctask-name> as completed` commit that has not been verified by the post-move test\n- A local feature branch that should have been deleted (modes `normal-pr` and `local-merge`, when `--keep-branch` is **not** set)\n- An unpushed commit when push was required (modes `local-merge` always; `normal-pr` when `--defer-push` is not set)\n\nEach of these is a hidden defect that breaks the next task's dependency resolution. Surface them honestly via `DONE_WITH_CONCERNS` or `BLOCKED` rather than declaring `DONE`.\n\n## Integration\n\n- **upstream**: `ywc-sequential-executor` (replaces its Steps 5–8), `ywc-parallel-executor` (replaces the merge + mark-complete portion of Step 4e–4f; worktree cleanup at Step 4g stays in parallel).\n- **internal delegation**: `ywc-create-pr` (Step 2), `ywc-handle-pr-reviews` (Step 4 inside the bot polling loop).\n- **shared references**: [..\u002Freferences\u002Fpr-bot-polling.md](..\u002Freferences\u002Fpr-bot-polling.md) (CI + bot polling), [..\u002Freferences\u002Flocal-merge-permissions.md](..\u002Freferences\u002Flocal-merge-permissions.md) (pre-authorized git\u002Fgh patterns the caller must set), [..\u002Freferences\u002Fsubagent-status-actions.md](..\u002Freferences\u002Fsubagent-status-actions.md) (how the caller responds to this skill's status return), [..\u002Freferences\u002Fpr-conflict-resolution.md](..\u002Freferences\u002Fpr-conflict-resolution.md) (merge-readiness gate and conflict resolution procedure).\n\n## Notes\n\nThis skill is a single-task delivery unit. It does not iterate over a range, manage a wave, or maintain checkpoint state — those concerns belong to the calling executor. Worktree **creation and removal** are intentionally out of scope, because the lifecycle differs between callers; placing it here would force one of them to special-case its cleanup. What this skill *does* support is **operating inside a caller-supplied worktree** via `--worktree-path` (see [Worktree-path mode](#worktree-path-mode)): `ywc-sequential-executor --worktree` runs its whole range inside one run worktree and passes that path so finish-branch's git commands target the worktree HEAD, while the worktree's own create\u002Fprune lifecycle stays with that caller. The historical \"sequential (no worktree)\" assumption now reads: sequential delivers in the main checkout *unless* `--worktree` is active, in which case `--worktree-path` redirects the git commands; parallel still owns its per-task worktrees.\n","# ywc-finish-branch\n\n**Announce at start:** \"I'm using the ywc-finish-branch skill to deliver this feature branch.\"\n\nEncapsulates the post-implementation delivery flow that `ywc-sequential-executor` and `ywc-parallel-executor` previously inlined separately. One feature branch, one task — given a verified branch with passing local tests, this skill takes it the rest of the way to \"done\": optionally creates the PR, marks it ready, waits for CI, handles automated bot reviews, merges (PR or local), runs the post-merge hard gate, moves the task directory to `completed\u002F`, and deletes the local feature branch. Worktree-specific cleanup is intentionally **not** in scope — that stays with `ywc-parallel-executor` because the lifecycle differs.\n\n## Rationalization Defense\n\nWhen tempted to skip a step, check this table first:\n\n| Excuse | Reality |\n|---|---|\n| \"Step 4 (Merge) succeeded, that means we are done\" | The Definition of Done has 5 conditions. Merge is condition 2 of 5. Mark Task Complete (Step 7) and branch deletion (Step 8) are equally required — skipping them silently breaks dependency resolution for downstream tasks. |\n| \"Post-merge verification is just running `git log` — skip it for speed\" | The hard gate exists because `git merge` can silently no-op (already merged, nothing to do, fast-forward elided) and the caller cannot tell from exit code alone. Always verify. |\n| \"Bot review polling found 0 comments, skip the wait window\" | Polling the full window is the contract. Bots can post asynchronously after CI completes; cutting short the window misses real findings. |\n| \"Branch was already deleted by `gh pr merge --delete-branch`, skip the local cleanup\" | `--delete-branch` only removes the **remote** branch. The local copy persists and the next task's branch creation will conflict. Always run `git branch -d`. |\n| \"`git branch -r --merged HEAD` lists the branch, so deleting the remote is safe\" | `--merged HEAD` only proves the branch is in the *local* checkout, not in the PR's actual base. Deleting the remote head of an open PR auto-closes that PR. Before any remote deletion outside `gh pr merge --delete-branch`, follow the Step 5 Remote deletion guard in order — its open-PR check `env -u GH_HOST gh pr list --repo \"$repo\" --head \"$branch\" --state open --json number --jq length` must print exactly `0`. Command failure → `BLOCKED`; undeterminable repo or ambiguous output → `NEEDS_CONTEXT`; an open PR or tip mismatch → zero deletions, report the PR numbers or both SHAs. |\n| \"Mode flag conflict was already validated upstream, skip the check here\" | This skill is a callable unit and may be invoked outside the executors. Validate flag conflicts at every entry point, not just the upstream caller. |\n| \"Mark Task Complete is bookkeeping — defer it for after all wave tasks merge\" | `tasks\u002Fcompleted\u002F` is the contract that downstream tasks read for dependency resolution. Move-then-merge ordering is forbidden by the Definition of Done; merge-then-move within the same task cycle is required. |\n| \"If `git merge --no-ff` reports a conflict, abort and try again\" | An aborted merge loses the working state needed to debug the conflict. **Never** auto-abort — surface the conflict to the user so they can inspect it. |\n| \"`build-pr-title.py` exited 1 — I'll use just the slug as the title\" | Exit 1 means `TASK_NUMBER` was not detected. Stop and return `NEEDS_CONTEXT` — do not construct a title without `[TASK_NUMBER]`. A title without the task number cannot be traced back to the task in the audit trail. |\n| \"`ywc-create-pr` generates its own title from `git log`, so `--title` is optional\" | `ywc-create-pr`'s internal title generation does not know the task-number format. It silently produces a title without `[TASK_NUM]`. Always pass `--title` explicitly with `[TASK_NUMBER]` already included. |\n| \"CI failed twice — return BLOCKED and let the user fix it\" | Before returning BLOCKED, categorize the failure type. Lint\u002Fformat failures are auto-fixable without judgment. Type errors and build errors usually have a clear mechanical fix visible in the log. Only return BLOCKED when the root cause requires a design decision or all fix attempts are genuinely exhausted. |\n| \"CI is green, so `gh pr merge` will succeed\" | A PR can be `CONFLICTING` or `BEHIND` against the base even with green CI — a sibling task or another PR merged first. Check `gh pr view --json mergeable,mergeStateStatus` before merging instead of letting `gh pr merge` fail. If the branch is merely behind, merge the base into it (never rebase — it orphans review threads) and re-verify CI; if it is a real textual conflict, surface it and return BLOCKED. See `references\u002Fpr-conflict-resolution.md`. |\n| \"The UL update in Step 1.5 is optional bookkeeping — skip it to save time\" | The glossary is the shared vocabulary LLMs use in every subsequent prompt on this project. A branch that introduces new domain terms without updating the glossary silently pollutes downstream code generation and spec reviews. If `docs\u002Fubiquitous-language.md` does not exist, Step 1.5 skips automatically — there is no overhead in that case. |\n\n**Violating the letter of these rules is violating the spirit.** Delivery is the step where the user trusts the executor most — earning that trust requires honesty about partial completion.\n\n## Arguments\n\n| Parameter | Format | Example | Description |\n|---|---|---|---|\n| `--mode` | `\u003Cmode>` | `--mode local-merge` | One of `normal-pr`, `local-merge`, `draft`, `skip-ci-wait`, `per-task-pr`. See [Modes](#modes). |\n| `--branch` | `feature\u002F\u003Ctask-name>` | `--branch feature\u002Fyk-000001-010-db-create-users` | The feature branch to deliver. Must already exist locally. |\n| `--base-branch` | `\u003Cbranch-name>` | `--base-branch develop` | Target branch. Default: auto-detect (`develop` > `main` > `master`). |\n| `--task-name` | `\u003Ctask-name>` | `--task-name yk-000001-010-db-create-users` | Task directory name under `\u003Ctasks-dir>\u002F`, used for the Mark Complete commit. Accepts both the prefixed form and legacy unprefixed IDs (`000001-010-db-create-users`). |\n| `--tasks-dir` | `\u003Cpath>` | `--tasks-dir tasks\u002F` | Tasks directory root. Default: `tasks\u002F`. |\n| `--pr-lang` | `\u003Clang>` | `--pr-lang ja` | PR title\u002Fdescription language. Default: auto-detect from CLAUDE.md \u002F AGENTS.md \u002F recent PRs. |\n| `--bot-action` | `sequential` \\| `parallel` | `--bot-action sequential` | Post-bot polling behavior. Default: `sequential` (re-run CI after bot fixes). Use `parallel` when called from a wave loop where CI does not re-gate between bot iterations. |\n| `--defer-push` | flag | | Skip the push of the Mark Complete commit. Used by range-mode callers that batch pushes at the end of the range. |\n| `--keep-branch` | flag | | Skip the local feature branch deletion (`git branch -d`). Used by `ywc-parallel-executor`, where the branch is checked out in a worktree at the time of merge — `git branch -d` would fail until the worktree is removed. Caller takes responsibility for the eventual `git worktree remove` + `git branch -d`. |\n| `--worktree-path` | `\u003Cpath>` | `--worktree-path \u002Fabs\u002Frun-000024-010-000024-020` | Run every git operation in Steps 1 and 5–8 as `git -C \u003Cpath> …` so the delivery acts on the run worktree's HEAD instead of the main checkout. When unset, all git commands run against the repo root (current behavior — 100% backward compatible). Passed by `ywc-sequential-executor --worktree`; worktree creation and removal stay the caller's responsibility. See [Worktree-path mode](#worktree-path-mode). |\n\n**Mode-flag mutual exclusivity**: `--mode` is a single value; conflicts are impossible by construction. The caller is responsible for resolving ambiguity (e.g., the upstream executor's `--draft` and `--local-merge` flags must be collapsed into one `--mode` value before invoking this skill).\n\n## Worktree-path mode\n\nWhen `--worktree-path \u003Cpath>` is set, **every git command this skill issues** — the Step 1 `git branch --list` \u002F `git rev-parse` validations, the Step 5 merge\u002Fcheckout\u002Fpull\u002Fpush\u002Fbranch-delete sequence, the Step 6 post-merge `git log`, the Step 7 `git check-ignore` \u002F `git mv` \u002F `git commit` \u002F post-move check, and the Step 8 checkout\u002Fpull\u002Fbranch-delete — runs as `git -C \u003Cpath> …`. The delivery semantics are unchanged: CI wait, bot-review polling, the merge-readiness gate, and Mark Task Complete behave identically; only the working directory the git commands act on differs (the run worktree instead of the main checkout). `gh` commands (`gh pr ready` \u002F `gh pr checks` \u002F `gh pr merge` \u002F `gh pr view`) operate on the remote PR, not a working tree, so they are unaffected by `--worktree-path`.\n\n**HEAD invariant (per-task feature branch deletion is safe).** At the moment Step 5 runs, the run worktree's HEAD is on the **integration branch** (the worktree's permanent checkout). finish-branch creates\u002Fmerges `feature\u002F\u003Ctask-name>` and then checks out the integration branch *before* deleting `feature\u002F\u003Ctask-name>`, so the per-task branch is never the worktree's current checkout when `git branch -d` runs. The integration branch (and the trunk base branch) is **never** a deletion target here — finish-branch only deletes the per-task `feature\u002F\u003Ctask-name>`. This is why per-task branch deletion succeeds inside a worktree without needing `--keep-branch`: only a branch that is *checked out* in a worktree is undeletable, and the per-task branch is not.\n\n## Modes\n\n| Mode | PR? | CI wait? | Merge? | Mark Complete? | Cleanup? | Use case |\n|---|---|---|---|---|---|---|\n| `normal-pr` | yes (delegates to `ywc-create-pr`) | yes | yes (`gh pr merge --delete-branch`) | yes | yes (`git branch -d`) | Default upstream flow |\n| `local-merge` | no | no | yes (`git merge --no-ff` + push) | yes | yes | Personal repos, fast iteration |\n| `draft` | yes | no | no | **no** (task stays open until manually merged) | no | User wants PR for review without auto-merge |\n| `skip-ci-wait` | yes (mark ready) | no | no | **no** | no | User merges manually after offline review |\n| `per-task-pr` | yes | no (caller handles per-wave CI) | no (caller merges locally for wave progression) | no (caller marks complete in wave loop) | no | `ywc-parallel-executor` per-task PR delivery |\n\n`per-task-pr` is the special mode used inside `ywc-parallel-executor`'s wave loop — this skill creates and pushes the PR but stops short of merging or marking complete, because wave-level orchestration handles those steps. For all other modes, this skill executes the full lifecycle.\n\n## Definition of Done\n\nA `--mode normal-pr` or `--mode local-merge` invocation is **done** only when all of the following have happened, in this order:\n\n1. **Verification gate passed** (caller's responsibility — this skill does not re-run tests; the upstream executor must have completed its verification before invoking).\n2. **Merge succeeded**: either the PR was merged via `gh pr merge --delete-branch` (normal-pr) or `git merge --no-ff` succeeded locally and was pushed (local-merge).\n3. **Post-merge verification passed**: `git log -1 --format=\"%s\"` on the base branch begins with `Merge branch 'feature\u002F`.\n4. **Task directory moved**: `git mv \u003Ctasks-dir>\u002F\u003Ctask-name> \u003Ctasks-dir>\u002Fcompleted\u002F\u003Ctask-name>` and the `chore: mark \u003Ctask-name> as completed` commit was created.\n5. **Local feature branch deleted**: `git branch -d \"$BRANCH\"` (`BRANCH` as validated in Step 1) succeeded (refuses to delete an unmerged branch — that is the safety check).\n\nFor `--mode draft` and `--mode skip-ci-wait`, conditions 2–5 are intentionally not performed; the skill's responsibility ends at PR creation (and ready-marking for `skip-ci-wait`). For `--mode per-task-pr`, only the PR creation portion runs; the caller handles the rest within the wave loop.\n\n## Execution Steps\n\n### Step 1: Validate Inputs\n\n- Hold `--branch` in `BRANCH` and `--base-branch` in `BASE`, and validate both with step 1(a)–(b) of the Step 5 Remote deletion guard (the character allowlist and `check-ref-format`; its `HEAD` \u002F `$base` rejection applies only to a branch about to be deleted) before any git command below (on failure return `BLOCKED: invalid branch name`). Every later step reuses these validated variables.\n- Confirm `--branch` exists locally (`git branch --list \"$BRANCH\"` returns the branch).\n- Confirm `--base-branch` is reachable (`git rev-parse --verify \"$BASE\"` succeeds).\n- Confirm `--task-name` matches an entry under `\u003Ctasks-dir>\u002F` (not under `\u003Ctasks-dir>\u002Fcompleted\u002F`).\n- For PR-based modes: confirm `gh auth status` succeeds.\n\nWhen `--worktree-path \u003Cpath>` is set, run the `git branch --list` and `git rev-parse` validations as `git -C \u003Cpath> …` (see [Worktree-path mode](#worktree-path-mode)).\n\nIf any check fails, return `NEEDS_CONTEXT` with the specific missing input. Do not proceed with partial information.\n\n### Step 1.5: Ubiquitous Language Update (optional)\n\nCheck whether `docs\u002Fubiquitous-language.md` exists in the project root:\n\n```bash\ntest -f docs\u002Fubiquitous-language.md\n```\n\n- **Exists**: Invoke `ywc-ubiquitous-language --mode update`. This runs before PR creation so that any new domain terms introduced by this branch are captured in the glossary before the PR description is written.\n- **Not exists**: Skip silently — the project has not yet established a ubiquitous language document.\n\n`ywc-create-pr` is called in Step 2 with `--skip-ubiquitous-update` to prevent a second invocation of the same update.\n\n### Step 2: PR Creation (PR-based modes only)\n\nFor `--mode` ∈ {`normal-pr`, `draft`, `skip-ci-wait`, `per-task-pr`}: construct the PR title per the format below, then invoke `ywc-create-pr` passing:\n- `--title \"\u003Cconstructed-title>\"` — the `[task-number] description` string built from `--task-name` and `--pr-lang`\n- `--lang \u003Cpr-lang>` — so the description is written in the correct language\n- `--base-branch \u003Cbase-branch>` — the resolved target branch\n- `--skip-post-ci-check` — prevents `ywc-create-pr` from running its own post-PR CI + bot check; this skill handles CI verification in Step 4\n- `--skip-ubiquitous-update` — prevents `ywc-create-pr` from running the UL update a second time; Step 1.5 already ran it\n\n`ywc-create-pr` handles security check, CI pre-push validation, push, and PR creation as a draft. Because `--title` is provided explicitly, `ywc-create-pr` will use it verbatim and skip its own title-generation step.\n\n**PR title format**: `[\u003Ctask-number>] \u003Chuman-readable description in --pr-lang>`\n\nRun the bundled script to extract the task number and English slug without regex parsing:\n\n```bash\npython \"${CLAUDE_SKILL_DIR}\u002Fscripts\u002Fbuild-pr-title.py\" \u003Ctask-name>\n# TASK_NUMBER=yk-000001-010\n# SLUG_EN=Db Create Users Table\n```\n\n**If the script exits 1 (`TASK_NUMBER` is empty)**: stop immediately and return `NEEDS_CONTEXT` — report the task name that failed to parse. Do not construct a title with an empty task number.\n\nFor English PRs (`--pr-lang en`), use `--format title` to get the complete title directly:\n\n```bash\npython \"${CLAUDE_SKILL_DIR}\u002Fscripts\u002Fbuild-pr-title.py\" \u003Ctask-name> --format title\n# [yk-000001-010] Db Create Users Table\n```\n\nFor other languages, translate only `SLUG_EN` to `--pr-lang`, then compose: `[\u003CTASK_NUMBER>] \u003Ctranslated-slug>`.\n\nThe script supports the prefixed task-name format (`yk-000001-010-slug`) and both legacy formats (`000001-010-slug` and `001010-slug`). **The PR-title prefix carries the initials segment when the task name has one** (`[yk-000001-010]`) and is unchanged for legacy unprefixed IDs (`[000001-010]`). Examples of final titles: `[yk-000001-010] Create users table` (en) · `[yk-000001-010] ユーザーテーブル作成` (ja) · `[001010] DB 사용자 테이블 생성` (ko).\n\n**Before calling `ywc-create-pr`**: verify the constructed title string starts with `[`. If it does not, stop — the `[TASK_NUMBER]` prefix was lost somewhere in the construction. Do not call `ywc-create-pr` without a valid title.\n\nFor `--mode local-merge`: skip this step entirely. Local-merge does not produce a PR.\n\n### Step 3: Mark PR Ready (normal-pr only)\n\nInvoke `gh pr ready \u003Cpr-number>` to convert the draft into an open PR. Skip for `--mode draft`, `--mode skip-ci-wait`, `--mode per-task-pr` (those modes leave the PR as draft or hand control back to the caller).\n\n### Step 4: CI Verification + Bot Review Polling (normal-pr only)\n\n> **Action required**: Read [`..\u002Freferences\u002Fpr-bot-polling.md`](..\u002Freferences\u002Fpr-bot-polling.md) now before proceeding. The 60-second initial wait, the 300-second polling window, the `BOT_COUNT` jq query, and the merge condition are all defined there. Do not implement your own polling logic without reading it first.\n\nRun the CI wait + fix loop and the bot review polling per [..\u002Freferences\u002Fpr-bot-polling.md](..\u002Freferences\u002Fpr-bot-polling.md). The polling reference defines the canonical loop; this skill applies its `--bot-action` parameter to choose the post-bot behavior:\n\n- `--bot-action sequential`: after `ywc-handle-pr-reviews` runs, re-run the CI verification step before re-polling. Bot fixes may trigger a new CI run that must pass before merging.\n- `--bot-action parallel`: after `ywc-handle-pr-reviews` runs, re-poll without re-gating on CI. The wave loop in `ywc-parallel-executor` handles CI at the wave level.\n\n**CI failure handling (up to 2 fix attempts per failure cycle):**\n\n1. **Identify failing checks:**\n   ```bash\n   gh pr checks \u003Cpr-number>\n   ```\n\n2. **Get failure logs:**\n   ```bash\n   # Get the most recent failed run ID for the feature branch\n   gh run list --branch \u003Cfeature-branch> \\\n     --json databaseId,name,conclusion \\\n     --jq '.[] | select(.conclusion == \"failure\") | .databaseId' | head -1\n   gh run view \u003Crun-id> --log-failed\n   ```\n\n3. **Categorize and fix by failure type:**\n\n   | Failure type | Fix action |\n   |---|---|\n   | Lint \u002F format | Run the project's auto-fix command (`eslint --fix`, `prettier --write`, `ruff --fix`, `biome check --apply`), commit, push |\n   | Type errors | Read compiler output, fix type mismatches in affected files, commit, push |\n   | Test failures | Analyze failing test output, fix the implementation (never disable or weaken tests), commit, push |\n   | Build errors | Read compiler\u002Fbundler output, fix compilation or import errors, commit, push |\n\n4. After each push, re-run the CI wait and bot review polling loop (return to the top of Step 4).\n\n5. If CI still fails after **2 fix attempts**, return `BLOCKED` with: the failing check name(s), a log excerpt (last 30 lines), the PR URL, and the failure category so the user has enough context to resolve it manually.\n\n#### Step 4 final: Merge-Readiness Gate (normal-pr only)\n\nCI green is necessary but not sufficient — the base may have advanced into a conflict while CI ran. Before Step 5's `gh pr merge`, confirm the PR can actually merge:\n\n> **Action required before Step 5's `gh pr merge`**: Read [`..\u002Freferences\u002Fpr-conflict-resolution.md`](..\u002Freferences\u002Fpr-conflict-resolution.md) — it defines the `mergeable` \u002F `mergeStateStatus` table and the merge-not-rebase update procedure.\n\n```bash\ngh pr view \u003Cpr-number> --json mergeable,mergeStateStatus --jq '{mergeable, mergeStateStatus}'\n```\n\n- `MERGEABLE` \u002F `CLEAN` → proceed to Step 5.\n- `BEHIND` (branch protection requires up-to-date; no textual conflict) → merge the base into the feature branch (never rebase), push, and re-verify CI (counts as one CI cycle). Then re-check the gate.\n- `CONFLICTING` \u002F `DIRTY` that auto-resolves → merge the base into the feature branch (never rebase), push, and re-verify CI (counts as one CI cycle). Then re-check the gate.\n- `CONFLICTING` \u002F `DIRTY` with real textual conflicts → surface the conflicting files + PR URL and return `BLOCKED`. Do not auto-resolve or force-push.\n- `BLOCKED` (a required check or review is missing — not a conflict) → do not run the base-merge procedure; surface the outstanding required check\u002Freview and return `BLOCKED` so the user can resolve the gate.\n- `UNKNOWN` → poll briefly per the reference, then re-read.\n\nSkip this step entirely for `--mode local-merge`, `--mode draft`, `--mode skip-ci-wait`, `--mode per-task-pr`.\n\n### Step 5: Merge\n\n**Remote deletion guard**: normal delivery removes the remote branch through `gh pr merge --delete-branch`. Any other remote deletion — even when the user asks — runs only after every step below passes, in this order. `$branch` is the validated `BRANCH` and `$base` the validated `BASE` (the intended base) of the blocks below. This guard is prose-only; no hook enforces it.\n\n1. **Validate the branch** (the same rule as `ywc-worktrees --existing-branch`): (a) in-process, without interpolating it into any shell command, it must match `^[A-Za-z0-9._\u002F-]+$` over the whole string, must not start with `-`, and must not contain `..`; (b) only then `git check-ref-format \"refs\u002Fheads\u002F$branch\"` must succeed. On any failure return `BLOCKED: invalid branch name` and run no remote command. (c) Only for the branch to delete: it must also not be `HEAD` (which `check-ref-format` accepts) or equal `$base`; either returns `BLOCKED: refusing to delete \u003Cbranch>` with no remote command. Pass the branch only as a quoted variable — never splice a `--branch`-derived value unquoted into the command line.\n2. **Pin the push target**: `url` is `git remote get-url origin`; it must not start with `-`. `url` is the git remote URL (HTTPS or SSH, as `git remote get-url` prints it); `gh repo view` accepts both forms. `git remote get-url --push --all origin` must print exactly one line, equal to `url` (a `pushurl` or `pushInsteadOf` would send the delete somewhere the checks below never looked); otherwise return `NEEDS_CONTEXT` and delete nothing.\n3. **Bind the repository to `origin`**: run every `gh` call in this guard as `env -u GH_HOST gh …` with an explicit `--repo`. `env -u GH_HOST gh repo view --json url,isFork,parent,defaultBranchRef -- \"$url\"` (flags before `--`). `repo` is that `url` without its `https:\u002F\u002F` prefix (`\u003Chost>\u002F\u003Cowner>\u002F\u003Cname>`). Take `repo` from the `url` field of gh's JSON output (always `https:\u002F\u002F\u003Chost>\u002F\u003Cowner>\u002F\u003Cname>`), never from the git remote string: an SSH remote such as `git@github.com:o\u002Fr.git` has no `https:\u002F\u002F` prefix to strip and would fail the shape check below. When `isFork` is true, `parent` is `\u003Chost>\u002F\u003Cparent.owner.login>\u002F\u003Cparent.name>`, and `env -u GH_HOST gh repo view --json isFork -- \"$parent\"` must report `false` — a fork of a fork returns `NEEDS_CONTEXT`. Each value must match `^[A-Za-z0-9.-]+\u002F[A-Za-z0-9._-]+\u002F[A-Za-z0-9._-]+$`. Pass `--repo \"$repo\"` (and, for a fork, a second run with `--repo \"$parent\"`) to every `gh pr list` below — never rely on gh's implicit remote pick, where an upstream PR from this head can be invisible.\n4. **Read the tip**: `git ls-remote origin \"refs\u002Fheads\u002F$branch\"`. Patterns tail-match (`refs\u002Fheads\u002Fx\u002Frefs\u002Fheads\u002F$branch` may also print), so assign `tip` from the one line whose ref field is exactly `refs\u002Fheads\u002F$branch`; it must match `^[0-9a-f]{40}([0-9a-f]{24})?$`. No exact line means the branch is already absent — report it and delete nothing. Then refuse the repository's default branch and any protected branch: `$branch` must differ from `defaultBranchRef.name` of the step 3 JSON, and `env -u GH_HOST gh api --hostname \"\u003Chost>\" \"repos\u002F\u003Cowner>\u002F\u003Cname>\u002Fbranches\u002F$branch\" --jq .protected` (host, owner and name from `repo`) must print exactly `false`; `true` stops with zero deletions and reports `protected branch`.\n5. **Merged check**: `env -u GH_HOST gh pr list --repo \"$repo\" --head \"$branch\" --state merged --json number,baseRefName,headRefOid,headRepository,headRepositoryOwner` (plus the `$parent` run for a fork) must return a row whose `baseRefName` equals `$base` **and** whose `headRefOid` equals `$tip`; a differing tip means commits were pushed after the merge. The row's head repository must be `origin`: `headRepositoryOwner.login` and `headRepository.name` must equal the owner and name in `repo`, in the `$parent` run too, since `--head` filters by branch name only and a same-named branch from another fork is not evidence. Compare on the parsed JSON in-process (or with `jq --arg`) — never interpolate `$base` or `$tip` into a `--jq` filter. Never judge \"merged\" by `git branch -r --merged HEAD` on a local integration or work branch, nor by `gh pr view \u003Cbranch>` (it returns only one of possibly several PRs for that head).\n6. **Open-PR check** (last before the push, to shrink the race window): `env -u GH_HOST gh pr list --repo \"$repo\" --head \"$branch\" --state open --json number --jq length` must exit 0 and print exactly `0`; for a fork, the `--repo \"$parent\"` run must print `0` too.\n7. **Lease-delete**: `git push --force-with-lease=\"refs\u002Fheads\u002F$branch:$tip\" origin --delete \"refs\u002Fheads\u002F$branch\"` — a push landing after step 4 is rejected instead of lost. A small window remains between step 6 and this push: a PR opened in it is not seen and is auto-closed by the delete; the lease does not cover that.\n\nOutcomes: any command exiting non-zero (`gh`, `git ls-remote`, the push) → `BLOCKED`; an undeterminable repo, a value failing its shape check, or ambiguous output (unparseable JSON, a malformed `tip`) → `NEEDS_CONTEXT`; an open PR, no qualifying merged row, or a tip mismatch → stop with zero deletions and report the PR numbers or both SHAs.\n\nFor `--mode normal-pr`:\n```bash\n# Pin to the head Step 4 verified: read headRefOid when its CI gate passed (must match\n# ^[0-9a-f]{40}$, else BLOCKED: head unreadable) and write it here as a literal.\ngh pr merge \u003Cpr-number> --delete-branch --match-head-commit \"\u003CHEAD_SHA>\"\n```\n\nA refused pinned merge means the head moved after CI passed: re-run Step 4 on the new head and pin to it. Never retry the merge unpinned.\n\nFor `--mode local-merge`:\n```bash\n# Caller has already verified its Step 4 (Task Verification); this skill does not re-verify.\nBASE='\u003Cbase-branch>'                   # validated value only (Remote deletion guard rule above)\nBRANCH='feature\u002F\u003Ctask-name>'           # validated value only (same rule)\ngit checkout \"$BASE\"\ngit pull origin \"$BASE\"\ngit merge --no-ff \"$BRANCH\" -m \"Merge branch '$BRANCH'\"\ngit push origin \"$BASE\"                # omit when --defer-push is set\ngit branch -d \"$BRANCH\"                # omit when --keep-branch is set (parallel wave loop case)\n```\n\nBoth `BASE` and `BRANCH` must pass the validation order from the Remote deletion guard rule above before the block runs (on failure return `BLOCKED: invalid branch name` and run no git command); quote every use.\n\nWhen `--worktree-path \u003Cpath>` is set, prefix every git command above with `-C \u003Cpath>` (e.g. `git -C \u003Cpath> checkout \"$BASE\"`, `git -C \u003Cpath> merge --no-ff \"$BRANCH\" …`, `git -C \u003Cpath> branch -d \"$BRANCH\"`); here `\u003Cbase-branch>` is the run's integration branch (the worktree's checkout). Per the [Worktree-path mode](#worktree-path-mode) HEAD invariant, the integration branch is checked out before the per-task `feature\u002F\u003Ctask-name>` is deleted, so the delete succeeds.\n\nFor all other modes: skip — merge happens later (manual for `draft`, caller for `skip-ci-wait` and `per-task-pr`).\n\n**Why `git merge --no-ff` specifically** (not cherry-pick, not direct commit on main): preserves original commit SHAs, marks the task boundary in `git log --graph`, and lets `git branch -d` act as a built-in safety check that refuses to delete an unmerged branch. Full rationale lives in the upstream executor's `references\u002Fbranch-lifecycle.md`.\n\n**Error handling**: `git merge` conflict → stop and ask the user to resolve manually (do not auto-abort; the user may want to inspect). `gh pr merge` failure due to conflict\u002Fout-of-date → apply the Step 4 final Merge-Readiness Gate (`references\u002Fpr-conflict-resolution.md`): merge the base into the feature branch and re-verify, or return `BLOCKED` on a real textual conflict. Other `gh pr merge` failures → stop and report. Push rejected (remote moved) → stop; never force-push.\n\n### Step 6: Post-Merge Verification (hard gate)\n\nFor `--mode normal-pr` and `--mode local-merge`:\n```bash\ngit log -1 --format=\"%s\"\n```\nThe output **must** begin with `Merge branch 'feature\u002F`. If not, the merge did not execute correctly — investigate and retry before proceeding to Step 7. Do not write a completion marker for a merge that did not happen; downstream tasks would resolve dependencies against a broken contract. When `--worktree-path \u003Cpath>` is set, run this check as `git -C \u003Cpath> log -1 --format=\"%s\"`.\n\n### Step 7: Mark Task Complete\n\nFor `--mode normal-pr` and `--mode local-merge`:\n\nUse the shared marker script — it handles the `.gitignore` branch, the mandatory marker commit, and the post-move verification in one deterministic step (exits non-zero if anything failed):\n\n```bash\nbash \"${CLAUDE_SKILL_DIR}\u002F..\u002Fscripts\u002Fmark-complete.sh\" \u003Ctasks-dir> \u003Ctask-name> [--push | --defer-push]\n```\n\nThe marker script runs `\"${CLAUDE_SKILL_DIR}\u002F..\u002Fywc-task-generator\u002Fscripts\u002Fcompact-dependency-graph.py\"` between the move and marker commit, using the same resolved `\u003Ctasks-dir>`, and stages the resulting graph when it is tracked. The heading-based compactor retroactively handles existing graphs: completed phases become `## Phase NNNNNN — done` plus a `- Completed: ...` bullet, while fully completed Parallel Execution Notes and Visual Dependency Graph sections are removed. In worktree mode, the script path may come from the main checkout, but `\u003Ctasks-dir>` must resolve inside `\u003Cpath>`.\n\nWhy a script, not inline git: `git mv` cannot stage a path inside a gitignored `\u003Ctasks-dir>` (the move produces no diff), so that case needs a plain `mv` plus an `--allow-empty` marker commit, while a tracked `\u003Ctasks-dir>` uses `git mv`. The script detects which applies. The `chore: mark \u003Ctask-name> as completed` commit is **mandatory in both cases** — it is the `git log` audit boundary that humans, audit tooling, downstream skills, the Completion Report, and resume \u002F replay all rely on to verify task completion at a specific commit. The script then verifies the move (destination exists, source gone, marker commit at HEAD) and exits non-zero if any check fails; **do not declare `DONE` on a non-zero exit** — investigate and retry.\n\nWhen `--worktree-path \u003Cpath>` is set, run `mark-complete.sh` so its `git check-ignore` \u002F `git mv` \u002F `git commit` and post-move `git log` operate on the worktree (invoke it with the worktree as the working directory, e.g. `cd \u003Cpath> && bash \"${CLAUDE_SKILL_DIR}\u002F..\u002Fscripts\u002Fmark-complete.sh\" …`); the `\u003Ctasks-dir>` move acts on `\u003Cpath>\u002F\u003Ctasks-dir>\u002F…` directly, and the verification checks resolve against the worktree's HEAD (see [Worktree-path mode](#worktree-path-mode)).\n\n**Push strategy**: pass `--push` to `mark-complete.sh` for `--mode local-merge` and for `--mode normal-pr` when `--defer-push` is **not** set. Otherwise pass `--defer-push` (the script's default) so the caller can batch completion-marker commits and push them once at the end of the range. The caller is responsible for the eventual push when deferral is requested.\n\nFor `--mode draft`, `--mode skip-ci-wait`, `--mode per-task-pr`: skip Step 7 entirely. The task is not yet merged; marking it complete would be incorrect.\n\n### Step 8: Local Branch Cleanup\n\nFor `--mode normal-pr`:\n```bash\nBASE='\u003Cbase-branch>'                   # validated value only (Remote deletion guard rule, Step 5)\nBRANCH='feature\u002F\u003Ctask-name>'           # validated value only (same rule)\ngit checkout \"$BASE\"\ngit pull origin \"$BASE\"\ngit branch -d \"$BRANCH\"                # omit when --keep-branch is set\n```\nValidate `BASE` and `BRANCH` per the Step 5 Remote deletion guard rule before this block (on failure return `BLOCKED: invalid branch name` and run no git command); quote every use.\n\nThe local branch must be deleted explicitly because `gh pr merge --delete-branch` only removes the remote. Skip the deletion when `--keep-branch` is set — the caller (typically `ywc-parallel-executor`) will release the worktree and delete the branch in its own cleanup step. When `--worktree-path \u003Cpath>` is set, run all three commands as `git -C \u003Cpath> …` (here `\u003Cbase-branch>` is the run's integration branch); the per-task `feature\u002F\u003Ctask-name>` deletion is safe because the worktree HEAD is on the integration branch per the [Worktree-path mode](#worktree-path-mode) invariant.\n\nFor `--mode local-merge`: already handled inside Step 5's command sequence (which honors `--keep-branch` likewise).\n\nFor all other modes: skip. The branch stays alive for the user or caller to handle.\n\n**Worktree prune (when caller used a worktree)** — if the caller created a per-task worktree (`ywc-parallel-executor` does this), the post-cleanup prune is delegated to the [`ywc-worktrees`](..\u002Fywc-worktrees\u002F) skill:\n\n```bash\nywc-worktrees --mode prune --task-name \u003Ctask-name>\n```\n\n`ywc-worktrees --mode prune` runs the bundled `cleanup-worktree.sh` against the resolved worktree path — `git worktree remove` + local `git branch -d` + `git worktree prune` + post-removal verification, refusing to operate on dirty worktrees without `--force`. This skill does not inline the prune logic; the worktree priority chain (`.worktrees\u002F` > CLAUDE.md `worktree_root` > `--root` fallback) and the dirty-tree safety check live in one place. Skip this delegation when no worktree was created (the typical `--mode local-merge` \u002F `--mode normal-pr` flow that ran inside the main checkout).\n\n## Output Format\n\n```text\n## Finish Branch Result: \u003Ctask-name>\n\n### Mode\n\u003Cmode>\n\n### Outcome\n- PR: \u003Cpr-url-or-\"none-local-merge\">\n- Merge: \u003Ccommit-sha-or-\"deferred\">\n- Mark Complete commit: \u003Ccommit-sha-or-\"skipped\">\n- Local branch: \u003C\"deleted\"|\"preserved\">\n\n### Verification\n- Post-merge gate: \u003Cpassed|skipped|failed>\n- Post-move gate: \u003Cpassed|skipped|failed>\n\n### Completion Status\n\u003CDONE | DONE_WITH_CONCERNS | BLOCKED | NEEDS_CONTEXT>\n```\n\n**Completion Status rules:**\n\n| Status | When to use |\n|---|---|\n| `DONE` | All applicable steps for the chosen mode succeeded; verification gates passed |\n| `DONE_WITH_CONCERNS` | Delivery succeeded but with caveats (e.g., advisor budget exceeded for the bot-polling loop, or `--defer-push` was set and the caller now owns the push) |\n| `BLOCKED` | Cannot proceed — merge conflict, CI failure unfixable in 2 attempts, push rejected, or post-merge verification failed |\n| `NEEDS_CONTEXT` | One of `--branch`, `--base-branch`, `--task-name`, `--tasks-dir`, or `--mode` was missing or invalid; no work was performed |\n\n## Banned Output Patterns\n\nThis skill produces operational side effects (commits, pushes, merges), not source code. The \"Banned Output Patterns\" idea applied here means: **never** declare `DONE` while leaving any of the following:\n\n- A merge commit that the post-merge verification step did not confirm\n- A `chore: mark \u003Ctask-name> as completed` commit that has not been verified by the post-move test\n- A local feature branch that should have been deleted (modes `normal-pr` and `local-merge`, when `--keep-branch` is **not** set)\n- An unpushed commit when push was required (modes `local-merge` always; `normal-pr` when `--defer-push` is not set)\n\nEach of these is a hidden defect that breaks the next task's dependency resolution. Surface them honestly via `DONE_WITH_CONCERNS` or `BLOCKED` rather than declaring `DONE`.\n\n## Integration\n\n- **upstream**: `ywc-sequential-executor` (replaces its Steps 5–8), `ywc-parallel-executor` (replaces the merge + mark-complete portion of Step 4e–4f; worktree cleanup at Step 4g stays in parallel).\n- **internal delegation**: `ywc-create-pr` (Step 2), `ywc-handle-pr-reviews` (Step 4 inside the bot polling loop).\n- **shared references**: [..\u002Freferences\u002Fpr-bot-polling.md](..\u002Freferences\u002Fpr-bot-polling.md) (CI + bot polling), [..\u002Freferences\u002Flocal-merge-permissions.md](..\u002Freferences\u002Flocal-merge-permissions.md) (pre-authorized git\u002Fgh patterns the caller must set), [..\u002Freferences\u002Fsubagent-status-actions.md](..\u002Freferences\u002Fsubagent-status-actions.md) (how the caller responds to this skill's status return), [..\u002Freferences\u002Fpr-conflict-resolution.md](..\u002Freferences\u002Fpr-conflict-resolution.md) (merge-readiness gate and conflict resolution procedure).\n\n## Notes\n\nThis skill is a single-task delivery unit. It does not iterate over a range, manage a wave, or maintain checkpoint state — those concerns belong to the calling executor. Worktree **creation and removal** are intentionally out of scope, because the lifecycle differs between callers; placing it here would force one of them to special-case its cleanup. What this skill *does* support is **operating inside a caller-supplied worktree** via `--worktree-path` (see [Worktree-path mode](#worktree-path-mode)): `ywc-sequential-executor --worktree` runs its whole range inside one run worktree and passes that path so finish-branch's git commands target the worktree HEAD, while the worktree's own create\u002Fprune lifecycle stays with that caller. The historical \"sequential (no worktree)\" assumption now reads: sequential delivers in the main checkout *unless* `--worktree` is active, in which case `--worktree-path` redirects the git commands; parallel still owns its per-task worktrees.\n",{"name":5,"phase":23,"version":24,"category":25,"requires":26,"description":7,"advisor_budget":28},"execution","1.0.0","delivery",[27],"ywc-create-pr",1,"main","7e8ac872e53df8c89d75663e031626281a2a2f5c","claude-code\u002Fskills\u002Fywc-finish-branch","https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit","https:\u002F\u002Fgithub.com\u002Fyongwoon","https:\u002F\u002Fwww.webhani.com","2026-11-08 17:14:59",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add yongwoon\u002Fywc-agent-toolkit --skill ywc-finish-branch",{"tool":42,"command":43},"bunx","bunx skills add yongwoon\u002Fywc-agent-toolkit --skill ywc-finish-branch",{"tool":45,"command":46},"pnpm","pnpm dlx skills add yongwoon\u002Fywc-agent-toolkit --skill ywc-finish-branch","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fclaude-code\u002Fskills\u002Fywc-finish-branch\u002FSKILL.md",true,[50,56,60,64,68,71,75,81],{"path":51,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":54,"sourceHtmlUrl":55},"README.en.md","REFERENCE","参考文档",3090,"https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fclaude-code\u002Fskills\u002Fywc-finish-branch\u002FREADME.en.md",{"path":57,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":58,"sourceHtmlUrl":59},"README.es.md",3184,"https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fclaude-code\u002Fskills\u002Fywc-finish-branch\u002FREADME.es.md",{"path":61,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":62,"sourceHtmlUrl":63},"README.ja.md",3215,"https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fclaude-code\u002Fskills\u002Fywc-finish-branch\u002FREADME.ja.md",{"path":65,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":66,"sourceHtmlUrl":67},"README.ko.md",3138,"https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fclaude-code\u002Fskills\u002Fywc-finish-branch\u002FREADME.ko.md",{"path":69,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":66,"sourceHtmlUrl":70},"README.md","https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fclaude-code\u002Fskills\u002Fywc-finish-branch\u002FREADME.md",{"path":72,"resourceType":52,"resourceTypeDesc":53,"sizeBytes":73,"sourceHtmlUrl":74},"README.zh.md",3009,"https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fclaude-code\u002Fskills\u002Fywc-finish-branch\u002FREADME.zh.md",{"path":76,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":79,"sourceHtmlUrl":80},"scripts\u002Fbuild-pr-title.py","SCRIPT","脚本",4675,"https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fclaude-code\u002Fskills\u002Fywc-finish-branch\u002Fscripts\u002Fbuild-pr-title.py",{"path":82,"resourceType":77,"resourceTypeDesc":78,"sizeBytes":83,"sourceHtmlUrl":84},"tests\u002Fbuild-pr-title-test.sh",3425,"https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fclaude-code\u002Fskills\u002Fywc-finish-branch\u002Ftests\u002Fbuild-pr-title-test.sh",[86,92,98,105,112,119],{"skillNo":87,"name":88,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":18},"01M72TQ84GTCPCV2VJ778V17TW","missing-frontmatter","https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fscripts\u002Ffixtures\u002Fcodex-description-limit\u002Fmissing-frontmatter\u002FSKILL.md",[],[],{"skillNo":93,"name":94,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":95,"categories":96,"keywords":97,"publishedAt":18},"01M72TQ6M4BFWE7P9EPW0GZDCM","malformed-frontmatter","https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fscripts\u002Ffixtures\u002Fcodex-description-limit\u002Fmalformed-frontmatter\u002FSKILL.md",[],[],{"skillNo":99,"name":100,"nameZh":6,"description":101,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":102,"categories":103,"keywords":104,"publishedAt":18},"01M72TQ3ESGKXZ4QRWGTX92BKJ","fixture-501-fail","(ywc) Use when aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Do not use for x.","https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fscripts\u002Ffixtures\u002Fcodex-description-limit\u002F501-fail\u002FSKILL.md",[],[],{"skillNo":106,"name":107,"nameZh":6,"description":108,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":109,"categories":110,"keywords":111,"publishedAt":18},"01M72TQ0HJ8H3R37J9WPWGKJZR","fixture-500-pass","(ywc) Use when aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Do not use for x.","https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fscripts\u002Ffixtures\u002Fcodex-description-limit\u002F500-pass\u002FSKILL.md",[],[],{"skillNo":113,"name":114,"nameZh":6,"description":115,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":116,"categories":117,"keywords":118,"publishedAt":18},"01M72TPWNCC7NEYD0D9N12KSQS","ywc-worktrees","(ywc) Use when creating, auditing, pruning, or resolving git worktrees for isolated task workspaces, whether delegated from an executor or used standalone. Triggers: \"worktree 생성\", \"worktree audit\", \"worktree 정리\", \"worktree prune\", \"ywc-worktrees\", \"create worktree\". Do not use for branch creation\u002Fdeletion alone, PR creation (use ywc-create-pr), CI or merge delivery (use ywc-finish-branch), task orchestration (use ywc-sequential-executor or ywc-parallel-executor), or non-git isolation.","https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fplugins\u002Fywc-agent-toolkit\u002Fskills\u002Fywc-worktrees\u002FSKILL.md",[],[],{"skillNo":120,"name":121,"nameZh":6,"description":122,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":9,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":123,"categories":124,"keywords":125,"publishedAt":18},"01M72TPRNR3E6QWB91GM98ABBV","ywc-wayfinder","(ywc) Use when a large or uncertain change needs multi-session discovery with a deterministic local map and exactly one active ticket before planning or implementation. Triggers: \"wayfinder\", \"길찾기\", \"discovery map\", \"multi-session discovery\", \"탐색 ticket\", \"経路整理\", \"探索マップ\", \"ywc-wayfinder\". Do not use for ordinary planning (use ywc-plan), idea clarification (use ywc-brainstorm), direct implementation, or tracker\u002Fdatabase writes outside the local Markdown map.","https:\u002F\u002Fgithub.com\u002Fyongwoon\u002Fywc-agent-toolkit\u002Fblob\u002Fmain\u002Fplugins\u002Fywc-agent-toolkit\u002Fskills\u002Fywc-wayfinder\u002FSKILL.md",[],[]]