Implement
Workflow position: /requirement → START → /issue (loop) → /code-review
# /implement
Workflow position: **/requirement → START → /issue (loop) → /code-review**
Implement the task following the unified requirement doc (which contains story + FE design + BE design + implementation plan with subtasks). Write failing tests first, then implement until all pass.
Arguments: `[task-id]` — e.g. `SP1-T002`
---
## Step 0 — Check brain for reusable patterns (scoped)
Skip entirely if `brain/BRAIN-INDEX.md` does not exist.
Otherwise, follow the access protocol in `.claude/rules/brain.md`:
- Open `MOC-Patterns.md` **only** if the Implementation Plan in `[task-id]-requirement.md` references a known pattern keyword (auth, schema, api-client, state, retry, idempotency, etc.). If no Implementation Plan section calls out a pattern, skip entirely.
- Open `MOC-Lessons.md` **only** if `Points >= 5`, or if the requirement doc's Existing Code Context cites a past failure mode by note ID. Otherwise skip.
- For each matching PAT/LES, read "Solution" + "Example from sprint" only — never the full note.
- **Apply patterns found here** — cite the PAT-NNN in code comments where used.
Print: `Brain: reusing [PAT-NNN], avoiding [LES-NNN warning]` (or `Brain: skipped — no pattern keywords`).
---
## Step 0b — Set up isolated worktree
If the superpowers plugin is available, invoke `Skill("superpowers:using-git-worktrees")` for smart directory selection and safety verification. Otherwise, follow the inline steps below.
Check if already in a worktree:
```bash
git rev-parse --show-toplevel
git worktree list
If already in a dedicated worktree for this task → skip this step, print current path.
If in the main working tree → create an isolated workspace:
Verify
.worktreesis gitignored:git check-ignore -q .worktrees || echo ".worktrees" >> .gitignoreCreate the worktree on the task branch:
git worktree add .worktrees/[task-id] -b [sprint-id]/[task-id]-[short-desc]Branch format:
SP1/SP1-T002-user-auth(per team conventions in CLAUDE.md)Enter the worktree and verify clean baseline:
cd .worktrees/[task-id] # Install deps if needed (npm install / go mod tidy / etc.) # Run test suite — must be GREEN before any new codeIf baseline tests are RED → stop. Investigate before proceeding.
Print: Worktree ready: .worktrees/[task-id] on branch [branch-name]
Note: All sub-agents in Step 2 and Step 3 work inside this worktree. When launching parallel agents, pass the worktree absolute path so they operate on the same isolated workspace — not the main working tree.
Step 1 — Load context
Parse [task-id], extract [sprint-id].
Read in parallel and store content in memory as DOC_OVERVIEW, DOC_REQ:
docs/sprints/[sprint-id]/[sprint-id]-overview.mddocs/sprints/[sprint-id]/[task-id]/[task-id]-requirement.md
DOC_REQ is the single source of truth — it contains the story, FE design (if any), BE design (if any), Implementation Plan, and TDD Test Plan all in one file. It is injected into every sub-agent prompt — agents must NOT re-read this file.
Section extraction rule (size guard): Only relevant when delegating to a sub-agent. Per .claude/rules/parallel-work.md, one sub-agent owns the WHOLE task (both FE and BE) — never split by layer. Check character count of DOC_REQ:
- ≤ 6000 chars → inject full
DOC_REQto the sub-agent. - > 6000 chars → extract
## Acceptance Criteria+ relevant### [FE]and### [BE]blocks +# 3 · Frontend Designand/or# 4 · Backend Designsections +## E2E Test Plan. Inject all of them — the agent is owning the full vertical slice and needs both halves of the contract.
Validate:
- Missing requirement or empty ACs → stop: "Run
/requirement [task-id]first." - Implementation Plan empty AND Task Type ≠ infra → stop: "Fill Implementation Plan in
[task-id]-requirement.mdfirst." - Missing
Execution SlicesorPlan Drift GuardAND Task Type ≠ infra → stop: "Runplan-driven-deliveryfrom/requirementfirst and save the plan contract."
Read Task Type from Metadata. Assess parallelization flags:
HAS_FE: Task Type ∈ {fullstack, fe-only} AND### [FE] TDD Testshas rowsHAS_BE: Task Type ∈ {fullstack, be-only} AND### [BE] TDD Testshas rowsSHARED_TYPES:HAS_FEANDHAS_BEAND FE API Contracts Consumed references shared typesHAS_MIGRATION:DOC_REQ## Database Migrationssection is filled (notN/A)
Context7 — fetch current library docs (if available):
From the design sections in DOC_REQ, identify the key libraries the implementation will use (max 3 — e.g. test framework, UI component library, ORM/query builder).
For each library, follow .claude/rules/context7-cache.md:
- Cache check — read
docs/sprints/[sprint-id]/.context7-cache.json; on hit, reuse and skip both MCP calls below. mcp__plugin_context7_context7__resolve-library-id— resolve the library name to a context7 ID.mcp__plugin_context7_context7__query-docs— query for the specific patterns needed (test utilities, component API, query syntax, etc.).- Append
{libraryId, result, fetchedAt}to the cache file.
Pass the fetched docs as context to sub-agents in Step 2 and Step 3 so they write code against current APIs. If context7 is not available, proceed using design doc patterns and existing knowledge.
Step 1b — Pre-implementation readiness check
Iron Law: if any implementation code for this task already exists that was written before its tests — delete it now. Do not keep it as reference. Rewrite from tests. See rules/testing.md.
For each AC in requirement: is there at least one test row in ### [FE] TDD Tests or ### [BE] TDD Tests? Flag any AC with no test → stop, fix [task-id]-requirement.md first.
Step 1c — Confidence Gate
Assess confidence that you can implement this task successfully based on all context loaded so far.
Key dimensions:
- Design docs compl
Maintain Implement?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[Implement on getagentictools](https://getagentictools.com/loops/maximumsoft-co-ltd-claude-foundation-template-implement?ref=badge)