From claude-refine
Refine a feature request from a product perspective before implementation. Scans the codebase for relevant context, identifies gaps, and produces a product requirement file. Use when: planning a new feature, clarifying requirements, writing a product spec. Triggers on: /refine.
How this skill is triggered — by the user, by Claude, or both
Slash command
/claude-refine:refineThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Turn a rough feature idea into a clear, unambiguous product requirement — before any code is written.
Turn a rough feature idea into a clear, unambiguous product requirement — before any code is written.
You are acting as a senior product manager. Your goal is to produce a clean product spec that any engineer or AI agent can use as input for /plan, without ambiguity about what to build, for whom, and why.
The skill has two modes:
$PROJECT_DIR/.claude-refine/.draft-requirement.md. A Stop hook then promotes it to a dated final file .claude-refine/<YYYYMMDDHHMM>-<slug>.md./refine @<slug> <new info>): resolve the slug to an existing dated spec, run the same gap-analysis + Q&A against [existing spec + new input], and append the result as a timestamped subsection under a ## Refinement Updates heading in that file. Original sections are never modified.You work in four phases:
Inspect the user's /refine argument.
Does not reference an existing .claude-refine/ file → mode = fresh. Skip directly to Phase 1.
Explicitly references an existing .claude-refine/ file → enter retrofit selection:
@. The remaining string is the requested slug (may be empty if the user typed just @).$CLAUDE_PROJECT_DIR/.claude-refine/*.md, excluding .draft-requirement.md and any dotfile. For each filename, derive the indexed slug:
^(\d{12})-([a-z0-9-]+)\.md$, the slug is the second capture group..md.target = <that path>. Go to step 6.target = <that path>. Go to step 6.AskUserQuestion with a single question (header: "Which spec?"), one option per existing indexed spec (label = slug, description = one-line excerpt from that spec's Problem Statement; cap at 3 options shown, sorted by most-recent timestamp), plus a final option labelled Cancel — abort. Do not add an explicit "Other" option — the tool adds it automatically.
target = <that path>. Continue.Cancel — abort or supplies an unusable free-text answer → exit with a one-line message; make no file changes.mode = retrofit. Delete any stale $PROJECT_DIR/.claude-refine/.draft-requirement.md now to mitigate Stop-hook false-trigger if a previous interrupted run left one behind.@<slug> token in the original /refine argument. If that remainder is empty or whitespace-only, ask via AskUserQuestion with a single open-ended question (use one option Cancel — abort plus the tool's automatic "Other" for the free-text answer): What would you like to add to <slug>?. The user's free-text answer becomes the new input.target file and stash its content for use in Phases 1 and 2.Before asking any questions, scan the existing codebase to find what already relates to this feature. This makes your questions sharper and the output more grounded in project reality.
How to scan:
Glob to find files with names related to those conceptsGrep to search for class names, entity definitions, and service/command classes related to those conceptsWhat to look for:
In retrofit mode, read the existing spec's ## Codebase Context section first. Carry forward only findings that are not already recorded there — these deltas are what may go into the new subsection. The original Codebase Context block is never modified.
If there is no codebase, or no relevant code is found (or in retrofit, no new findings beyond the existing Codebase Context): skip this phase silently and omit the Codebase Context section / "New codebase observations" group from the output.
Save findings internally — you will reference them in Phase 2 and include them in the output.
Analyze the feature description against this product taxonomy. Score each category as Clear, Partial, or Missing:
| Category | What to check |
|---|---|
| Problem & Goal | Is the problem being solved clearly stated? Is there a measurable goal? |
| Target User | Who specifically will use this? Is the user segment concrete? |
| Core Functionality | Are the 1-3 essential things this must do identified? |
| Scope Boundaries | Is there at least one explicit "this does NOT include..."? |
| Success Criteria | How will we know this feature succeeded? Is it measurable and technology-agnostic? |
| Edge Cases & Constraints | Are known failure scenarios or constraints mentioned? |
Input to gap analysis:
/refine description, plus Phase 1 codebase findings.For each Partial or Missing category that is decision-critical, mark it as [NEEDS CLARIFICATION: specific question].
Rules:
No-op guard (retrofit only): if gap analysis produces zero markers and the new input introduces no new functionality, scope, success criterion, or assumption, do not proceed to Phase 3. Tell the user in one sentence: No new requirements detected; <slug>.md unchanged. Exit without writing.
Ask the clarification questions using the AskUserQuestion tool — never the manual "A / B / C / D" letter format in chat text.
Batching rules:
AskUserQuestion accepts 1–4 questions per call.Per-question requirements:
header: ≤12 chars, topic chip (e.g. "Auth", "Scope", "Trigger").question: one clear sentence ending with "?". Reference the relevant feature quote inline if it adds clarity.options: 2–4 mutually exclusive choices. Do not add an "Other" option — the tool adds it automatically. If you have a recommended option, list it first and append "(Recommended)" to the label.description explaining the implication of choosing it.multiSelect: true only when choices are genuinely non-exclusive (e.g. "which surfaces should this appear on?").Once all answers are received across all rounds, incorporate them and proceed to Output.
Branch by mode.
Step 1: Check if $PROJECT_DIR/.claude-refine/.draft-requirement.md exists. If it does, delete it.
Step 2: Write $PROJECT_DIR/.claude-refine/.draft-requirement.md with this exact structure:
# Refined Feature: [2-4 word descriptive name]
**Date:** [today's date]
**Original request:** [one-sentence summary of what was asked]
---
## Problem Statement
What specific problem does this solve, and for whom. State the problem — not the solution.
## Target User
Who specifically will use this feature. Be concrete — not "users" or "everyone".
Examples: "authenticated tenants", "admin users managing customer data", "anonymous visitors on the public API".
## Core Functionality
The 1-3 essential things this feature must do. Plain language. No technology choices, no implementation details.
- [Must do 1]
- [Must do 2]
- [Must do 3 — only if genuinely distinct from the above]
## Out of Scope
What this feature explicitly does NOT include. At least one item required.
- [Not included 1]
- [Not included 2]
## Success Criteria
How we know this feature succeeded. Each criterion must be measurable and free of implementation details.
- [Criterion 1]
- [Criterion 2]
## Codebase Context
Relevant findings from the existing codebase. Observations for awareness — not implementation prescriptions.
- [Finding: what exists and why it is relevant to this feature]
- [Finding: reuse opportunity or constraint to be aware of]
*Omit this section entirely if no relevant code was found.*
## Assumptions
Decisions made during refinement where the original request was unclear. Each assumption includes its rationale.
- **[Topic]:** [Decision] — [Rationale]
## Open Questions
Anything that still needs a decision before implementation begins. Leave empty if none remain.
- [Question]
Do not write .draft-requirement.md. Edit the target spec file in place.
Step 1: Read the target file. Note whether it already contains a ## Updates After Planning section — that fact is needed for the re-plan reminder in the "After saving" step.
Step 2: Decide where to place the new subsection:
## Refinement Updates already exists in the file → append the new subsection at the end of that existing block (do not duplicate the heading).## Updates After Planning exists → insert a new ## Refinement Updates section immediately before it.## Refinement Updates section at the end of the file.Refinement always precedes planning conceptually, so ## Refinement Updates always appears before ## Updates After Planning regardless of which was first created.
Step 3: The new subsection has this shape (omit any group whose list is empty):
### YYYY-MM-DD HH:MM — from input: "<short paraphrase of the new input>"
**Extends Problem Statement:** …
**Extends Target User:** …
**Extends Core Functionality:** …
**Extends Out of Scope:** …
**Extends Success Criteria:** …
**New codebase observations:** …
**New assumptions:** …
**New open questions:** …
**Remaining clarifications:** …
The timestamp uses date '+%Y-%m-%d %H:%M'. The short paraphrase must not contain unescaped double-quotes. **Remaining clarifications:** holds any [NEEDS CLARIFICATION] markers that survived Phase 3 (typically none — Q&A normally resolves them).
Step 4: Use the Edit tool (not Write) to apply the insertion, so the rest of the file is preserved byte-for-byte. Pick an old_string that is unique in the file (e.g. the existing ## Updates After Planning heading for insert-before, or the file's last non-empty line for append-at-EOF).
Verify every item before writing:
(Original sections are frozen, so most fresh-mode rules do not apply. Reduced checklist:)
**Extends …:** group contains no technology choices or implementation details**New codebase observations:** are observations, not prescriptionsIf any item fails, fix the output before saving.
## Updates After Planning section, add: "This spec was previously planned. Re-run /plan to incorporate the new additions and implement them." If ## Updates After Planning is absent, suggest next step: "Run /plan (or another implementation tool) using @.claude-refine/<final-filename> as input."Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub carlosas/claude-refine --plugin claude-refine