brainstorm · diff

git:20260707.9f79bc7 to git:20260717.01e4a14

78 added, 168 removed. Audit B to B.

---
description: >-
- Guides structured design brainstorming — explores the codebase, asks clarifying
- questions, proposes multiple approaches with trade-offs, and writes an approved
- spec to docs/specs/ for /optimus:tdd and /optimus:workflow to auto-detect.
- Use before implementation to think through design
- decisions and avoid premature coding. Produces a persistent artifact that feeds
- into plan mode and TDD. For stakeholder-facing or acceptance-criteria-driven
- work, the spec includes a Given/When/Then Scenarios section consumed by
- /optimus:tdd.
+ Runs a structured design conversation — clarifies intent, proposes 2-3 approaches
+ with trade-offs, iterates the design — and writes a user-approved engineering spec
+ to docs/specs/ that /optimus:tdd auto-detects. No implementation happens until the
+ spec is approved. With the scaffold argument, creates docs/product/ steering
+ skeletons instead (never overwrites, authors no content). Run /optimus:init first.
disable-model-invocation: true
- argument-hint: "[topic or JIRA key]"
+ argument-hint: "[topic, JIRA key, or scaffold]"
---
# Brainstorm
- Guide the user through a structured design conversation that produces a written, approved spec before any implementation begins. The output is a persistent file in the project that feeds into Claude Code plan mode and then into `/optimus:tdd` for test-first implementation.
-
- ### The Hard Gate
-
- **No implementation until the design is approved.** Do not invoke any implementation skill, write any production code, scaffold any project structure, or take any implementation action until you have written a spec and the user has approved it. This applies to all tasks — even seemingly simple ones. Unexamined assumptions in "simple" projects cause the most wasted effort.
-
- ## Step 1: Pre-flight
+ Guide the user through a design conversation that produces a written, approved spec before any implementation begins.
- Read `$CLAUDE_PLUGIN_ROOT/skills/init/references/multi-repo-detection.md` for workspace detection. If a multi-repo workspace is detected, process within the repo the user is targeting. If ambiguous, ask which repo.
+ **The hard gate: no implementation until the design is approved.** Do not invoke an implementation skill, write production code, or scaffold project structure until a spec is written and the user has approved it — even for seemingly simple tasks.
- ### Verify prerequisites
+ ## Scaffold mode
- Check that `.claude/CLAUDE.md` exists. If it doesn't, stop and recommend running `/optimus:init` first — project context and coding guidelines shape design decisions.
+ When invoked with the `scaffold` argument, or when the user asks to set up the docs-first steering cascade, run this flow instead of the design conversation:
- Load these documents:
+ 1. Target the current repo root. If the current directory has no `.git/` directory, read `$CLAUDE_PLUGIN_ROOT/skills/init/references/multi-repo-detection.md` and apply it — when a workspace is detected, ask which repo the product lives in and scaffold there (a cascade outside the target repo never auto-loads as steering).
+ 2. For each of `docs/product/product-context.md`, `mvp-prd.md`, and `tech-stack.md`: if it exists, never overwrite — skip it. If missing, copy the matching file from `$CLAUDE_PLUGIN_ROOT/skills/brainstorm/templates/product/` verbatim, creating `docs/product/` if needed. Write nothing else — no `docs/specs/` file (the design flow authors that later), nothing under `.claude/`.
+ 3. **Emit skeletons with TODO markers only — author no product content (no personas, KPIs, business-value prose, or technology choices) and never fill a TODO; that is the human's job.**
+ 4. Report created vs skipped files. Tell the user to fill the TODOs top-down (vision → MVP PRD → target stack), then run `/optimus:brainstorm` in a fresh conversation to design the first build.
- | Document | Role |
- |----------|------|
- | `.claude/CLAUDE.md` | Project overview, tech stack, architecture |
- | `coding-guidelines.md` | Quality standards that constrain the design |
- | `docs/product/product-context.md` *(if present)* | Product vision — steering context |
- | `docs/product/mvp-prd.md` *(if present)* | MVP scope — steering context |
- | `docs/product/tech-stack.md` *(if present)* | Target tech stack — steering context |
+ ## Step 1: Pre-flight
- The three `docs/` rows are the optional spec-driven-development steering cascade (scaffolded by `/optimus:spec-init`). Load them **only if they exist**, and treat them as higher-altitude direction that *informs* the design — never as the task itself or as content to copy. The spec you write stays engineering-focused: do **not** author product/PM prose (personas, KPIs, business-value) into it. See `$CLAUDE_PLUGIN_ROOT/references/sdd-mapping.md` for the precedence contract.
+ If `.claude/CLAUDE.md` or `.claude/docs/coding-guidelines.md` is missing, recommend `/optimus:init` first; on the user's choice, continue with general best practices.
- **Monorepo path note:** Read the "Monorepo Scoping Rule" section of `$CLAUDE_PLUGIN_ROOT/skills/init/references/constraint-doc-loading.md` for doc layout and scoping rules.
+ Load `.claude/CLAUDE.md` and `.claude/docs/coding-guidelines.md`, plus — only if present — the steering cascade `docs/product/product-context.md`, `mvp-prd.md`, and `tech-stack.md`. Steering is higher-altitude direction that informs the design, never the task itself or content to copy; the spec stays engineering-focused, with no PM prose (personas, KPIs, business value). Precedence contract: `$CLAUDE_PLUGIN_ROOT/references/sdd-mapping.md`. In a monorepo, load the subproject's own `docs/` files (testing, architecture, styling) and shared guidelines from the root `.claude/docs/`.
- ### Scan project structure
+ If the current directory has no `.git/` directory, read `$CLAUDE_PLUGIN_ROOT/skills/init/references/multi-repo-detection.md` and apply it — operate within the repo the user is targeting; ask which repo if ambiguous.
- Explore the project's directory structure, key modules, and existing patterns. This grounds the design conversation in what actually exists — not assumptions.
+ Scan the project's directory structure, key modules, and existing patterns to ground the conversation in what actually exists.
## Step 2: Gather Intent
- ### JIRA context detection
-
- Before asking the user for input, check for pre-existing JIRA context:
-
- 1. If the user's inline input matches a JIRA key pattern (`[A-Z][A-Z0-9]+-\d+`), check for `docs/jira/<key>.md`. If found, read it and use its Goal and Acceptance Criteria as the brainstorm input. If the file is not found, inform the user ("No task file found for [KEY] — run `/optimus:jira [KEY]` first to fetch it") and proceed with normal intent gathering below.
-
- 2. If no inline input (or no JIRA key match), check whether `docs/jira/` exists and contains `.md` files. If so, read each file's YAML frontmatter and select the one with the most recent `date` field. Extract the `issue` field and the Goal section. Present to the user via `AskUserQuestion` — header "JIRA context", question "Found JIRA context: [ISSUE-KEY] — [Goal]. Use this as the basis for design?":
- - **Use it** — "Design around this JIRA task"
- - **Ignore** — "Describe a different task"
-
- If the file's `date` frontmatter field is older than 7 days, add a note: "(This context is [N] days old — you may want to re-run `/optimus:jira` for fresh data.)"
-
- If **Use it**: use the file's Goal and Acceptance Criteria as the brainstorm input. Proceed to clarifying questions (skip the intent-gathering prompts below).
- If **Ignore**: proceed with normal intent gathering below.
-
- 3. If no `docs/jira/` directory or no files in it, proceed with normal intent gathering below.
-
- ### Gather from user
-
- If the user provided a description inline (e.g., `/optimus:brainstorm "add authentication system"`), use it. Otherwise, use `AskUserQuestion` — header "Design scope", question "What do you want to build or change?":
- - **New feature** — "Build something new (e.g., 'Add user authentication')"
- - **Significant change** — "Rework or extend an existing part of the system"
-
- If the description is longer than ~3 sentences (e.g., a pasted spec, ticket, or acceptance criteria), distill it into a **single-sentence goal** and confirm with `AskUserQuestion` — header "Distilled goal", question "I've distilled your input to: '[single-sentence summary]'. Is this accurate?":
- - **Looks good** — "Proceed with this goal"
- - **Adjust** — "Let me refine the focus"
-
- ### Clarifying questions
+ Check for JIRA context before prompting the user:
- Before asking questions, identify your key assumptions about scope, constraints, and expected behavior. Surface them in your reply text before the first `AskUserQuestion` call so the user can correct or confirm them.
+ 1. Inline input matching `[A-Z][A-Z0-9]+-\d+` → read `docs/jira/<key>.md` and use its Goal and Acceptance Criteria as the brainstorm input. If the file is missing, tell the user to run `/optimus:jira <KEY>` first, then gather intent normally.
+ 2. No inline input and `docs/jira/` contains `.md` files → pick the one with the newest frontmatter `date` and offer it via AskUserQuestion (Use it / Ignore), noting when the date is over 7 days old that re-running `/optimus:jira` refreshes it. **Use it** consumes the file's Goal and Acceptance Criteria and skips the prompts below.
- Ask up to **3 clarifying questions** to fill critical gaps — one per `AskUserQuestion` call, prefer multiple-choice options. Focus on:
- - Constraints the user hasn't mentioned (performance, compatibility, security)
- - Scope boundaries (what's in, what's explicitly out)
- - Integration points with existing code
+ Otherwise use the inline description; if none, ask what to build or change. Distill input longer than ~3 sentences into a single-sentence goal and confirm it with the user.
- Skip questions if the intent is already clear. Three is the maximum, not the target.
+ Surface your key assumptions about scope, constraints, and expected behavior in reply text before the first clarifying question. Then ask at most 3 clarifying questions — a maximum, not a target; one per AskUserQuestion call, preferring multiple-choice — and skip them entirely when intent is already clear.
## Step 3: Explore and Propose
- ### Explore relevant code
-
- Based on the user's goal, explore the codebase areas that the design will touch:
- - Existing modules, patterns, and conventions relevant to the goal
- - Dependencies and integration points
- - Related tests (if any) that reveal expected behavior
-
- ### Propose approaches
-
- Present **2-3 approaches** to the user:
-
- ```
- ## Approaches
+ Explore the code the design will touch: relevant modules and conventions, dependencies and integration points, related tests. Then present 2-3 approaches (a third only if genuinely distinct), each with a name, a 2-3 sentence description, pros/cons, effort (Low / Medium / High), and alignment with existing patterns — plus a recommendation with a one-sentence rationale.
- ### A: [Name]
- [Brief description — 2-3 sentences]
- - **Pros:** [key advantages]
- - **Cons:** [key disadvantages]
- - **Effort:** [Low / Medium / High]
- - **Alignment:** [how well it fits existing patterns]
+ The user selects via AskUserQuestion, one option per approach with the recommendation marked. If they want to combine aspects or redirect, incorporate the feedback and present a revised approach before proceeding.
- ### B: [Name]
- ...
+ ## Step 4: Design
- ### C: [Name] (optional — only if genuinely distinct)
- ...
+ Develop a detailed design covering the spec template sections in Step 5, omitting those that don't apply. Before writing a Scenarios section, read `$CLAUDE_PLUGIN_ROOT/skills/brainstorm/references/scenario-style.md` for inclusion signals and Given/When/Then discipline — `/optimus:tdd` consumes each scenario as one Red-Green-Refactor cycle.
- **Recommendation:** [Approach letter] — [one-sentence rationale]
- ```
+ Present the design in conversation and iterate through an Approve / Adjust AskUserQuestion until the user approves.
- Use `AskUserQuestion` — header "Approach", question "Which approach should I design in detail?":
- - One option per approach, with the recommendation marked
+ ## Step 5: Write the Spec
- If the user wants to combine aspects of multiple approaches or suggests a different direction, incorporate their feedback and present a revised approach before proceeding.
+ Write to `docs/specs/YYYY-MM-DD-<topic-slug>.md` (lowercase hyphenated slug from the goal, max 5 words; create `docs/specs/` if needed). If the file already exists, ask the user whether to overwrite or append a `-2`, `-3`, … suffix; on overwrite, carry any existing `### Refined plan` section into the new file — it holds plan-mode iteration. Set Status to `Approved`. Keep the spec under 200 lines.
- ## Step 4: Design
+ ```markdown
+ # Spec: <Title>
- Based on the chosen approach, develop a detailed design. Cover each section as applicable — omit sections that don't apply to the task:
+ **Date:** YYYY-MM-DD
+ **Status:** Approved
+ **Goal:** <single sentence — what and why>
- - **Goal** — single sentence: what and why
- - **Context** — why the change is needed and the relevant existing state (what exists today, what's missing, what's broken)
- - **Approach** — how it works, key decisions and their rationale
- - **Components** — what gets created or modified, each component's responsibility
- - **Interfaces** — how components interact (APIs, data flow, contracts, function signatures)
- - **Edge cases and risks** — what could go wrong, mitigations
- - **Scenarios** — *conditional.* 3–7 Given/When/Then scenarios that `/optimus:tdd` consumes as the behavior list. See `$CLAUDE_PLUGIN_ROOT/skills/brainstorm/references/scenario-style.md` for inclusion signals and phrasing — read it before writing scenarios.
- - **Out of scope** — explicit boundaries to prevent scope creep
- - **Open questions** — decisions deferred or needing more information (omit if none)
+ ## Context
+ <Why the change is needed; relevant existing state.>
- Present the design in conversation. Use `AskUserQuestion` — header "Design review", question "Does this design look right?":
- - **Approve** — "Write it to a spec"
- - **Adjust** — "I have feedback before writing"
+ ## Approach
+ <How it works; key decisions and their rationale.>
- If the user has feedback, refine the design and present it again. Iterate until approved.
+ ## Components
+ | Component | Responsibility | New / Modified |
+ |-----------|----------------|----------------|
- ## Step 5: Write the Spec
+ ## Interfaces
+ <How components interact — APIs, data flow, signatures. Skip for single-file changes.>
- Read `$CLAUDE_PLUGIN_ROOT/skills/brainstorm/references/spec-format.md` for the template.
+ ## Edge Cases and Risks
+ | Risk | Mitigation |
+ |------|------------|
- ### Write the file
+ ## Scenarios
+ <Conditional — 3-7 Given/When/Then scenarios per scenario-style.md; remove the section if none apply.>
- - **Path:** `docs/specs/YYYY-MM-DD-<topic-slug>.md` — derive the slug from the goal (lowercase, replace non-alphanumeric characters with hyphens, collapse consecutive hyphens, strip leading/trailing hyphens, max 5 words). The slug must match `[a-z0-9]+(-[a-z0-9]+)*` — reject any slug that does not match this pattern
- - Create the `docs/specs/` directory if it doesn't exist
- - If the target file already exists (e.g., a same-day re-brainstorm of the same topic), ask the user via `AskUserQuestion` whether to overwrite it or write to a suffixed filename (append `-2`, `-3`, … to the slug); on overwrite, carry any existing `### Refined plan` section into the new file — it captures plan-mode iteration the append-not-overwrite rule exists to preserve
- - Fill the template with the approved design content
- - Set **Status** to `Approved`
+ ### Scenario: <concrete user-observable outcome>
+ **Given** <starting state in business language>
+ **When** <single user action>
+ **Then** <observable outcome>
- ### Self-review
+ ## Out of Scope
+ - <What this design explicitly does not cover>
- After writing, read the file back and check for:
- - TODOs, placeholders, or "TBD" markers
- - Internal contradictions (e.g., a component listed in Components but missing from Interfaces)
- - Requirements ambiguous enough to cause someone to build the wrong thing
- - YAGNI violations — features or complexity the user didn't ask for
- - If a Scenarios section was included: re-check it against `$CLAUDE_PLUGIN_ROOT/skills/brainstorm/references/scenario-style.md` (Discipline and Anti-patterns)
+ ## Open Questions
+ - <Deferred decisions — remove if none>
+ ```
- Fix any issues found. If a fix would change a design decision, ask the user first.
+ Self-review the written file for: TODOs or placeholders; internal contradictions; ambiguity that could lead to building the wrong thing; YAGNI violations; scenario discipline (against scenario-style.md's Discipline and Anti-patterns) when Scenarios are present. Fix what you find, but ask the user before any fix that changes a design decision.
## Step 6: Report
- Present the result:
-
```
## Design Complete
**Spec:** `<spec-path>`
**Goal:** <single-sentence goal>
**Approach:** <chosen approach name>
**Components:** <count> (<count> new, <count> modified)
```
## Step 7: Next Step
- Handle non-implementation tasks first. Neither skill below reads `docs/specs/` on its own — include the spec path in the handoff so the approved design isn't dropped:
- - **Refactoring task** → tell the user: "Recommend running `/optimus:refactor` to restructure the code, passing the scope and key decisions from `<spec-path>` as the scope argument. **Tip:** for best results, start a fresh conversation for the next skill — each skill gathers its own context from scratch."
- - **Test-only task** → tell the user: "Recommend running `/optimus:unit-test` to write tests for existing code, passing the target paths from `<spec-path>` as the path argument. **Tip:** for best results, start a fresh conversation for the next skill — each skill gathers its own context from scratch."
-
- For implementation tasks, assess complexity from the Components table in the spec. If the Components table lists zero code components or the Goal names a written artifact (research note, audit report, investigation write-up), the deliverable is **prose** — read the "Prose deliverable" note at the end of this step first, then use the Medium-to-large branch below with its adjustments (they replace the prompt closer, the user steps, and the execution prompt).
-
- ### Small (1–2 components, <5 behaviors implied)
-
- Tell the user: "This is small enough to implement directly — run **`/optimus:tdd`** to build it test-first (Red-Green-Refactor, interactive checkpoints). It auto-detects the spec at `<spec-path>`. (You can use **`/optimus:workflow`** instead for a self-orchestrated parallel build — test-first as a quality bar, no mid-run input, more tokens — but for a spec this small TDD is usually the better fit; `/optimus:workflow` shines on large or parallelizable specs.) **Tip:** for best results, start a fresh conversation for the next skill — each skill gathers its own context from scratch."
+ Route by task type. Substitute the actual spec path into every recommendation and emitted block — `/optimus:refactor` and `/optimus:unit-test` do not read `docs/specs/` on their own. Recommend running the routed skill in a fresh conversation.
- ### Medium-to-large (3+ components, complex interfaces, or anything not matching Small)
+ | Task | Route |
+ |------|-------|
+ | Refactoring | `/optimus:refactor`, passing the scope and key decisions from `<spec-path>` as the scope argument |
+ | Test-only | `/optimus:unit-test`, passing the target paths from `<spec-path>` |
+ | Small implementation (1-2 components, <5 behaviors) | `/optimus:tdd` directly — it auto-detects the spec at `<spec-path>` |
+ | Medium-to-large implementation | Plan-mode handoff below |
+ | Prose deliverable (zero code components, or the goal names a written artifact) | Prose flow below |
- **Alternative — a parallel build (code deliverables only):** if the user prefers a self-orchestrated parallel build over supervised TDD, they can run **`/optimus:workflow`** instead. It auto-detects the spec at `<spec-path>`, launches a Claude Code dynamic workflow directly (no plan-mode iteration, no "Refined plan" step), applies test-first as a quality bar, and uses meaningfully more tokens. **If the user takes this alternative, skip the plan-mode prompt and execution-prompt blocks below** — point them to `/optimus:workflow` (in a fresh conversation) and stop here. Otherwise the plan-mode → `/optimus:tdd` flow below remains the default for supervised, test-first work. For a **prose deliverable**, skip this alternative — `/optimus:workflow` is overkill for documentation-only work (see the "Prose deliverable" note below).
+ ### Plan-mode handoff (medium-to-large)
- Generate a plan-mode prompt inline, pre-filled from the spec. Present it as a single copyable block:
+ Read `$CLAUDE_PLUGIN_ROOT/skills/brainstorm/references/plan-mode-handoff.md`. Emit a copyable plan-mode prompt pre-filled from the spec:
````
```
## Goal
[Goal from the spec]
## Context
- [Synthesize from the spec's Context and Approach sections.
- Include key decisions, constraints, and the chosen approach rationale.]
+ [Synthesized from the spec's Context and Approach — key decisions, constraints, chosen-approach rationale.]
## Starting Hints
- Spec: <spec-path>
- - [Key files/modules identified during codebase exploration in Step 3]
-
- ## What to Figure Out
- 1. Which existing files and modules need to be modified or extended?
- 2. What's the right implementation sequence given the component dependencies?
- 3. Are there existing patterns in the codebase to follow or reuse?
- 4. What are the risks or edge cases not covered in the design?
-
- ## Plan Deliverable
- The plan should include:
- - Proposed approach with rationale
- - Files to create or modify, with what changes
- - Implementation sequence and dependencies
- - Test strategy mapped to each component
+ - [Key files/modules from Step 3 exploration]
## Scope
- Focus on: [components from the spec]
- Out of scope: [from the spec's Out of Scope section]
- [Close the prompt with the "## How this conversation should run" section from `$CLAUDE_PLUGIN_ROOT/references/skill-handoff.md` "Carve-out canonical blocks", substituting `<doc-path>` = `<spec-path>`.]
+ [Close with the canonical block from plan-mode-handoff.md "Carve-out canonical blocks", substituting <doc-path> = <spec-path>.]
```
````
- Substitute `<spec-path>` with the actual path from Step 5 wherever it appears in Steps 6–7 — the report, the branch texts, and every emitted prompt block — so each pasted block is self-contained.
-
- Tell the user the three numbered plan-mode steps from `$CLAUDE_PLUGIN_ROOT/references/skill-handoff.md` "Carve-out canonical blocks" verbatim, substituting `<doc-path>` = `<spec-path>`.
-
- Then emit the **execution prompt** as a second copyable block, pre-filled from the spec:
+ Then tell the user the three carve-out steps from plan-mode-handoff.md (substituting `<doc-path>` = `<spec-path>`), and emit the execution prompt as a second copyable block:
````
```
## Goal
- Run `/optimus:tdd` to implement the refined plan in `<spec-path>` test-first.
+ Run /optimus:tdd to implement the refined plan in <spec-path> test-first.
## Starting Hints
- Spec (with "Refined plan" section): <spec-path>
- - Components from the spec: [list component names from the Components table]
+ - Components: [names from the spec's Components table]
## Scope
- Focus on: [components from the spec]
- Out of scope: [from the spec's Out of Scope section]
```
````
- **Prose deliverable:** if the design produces a written artifact rather than code, `/optimus:tdd` does **not** apply — follow the default plan-mode flow (approve the plan to implement in the same conversation; see `$CLAUDE_PLUGIN_ROOT/references/skill-handoff.md` "Plan mode") instead of the review-only carve-out. Adjust the Medium-to-large branch as follows:
-
- - Close the plan-mode prompt with a `## How this conversation should run` section that says: iterate on the plan against the actual codebase; once the user approves the plan, implement it in this conversation to produce `<deliverable-path>`; after writing the deliverable, recommend `/optimus:commit` to commit it, followed by the closing tip. Substitute the tip text into the prompt — **Variant A** from skill-handoff.md "Closing tip wording" with `<continuation-skill(s)>` = `/optimus:commit` and `<non-continuation-examples>` = `/optimus:code-review`, `/optimus:unit-test` — so the executing conversation can emit it verbatim after the deliverable exists.
- - Instead of the three carve-out steps, tell the user: start a fresh conversation in **plan mode**, paste the prompt, iterate, and **approve the plan** when satisfied — approval implements it in the same conversation (no `### Refined plan` append, no second conversation).
- - Skip the execution prompt above entirely.
+ ### Prose flow
- See `$CLAUDE_PLUGIN_ROOT/references/skill-handoff.md` for the full handoff convention and why plan mode is review-only on the `/optimus:tdd` path.
+ `/optimus:tdd` does not apply — use the default flow from plan-mode-handoff.md. Emit the same plan-mode prompt, but close it with a `## How this conversation should run` section saying: iterate on the plan against the actual codebase; once the user approves the plan, implement it in that same conversation to produce the deliverable; afterwards recommend `/optimus:commit` in that same conversation so the implementation context is captured. Tell the user: start a fresh conversation in plan mode, paste the prompt, iterate, and approve the plan when satisfied. Skip the execution prompt.