Implement a GitHub Story end to end, across every layer it touches (db, backend, frontend), in one spec-driven cycle, with ponytail code: resolve → explore → propose → apply [with ponytail] → verify → commit → archive → PR. The Story's Task sub-issues are its checklist and are closed at the end. Use when the user provides a Story issue number, a Story ID like 'FS-AUTH-1' from a backlog generated by prd-to-github-backlog, a single Task ID like 'FS-AUTH-1-T1', or says 'implement story #N', 'wor...
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Spec Apply?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/orrrrli-spec-apply)
---
name: spec-apply
stacks: [all]
description: "Implement a GitHub Story end to end, across every layer it touches (db, backend, frontend), in one spec-driven cycle, with ponytail code: resolve → explore → propose → apply [with ponytail] → verify → commit → archive → PR. The Story's Task sub-issues are its checklist and are closed at the end. Use when the user provides a Story issue number, a Story ID like 'FS-AUTH-1' from a backlog generated by prd-to-github-backlog, a single Task ID like 'FS-AUTH-1-T1', or says 'implement story #N', 'work on FS-AUTH-1', 'list my stories', or 'spec-apply N'."
trigger: /spec-apply
---
# /spec-apply [issue#] [full|light] (with Ponytail Principles)
Implement a **Story** in **one cycle** through the phases below, covering every layer the Story
touches. Its **Task sub-issues are the checklist** of that cycle, not separate iterations: they are
all planned together, built together, verified together and closed together. Never skip a phase.
If given a single Task ID, run the same cycle scoped to that one task. **Applies ponytail
principles during the Apply phase** to favor the simplest, most minimal solution that works.
## Execution model
```
Phase 0 Resolve → Story# + its open Task sub-issues (the checklist); set up the Story worktree;
estimate XL → STOP and propose a split
AC missing/untestable → business-analyst drafts them ⏸ STOP for approval
Phase 1 Explore (no stop gate — report and continue)
Phase 2 Propose ⏸ STOP: one plan for every layer + the contract; wait for OK before writing code
Phase 3 Apply → Apply with ponytail principles (laziest solution that works)
Phase 4 Verify → spec-verify on the whole Story (code-reviewer) [+ security-auditor]; on failure STOP
Phase 4.5 Commit (the Story's one commit)
Phase 5 Archive (comment on the Story, close every Task in the checklist)
Phase 6 Finish → push the Story branch and open one PR for the Story
(light mode: draft + deferred-checks; a later full run finishes it)
```
## Prerequisites
```bash
gh auth status # must succeed with repo + project scope
```
---
## Naming convention (how the backlog encodes the hierarchy)
`prd-to-github-backlog` creates every issue with the title `"<ID>: <title>"`, and the
**ID itself encodes the parent chain** — so you never have to guess relationships:
| Level | ID convention | Example title | Labels |
|-------|--------------------|----------------------------|------------------------------|
| Epic | `EPIC-<SLUG>` | `EPIC-AUTH: Authentication`| `type:epic` |
| Story | `<AREA>-<EPIC>-<n>`| `FS-AUTH-1: Sign in` | `type:story`, `area:<area>` |
| Task | `<story-id>-T<k>` | `FS-AUTH-1-T1: Add route` | `type:task`, `area:<area>` |
`FS` stories are vertical slices: their tasks mix `area:backend` and `area:frontend`. The cycle
builds all of them at once, so the frontend is written against the same contract the backend
implements.
Derivation rules:
- **Task → Story:** strip the trailing `-T<k>`. `FS-AUTH-1-T1` → story `FS-AUTH-1`.
- **Story → Epic:** the story's `<EPIC>` segment maps to epic `EPIC-<EPIC>`. `FS-AUTH-1` → `EPIC-AUTH`.
- Tasks and stories also have **real GitHub sub-issue parent links** — use those as the source of truth.
---
## Phase 0 — Resolve the Story and its tasks
**Goal:** Turn whatever the user gave you (raw `#N`, a Story ID like `FS-AUTH-1`, a Task ID like
`FS-AUTH-1-T1`, or "list my stories") into a concrete **Story issue number**, its **Epic number**,
and the **checklist of its open Task sub-issues**. Then set up the Story worktree.
**Runtime mode first:** the last word of `$ARGUMENTS` may be `full` or `light`
(`/spec-apply 475 full`) → that wins. Otherwise `cat ~/.claude/runtime-mode 2>/dev/null`, where a
missing file means `full`. `full` → the slice checks (e2e, browser check) run against this
worktree's own stack. `light` → they are deferred, the Story still ships its code once the tests that
need no running stack pass, and its PR opens as a draft. State the mode in the Phase 0 exit gate.
**Catch-up (full mode only):** if the Story already has an open draft PR labeled `deferred-checks`
(`gh pr list --repo <owner/repo> --head feat/<STORY_ID> --label deferred-checks --json number`),
do not run the cycle again. After steps 1-8 below resolve the Story and its worktree, run only:
1. `spec-verify <STORY_ID>` on the committed branch (clean tree → `<BASE>...HEAD`).
2. PASS → remove the PR's `## Deferred checks` section, `gh pr edit <pr#> --remove-label
deferred-checks`, `gh pr ready <pr#>`, then close the Story's Tasks as in Phase 5.
3. FAIL → the Phase 4 failure policy: one fix, committed as `fix(<STORY_ID>): <summary>`, pushed,
verified again. Still failing → STOP; the PR stays draft.
Resolve via the **manifest as a cache, verified against the live board** (the chosen strategy):
1. **Read config from the manifest** if present (`manifest.json` at repo root or alongside the
backlog skill output). Pull `owner`, `repo`, `project_number`, and the `epics[].stories[].tasks[]`
tree. The manifest IDs let you map a Story ID → Epic ID and enumerate its Tasks offline.
- If there is **no manifest**, fall back to pure `gh` label/title queries below.
2. **List stories** (use when the user says "list my stories" or gives ambiguous input):
```bash
gh issue list --repo <owner/repo> --label type:story --state open --limit 100
```
3. **Resolve the input → a Story issue number** (exact title prefix match):
```bash
# If given a Story ID (FS-AUTH-1):
gh issue list --repo <owner/repo> --label type:story --state all \
--search "in:title <STORY_ID>" --json number,title \
--jq '.[] | select(.title | startswith("<STORY_ID>:")) | .number'
# If given a Task ID (FS-AUTH-1-T1): strip the trailing -T<k> to get the Story ID, then as above.
# If given a raw #N: check its type:* label. If type:task, walk up to its parent story.
```
4. **Enumerate the Story's Task sub-issues** (source of truth = live sub-issue links):
```bash
gh api repos/<owner/repo>/issues/<story#>/sub_issues \
--jq '.[] | {number, title, state}'
```
Keep only **open** tasks: they are the checklist the cycle must cover. Skip tasks already
closed and note them.
5. **Verify against the live board** — confirm the story's parent epic matches the manifest:
```bash
gh api repos/<owner/repo>/issues/<story#>/parent --jq '.number' # epic number
```
If the live links disagree with the manifest, **trust the live board** and note the drift.
6. **Check the Story's size** — one cycle means one review of the whole Story, and the Story's
size sets the size of that diff. Read the estimate from the Story body (`**Estimate:** <size>`)
or the manifest `estimate`. If it is **XL**, **STOP** before any code: propose a split into
thinner vertical slices, each a full behavior across its layers (email sign-in, then OAuth),
never by layer. The user decides; the split is applied in the backlog, not here. A single-task
input skips this check.
7. **Resolve the base branch** — do NOT hardcode it. Take it from the project config in this order:
manifest `base_branch` → repo default (`gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'`)
→ `main`. Call it `<BASE>` and reuse it in Phase 6.
8. **Set up the Story worktree** — one worktree and one branch per Story, so parallel sessions
never share a working tree. Every commit goes onto `feat/<STORY_ID>`. Never `git checkout` in
the current tree and never `cd`.
```bash
git fetch origin <BASE>
main=$(dirname "$(git rev-parse --path-format=absolute --git-common-dir)")
git branch --show-current
git worktree list --porcelain
```
- Current branch is `feat/<STORY_ID>` → you are in the Story worktree. `git pull --ff-only` if it
has an upstream, then continue.
- `feat/<STORY_ID>` is checked out in another worktree → **STOP**: "Open a session in `<path>` and
run `/spec-apply <STORY_ID>` there."
- Otherwise create it (the post-checkout hook links the local Claude harness and the ignored `.env*` files into it):
```bash
git worktree add -b feat/<STORY_ID> "$main-<STORY_ID>" origin/<BASE> # new branch
git worktree add "$main-<STORY_ID>" feat/<STORY_ID> # branch already exists
```
Then **STOP**: "Worktree ready at `<path>`. Open a session there and run `/spec-apply <STORY_ID>`."
9. **Check the Story's acceptance criteria** — the cycle and `spec-verify` are judged against them:
```bash
gh issue view <story#> --repo <owner/repo> --json body --jq '.body'
```
Testable means Given/When/Then with an observable outcome. A `fullstack` Story also needs at
least one criterion the user observes in the UI ("Then sees the dashboard", not only "Then
returns 200"): without it the frontend has nothing to be verified against. If they are present
and testable, continue. If they are missing or untestable (e.g. "works well", "good UX"), or a
`fullstack` Story has no UI-observable criterion:
- Dispatch `business-analyst`. It cannot see this conversation or run `gh`, so the prompt
carries the Story body and the Epic body verbatim, plus the paths to `CLAUDE.md` and
`business/rules.md`. Ask for Given/When/Then criteria returned in the report, no files written.
For a `fullstack` Story, say it is a vertical slice and ask for at least one criterion
observable in the UI.
- Show them to the user. **STOP** and wait for approval or edits.
- Once approved, append them to the Story under `## Acceptance criteria` so `spec-verify` reads
the same ones:
```bash
gh issue view <story#> --repo <owner/repo> --json body --jq '.body' > /tmp/story-<story#>.md
# append the approved criteria to that file, then:
gh issue edit <story#> --repo <owner/repo> --body-file /tmp/story-<story#>.md
```
**Single-task input:** if the user explicitly named one Task ID/number and asked for just that,
the checklist is that one task (still in the Story worktree), and the cycle covers only the AC
that task serves.
**Exit gate:** State the resolved `Story #<n> (<STORY_ID>)`, `Epic #<n> (<EPIC_ID>)`, the
estimate, the runtime mode, the base branch `<BASE>`, the working branch `feat/<STORY_ID>` and its worktree path,
and the **checklist** (`Task #<n> (<TASK_ID>) [area]` each). If the input matched zero or many
stories, list the candidates and ask which one. Then continue to Phase 1.
---
> `<story#>` / `<epic#>` stay fixed for the whole run. `<SCOPE_ID>` is `<STORY_ID>`, or the
> Task ID on a single-task input.
## Phase 1 — Explore
**Goal:** Understand the whole Story before touching a single file. Use the `Story #`, `Epic #` and
the checklist resolved in Phase 0.
1. Fetch the Story (the AC are the exit criteria for Phase 4) and every Task in the checklist:
```bash
gh issue view <story#> --repo <owner/repo>
gh issue view <task#> --repo <owner/repo> # once per checklist task
```
2. Fetch the Epic for broader context:
```bash
gh issue view <epic#> --repo <owner/repo>
```
3. **Read the project context index** — find it using this fallback order:
```
CLAUDE.md at the repo root → AGENTS.md → the parent directory's CLAUDE.md (hub)
```
Once you find the index, read it to locate these files (most will be linked in the index):
- `business/overview.md`, `business/rules.md` — domain constraints, success metrics
- `domains/[entity].md` — detailed model for each entity this Story touches
- `architecture/overview.md`, `architecture/integrations.md` — patterns, stack, external services
- `engineering/standards.md`, `engineering/testing.md` — coding conventions, test approach
**Always read the context files; do not skip because the Story "looks simple."**
4. Locate the relevant code in **every layer** the checklist touches (db/migrations, backend,
frontend). Report exact file paths and line numbers.
**Report (no stop gate):** State in plain language, then continue straight to Phase 2:
- What the Story requires, end to end
- Which files will change per layer and why
- Any risks or ambiguities
---
## Phase 2 — Propose
**Goal:** Define the approach for the whole Story before writing code.
Start with the riskiest decision in the Story (data shape, where a responsibility lives, a
contract other code will depend on). Give 2 or 3 real approaches for it, each with its
tradeoff, and recommend one. If only one approach fits the codebase, say so in one line and
why; never invent alternatives to fill the slot. The plan below builds on the recommended one.
Produce one implementation plan, with a section per layer touched (db, backend, frontend):
- **The contract** between layers, when the Story crosses one: route and method, request and
response shapes (field names and types), status codes and the error shape. The code in
Phase 3 follows it exactly.
- What interfaces / signatures change (if any)
- Which layer(s) are touched (domain / application / infrastructure / presentation)
- Whether new files are needed
- Whether any dependency is required — if so, name it explicitly and wait for approval
- Any architectural decision that deviates from existing patterns — flag it and ask
- Responsibilities: list each distinct one (business rule, persistence, security, external
call, presentation) and where it lives: an existing component, a new one with its reason,
or a framework capability (e.g. ASP.NET Identity, NextAuth). Security never lives in an
ad-hoc check when the framework provides it.
- Checklist coverage: which part of the plan delivers each Task. A Task the plan does not
cover is named here with the reason.
**Exit gate:** Present the plan. STOP and wait for explicit user confirmation before writing any code.
---
## Phase 3 — Apply (with Ponytail Principles)
**Goal:** Implement exactly what was proposed, across every layer. Nothing more. **Apply ponytail principles: favor the laziest solution that actually works.**
Rules:
- Only modify files identified in Phase 2
- **Implement the Phase 2 contract exactly.** A change to it means STOP and re-propose: the
other layer was built on it.
- **Write no new tests.** Keep the existing suite green. Never edit, skip, delete or weaken a
test, and never touch test or CI config to get green. If a test looks wrong, STOP and report
it: a wrong test usually means an ambiguous AC, and that is the user's call.
- **Apply the ponytail ladder during implementation.** Bug fixes go to the root cause.
- **Follow the coding conventions and patterns** from:
- `engineering/standards.md` (naming, structure, test strategy)
- `business/rules.md` (domain constraints that code must enforce)
- `domains/[entity].md` (entity-specific rules and relationships)
- No new dependencies without asking
- No refactoring outside the Story scope — note suggestions after completing
- If you discover something unexpected mid-implementation, STOP and report it
- **Mark deliberate simplifications with a `ponytail:` comment** (e.g., `# ponytail: using existing util instead of new class`)
After each file change, state: file path + what changed + why.
**Output pattern:** `[code] → skipped: [X], add when [Y].`
---
## Phase 4 — Verify
**Goal:** Prove the Story is done against its acceptance criteria, end to end, with a reviewer that
did not write the code.
1. **Self-check first** (cheap, before spending a review):
- [ ] Existing tests still pass in every layer (`npm run test` / `dotnet test` / equivalent).
In `light` mode, only the ones that need no running stack (skip e2e).
- [ ] No test file was modified (`git diff --stat` lists none)
- [ ] No files outside Phase 2 scope were modified
2. **Independent review**, uncommitted, in ONE message so they run concurrently:
- Invoke the `spec-verify` skill with `<SCOPE_ID>`, plus the mode word (`full` or `light`)
this run resolved. It runs in a fresh `code-reviewer` subagent, reads the Story's AC from
GitHub, reviews the uncommitted implementation, runs the tests, and returns PASS/FAIL per
criterion, including the browser check against the real backend on web projects.
- **Also** dispatch `security-auditor` when the diff touches auth, sessions/tokens, permissions,
payments, webhooks, or untrusted input. Its prompt must stand alone: the Story's AC verbatim,
the diff command (`git diff HEAD`), and the
paths to `CLAUDE.md` and `engineering/standards.md`.
3. **Act on the reports:** reviewers never edit. Fix blocking findings yourself; list minor ones in
the Phase 5 comment instead of fixing them.
`PASS (DEFERRED)` from spec-verify (light mode) counts as a pass for Phase 4.5: keep its list of
`~ DEFERRED` criteria for Phase 6.
**Failure policy:** If `spec-verify` returns FAIL or the security-auditor reports a critical/high
issue, make **one** attempt to fix it in Phase 3 and verify again. If it still fails, **STOP the
Story** here — do NOT commit the failing implementation, close no Task, and report: which criteria fail, why, and what's left.
---
## Phase 4.5 — Commit
**Goal:** The Story's one commit, only after Verify passes.
```bash
git add <files from Phase 2 scope>
git commit -m "<type>(<SCOPE_ID>): <Imperative summary>"
# e.g. feat(FS-AUTH-1): Sign in with email and password
```
Rules:
- **Conventional Commits format** (`feat`, `fix`, `refactor`, `test`, …) — projects set up by
`harness.sh` reject any subject that is neither conventional nor ticket-first through the git `commit-msg` hook that
`core.hooksPath` points to in clawd-harness (`global/githooks/`).
Pick the type that matches the Story.
- **Subject line only — no body, no trailers.** The scope is the Story ID (or the Task ID on a
single-task input). Tasks are closed in Phase 5 with `gh issue close`, and the Story PR body
lists `Closes #<task#>`, so the commit needs no `Closes` line.
- Commit **only** the files this Story changed (they should match Phase 2 scope).
---
## Phase 5 — Archive
**Goal:** Close the loop on GitHub for the whole checklist.
1. Comment on the Story with a brief summary of what was implemented:
```bash
gh issue comment <story#> --repo <owner/repo> --body "Implemented: <one-line summary per layer>. Commit: <sha>. Files changed: <list>. Minor review notes: <list or none>."
```
2. Close every Task in the checklist that the plan covered. A Task left out in Phase 2 stays open
and is named in the Phase 6 report. After a `PASS (DEFERRED)`, close none: the full-mode
catch-up closes them once the slice passes, so the board never shows an unverified Story as done:
```bash
gh issue close <task#> --repo <owner/repo> --comment "Done in <sha> (<STORY_ID>)."
```
---
## Phase 6 — Finish the Story
**Goal:** Ship the Story as one PR.
1. Push the Story branch:
```bash
git push -u origin feat/<STORY_ID>
```
2. Open **one PR named after the Story** — title = the Story's full issue title
(`<STORY_ID>: <story title>`):
```bash
gh pr create --repo <owner/repo> --base <BASE> --head feat/<STORY_ID> \
--title "<STORY_ID>: <story title>" \
--body-file <scratchpad>/pr.md
```
Write `pr.md` with the `pr-body` skill. `## What` names Story #<story#>
(<STORY_ID>) and ends with one `Closes #<task#>` line per task the plan covered. A task left
out goes under `## Not changed`.
After a `PASS (DEFERRED)`: add `--draft --label deferred-checks` (create the label once with
`gh label create deferred-checks --repo <owner/repo> --force`), and add a `## Deferred checks`
section listing each `~ DEFERRED` criterion and the check it waits for. A draft cannot be
merged; only the full-mode catch-up marks it ready.
3. Report done: the PR URL, the tasks closed, and anything left open or for a follow-up. A draft
PR ends with: "Slice checks deferred (light mode). Run `/spec-apply <STORY_ID> full` to
finish." Only if this run started the Story's stack (full mode), close with: "After merge,
stop the Story's containers and drop its volume (`docker compose -p <COMPOSE_PROJECT_NAME from
.env.worktree> down -v`) before deleting the worktree." Never give commands to remove the
worktree, its symlinks or its branch; the user removes them from Orca.
---
## Hard rules
- **One Story per invocation, in one cycle.** The unit of work is a Story across every layer it
touches; its open Tasks are the checklist, never separate iterations. If the user names
multiple stories, ask which one to start with.
- **Never implement an Epic directly.** If given an Epic number/ID, list its Story sub-issues and ask
which Story to run.
- **Never run an XL Story.** Stop in Phase 0 and propose a split into thinner vertical slices.
- **Always read the project context** (Phase 1, step 3). Do not skip because the Story "looks simple."
This ensures code conforms to domain rules, business constraints, and engineering standards.
- **One Propose gate per Story:** stop and wait for approval of the whole plan, contract included,
before writing code.
- **No new tests.** The Story keeps the existing suite green and never edits it.
- **Stop on verify failure:** one fix attempt, then halt the Story and report. No Task is closed.
- If the Story `depends_on` another issue (manifest / Story body), check that dependency is closed
before starting Phase 3.
- **A draft PR with `deferred-checks` leaves draft only after a full-mode run passes.** Never mark it
ready by hand from light mode.
- **Ponytail principles must be applied during Phase 3 (Apply)** — favor simplicity, reuse, and minimalism.