---
name: prompt-generator
description: Generate or convert Claude Code prompt files — command orchestrators, agent role definitions, or style conversion of existing files. Follows GSD-style content separation with built-in quality gates. Triggers on "create command", "new command", "create agent", "new agent", "convert command", "convert agent", "prompt generator".
allowed-tools: Read, Write, Edit, Bash, Glob, AskUserQuestion
---
Generate or convert Claude Code prompt files with concrete, domain-specific content. Three modes:
- **Create command** — new orchestration workflow at `.claude/commands/` or `~/.claude/commands/`
- **Create agent** — new role + expertise file at `.claude/agents/`
- **Convert** — restyle existing command/agent to GSD conventions with zero content loss
Content separation principle (from GSD): commands own orchestration flow; agents own domain knowledge.
Invoked when user requests "create command", "new command", "create agent", "new agent", "convert command", "convert agent", or "prompt generator".
- @.claude/skills/prompt-generator/specs/command-design-spec.md
- @.claude/skills/prompt-generator/specs/agent-design-spec.md
- @.claude/skills/prompt-generator/specs/conversion-spec.md
- @.claude/skills/prompt-generator/templates/command-md.md
- @.claude/skills/prompt-generator/templates/agent-md.md
## 1. Determine Artifact Type
Parse `$ARGUMENTS` to determine what to generate.
| Signal | Type |
|--------|------|
| "command", "workflow", "orchestrator" in args | `command` |
| "agent", "role", "worker" in args | `agent` |
| "convert", "restyle", "refactor" + file path in args | `convert` |
| Ambiguous or missing | Ask user |
**Convert mode detection:** If args contain a file path (`.md` extension) + conversion keywords, enter convert mode. Extract `$SOURCE_PATH` from args.
If ambiguous:
```
AskUserQuestion(
header: "Artifact Type",
question: "What type of prompt file do you want to generate?",
options: [
{ label: "Command", description: "New orchestration workflow — process steps, user interaction, agent spawning" },
{ label: "Agent", description: "New role definition — identity, domain expertise, behavioral rules" },
{ label: "Convert", description: "Restyle existing command/agent to GSD conventions (zero content loss)" }
]
)
```
Store as `$ARTIFACT_TYPE` (`command` | `agent` | `convert`).
## 2. Validate Parameters
**If `$ARTIFACT_TYPE` is `convert`:** Skip to Step 2c.
Extract from `$ARGUMENTS` or ask interactively:
**Common parameters (create mode):**
| Parameter | Required | Validation | Example |
|-----------|----------|------------|---------|
| `$NAME` | Yes | `/^[a-z][a-z0-9-]*$/` | `deploy`, `gsd-planner` |
| `$DESCRIPTION` | Yes | min 10 chars | `"Deploy to production with rollback"` |
**Command-specific parameters:**
| Parameter | Required | Validation | Example |
|-----------|----------|------------|---------|
| `$LOCATION` | Yes | `"project"` or `"user"` | `project` |
| `$GROUP` | No | `/^[a-z][a-z0-9-]*$/` | `issue`, `workflow` |
| `$ARGUMENT_HINT` | No | any string | `" [--skip-verify]"` |
**Agent-specific parameters:**
| Parameter | Required | Validation | Example |
|-----------|----------|------------|---------|
| `$TOOLS` | No | comma-separated tool names | `Read, Write, Bash, Glob` |
| `$SPAWNED_BY` | No | which command spawns this agent | `/plan-phase orchestrator` |
Normalize: trim + lowercase for `$NAME`, `$LOCATION`, `$GROUP`.
## 3. Resolve Target Path
**Command:**
| Location | Base |
|----------|------|
| `project` | `.claude/commands` |
| `user` | `~/.claude/commands` |
```
If $GROUP:
$TARGET_PATH = {base}/{$GROUP}/{$NAME}.md
Else:
$TARGET_PATH = {base}/{$NAME}.md
```
**Agent:**
```
$TARGET_PATH = .claude/agents/{$NAME}.md
```
Check if `$TARGET_PATH` exists → `$FILE_EXISTS`.
## 4. Gather Requirements
**4a. Pattern discovery** — Find 3+ similar files in the project for style reference:
```bash
# For commands: scan existing commands
ls .claude/commands/**/*.md 2>/dev/null | head -5
# For agents: scan existing agents
ls .claude/agents/*.md 2>/dev/null | head -5
```
Read 1-2 similar files to extract patterns: section structure, naming conventions, XML tag usage, prompt style.
**4b. Domain inference** from `$NAME`, `$DESCRIPTION`, and context:
| Signal | Extract |
|--------|---------|
| `$NAME` | Action verb → step/section naming |
| `$DESCRIPTION` | Domain keywords → content structure |
| `$ARGUMENT_HINT` | Flags → parse_input logic (command only) |
| `$SPAWNED_BY` | Upstream contract → role boundary (agent only) |
**For commands — determine complexity:**
| Complexity | Criteria | Steps |
|------------|----------|-------|
| Simple | Single action, no flags | 3-5 numbered steps |
| Standard | 1-2 flags, clear workflow | 5-8 numbered steps |
| Complex | Multiple flags, agent spawning | 8-14 numbered steps |
**For agents — determine expertise scope:**
| Scope | Criteria | Sections |
|-------|----------|----------|
| Focused | Single responsibility | `` + 1-2 domain sections |
| Standard | Multi-aspect domain | `` + 2-4 domain sections |
| Expert | Deep domain with rules | `` + 4-6 domain sections |
If unclear, ask user with AskUserQuestion.
## 5. Generate Content
Route to the appropriate generation logic based on `$ARTIFACT_TYPE`.
### 5a. Command Generation
Follow `@specs/command-design-spec.md` and `@templates/command-md.md`.
Generate a complete command file with:
1. **``** — 2-3 sentences: what + when + what it produces
2. **``** — @ references to context files
3. **``** — numbered steps (GSD workflow style):
- Step 1: Initialize / parse arguments
- Steps 2-N: Domain-specific orchestration logic
- Each step: banner display, validation, agent spawning via `Task()`, error handling
- Final step: status display + `` with next actions
4. **``** — checkbox list of verifiable conditions
**Command writing rules:**
- Steps are **numbered** (`## 1.`, `## 2.`) — follow `plan-phase.md` and `new-project.md` style
- Use banners for phase transitions: `━━━ SKILL ► ACTION ━━━`
- Agent spawning uses `Task(prompt, subagent_type, description)` pattern
- Prompt to agents uses ``, ``, `