/spwf:branch-rescuefrom spwf
Recovery skill — moves commits that landed on the base branch onto a proper feature branch and resets local base, without touching origin. Resolves the active OpenSpec change, detects the pre-spec base commit (subject-line grep with manual-confirm fallback), performs three local-only safe git operations, and surfaces the force-push command for the user to run manually. Run standalone; pr-create's rescue offer runs the same procedure inline (_shared/branch-management.md §4), because this skill is user-only.
Ships in spwf. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Move commits that leaked onto the base branch onto ${prefix}${change_id} and
reset local base — local-only, never force-pushing to the remote. Delegates the
operation logic to _shared/branch-management.md §4.
Use this when work has already accumulated on main (the failure mode the
spec/build layers prevent going forward) and you need to recover.
Variables. Step 1 resolves
prefix,base, andchange_id; Step 2 derivesSPEC_COMMITandBASE_COMMIT. Every later step uses these — same casing as_shared/branch-management.md§4 (lowercase config, uppercase derived). Do not reference a variable before its assigning step.
Resolve config from .spwf/branch.yaml (defaults when the file or a field is
absent) and the active OpenSpec change. See
§1 for the full
schema.
prefix=$(sed -n 's/^prefix:[[:space:]]*//p' .spwf/branch.yaml 2>/dev/null); prefix=${prefix:-feature/}
base=$(sed -n 's/^base:[[:space:]]*//p' .spwf/branch.yaml 2>/dev/null); base=${base:-main}
change_id=$(openspec list --json 2>/dev/null | jq -r '.[0].name')
If no active change is found (change_id empty or null), halt — do not touch
any branch:
No active OpenSpec change found — nothing to rescue.
Validate the change-id before any substitution (OpenSpec slug rule):
echo "$change_id" | grep -Eq '^[a-z][a-z0-9-]+$' || { echo "Invalid change-id"; exit 1; }
Then grep the base branch for the spec commit and take its parent (§4 base-commit detection):
SPEC_COMMIT=$(git log "${base}" \
--grep "^spec: add OpenSpec change ${change_id}$" --format=%H | head -1)
BASE_COMMIT=$(git rev-parse "${SPEC_COMMIT}^")
Fallback (no match). If SPEC_COMMIT is empty (edited spec message or
squash-merge), do NOT pick a commit silently. Show the recent history and ask
the user for the SHA, then confirm before using it:
git log "${base}" --oneline | head -20
"No
spec:commit found for${change_id}. Enter the SHA of the last commit that should stay on${base}(the commit BEFORE this change's work began):"
After the user supplies a SHA, set BASE_COMMIT to it, echo it back with its
subject, and require an explicit confirmation before proceeding.
Run atomically, in order (§4 recipe):
git checkout -b "${prefix}${change_id}" # 1. preserve work on the feature branch
git checkout "${base}" && git reset --hard "${BASE_COMMIT}" # 2. reset local base
# 3. verify base vs origin (explicit equality — rev-parse with two args only prints, never compares)
if git rev-parse --verify -q "origin/${base}" >/dev/null; then
[ "$(git rev-parse "${base}")" = "$(git rev-parse "origin/${base}")" ] \
&& echo "origin/${base} unchanged" \
|| echo "⚠ local ${base} diverged from origin/${base}"
fi
The verification declares the local-only part clean only when ${base} equals
origin/${base}. If they differ, the leaked commits had been pushed — that is
expected, and Step 4 surfaces the manual force-push. If origin/${base} does
not exist locally (never pushed), the check is skipped and there is nothing to
publish.
If local ${base} diverged from origin/${base} because the leaked commits had
been pushed, print exactly (the ${base} value is substituted in — on the
default it reads main):
Local ${base} reset to ${BASE_COMMIT}. To publish: git push --force-with-lease origin ${base}
Never run git push --force automatically. Force-pushing to the shared base
is a destructive action that stays in the user's hands.
## Rescue complete: ${change_id}
✓ {N} commit(s) moved to `${prefix}${change_id}`
✓ Local `${base}` reset to ${BASE_COMMIT} ({subject})
✓ origin/${base} untouched
{If base diverged from origin:}
⚠ Local `${base}` now diverges from `origin/${base}`.
Publish when ready: git push --force-with-lease origin ${base}
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub simon-potter/spwf --plugin spwf38 skills in this plugin
/address-reviewPhase 6.5 — Address Review. Turn review feedback into action. Sources feedback from either a local report file (e.g. {branch}-review.md from /spwf:pr-review or {branch}-self-review.md from /spwf:simplify) or fetched human comments on an open PR/MR. For each item runs READ → VERIFY → EVALUATE → implement-or-push-back, in priority order (blocking → important → nit). Forbids performative agreement ("you're absolutely right"). Use after pr-review, or whenever a reviewer leaves comments./agent-optimiseCross-cutting — Audit both the project .claude/ and personal ~/.claude/ for quality issues. Covers CLAUDE.md scope and length, agent descriptions, skill frontmatter, and settings.json conflicts. Always audits both scopes. Produces a prioritised P1/P2/P3 fix list./approve-planPhase 2 — Approve plan. Reviews the task list from spec for quality (atomicity, testability, clarity), then applies four adversarial lenses (Skeptic, Architect, Minimalist, Security) as advisory input for the human reviewer. Quality issues are blocking; adversarial findings are advisory. Security lens identifies tasks touching auth, billing, user input, or secrets so the builder has explicit awareness before writing those tasks. Presents everything for explicit human go/no-go before building starts./briefPhase 1.5 — Explain a planned change before it is built. Runs between spec and approve-plan, so a mismatch costs a conversation rather than a change. Five sections, expanding then summarising — what will be built, why this way, the choices you didn't make, what it touches, and a short summary. Never blocks: it prints, offers one skippable prompt, and returns. Calibrated via .spwf/learner.md. Companion to recap and understand, which teach after the fact; this teaches before. Runs on changes, not bug fixes./buildPhase 3 orchestrator — Full Red-Green-Refactor cycle. For each pending task: invokes write-tests (Red: write failing tests), then opsx:apply (Green: implement via OpenSpec), then run-tests (Verify: confirm green before moving on). Loops until all tasks complete. After all tasks complete, runs opsx:verify (spec sign-off), then recommends simplify (Refactor)./capturePre-phase orchestrator — accepts any input (issue tracker ticket, Slack message, file, or freeform description), classifies it as a bug or a change, then routes to the appropriate path. Bug path runs systematic root-cause investigation and produces todo/BUG-{slug}.md. Change path runs a lightweight qualification check and produces todo/{slug}.md. Both outputs feed /spwf:challenge.