Generates single-purpose Claude Code sub-agents for use via the Task tool. Use when creating dedicated sub-agents, scaffolding agent definitions, or generating agents with diagnostics and permissions setup.
Instalaciรณn
Instalar con Codex o Claude Copia este prompt, pรฉgalo en Codex, Claude u otro asistente, y deja que revise la pรกgina de la skill y la instale por ti.
Generates single-purpose Claude Code sub-agents for use via the Task tool. Use when creating dedicated sub-agents, scaffolding agent definitions, or generating agents with diagnostics and permissions setup.
Generates a complete single-purpose Claude Code sub-agent from a description or requirements document. Conducts an adaptive interview to understand the agent's identity and mission, determines tool permissions and supporting configuration, spawns a Sonnet sub-agent to generate the agent file, validates with anthropic-validator, and presents the scaffold with architectural decisions.
Sub-agents are invoked via Task(subagent_type=...) and run in a forked context. They perform a single focused task and return results. They cannot spawn other sub-agents โ pipeline orchestration belongs in skills, not agents.
When to Use This Skill
Load this skill when the user request matches ANY of these patterns:
Trigger Pattern
Example User Request
Sub-agent creation
"Create a sub-agent for X", "Make an agent for X"
Agent scaffolding
"Scaffold an agent", "Set up a new agent"
Agent generation
"Generate an agent that does X"
Dedicated worker
"Create a dedicated agent for this sub-agent role"
Task tool agent
"I need an agent I can invoke via Task tool"
DO NOT use for:
Creating pipeline orchestration (use create-skill โ it generates the orchestrating skill + sub-agent files)
Creating Agent Teams leads (use create-skill with the research template)
<description-or-name> โ Free-text description of the desired agent, or an agent name to start from
--doc <path> โ Path to a requirements document. Extracts interview answers from it instead of asking fresh.
Examples:
/create-subagent a code security reviewer that checks for OWASP vulnerabilities โ Start from description
/create-subagent --doc plans/task-briefs/P4.4-implementer.md โ Start from requirements doc
/create-subagent market-analyst โ Start from a name
Mandatory Execution Checklist (BINDING)
Every item below is mandatory. No deviations. No substitutions. No skipping.
This skill uses a 6-stage pipeline. You are the orchestrator. Follow every item in order. Do NOT return to the user until all applicable items are checked.
Stage 0 โ Pre-Flight: Arguments parsed (description, name, or --doc)
Stage 0: Pre-Flight
โโโ Parse arguments (description, name, or --doc path)
โโโ Load references/decision-framework.md
โโโ Load references/agent-conventions.md
โโโ Load references/content-guidance.md
โโโ Load subagent-prompting skill
โโโ If --doc provided:
โ โโโ Read the requirements document
โ โโโ Extract answers to Q1-Q5 from the document
โ โโโ Present extracted answers to user for confirmation via AskUserQuestion
โโโ If no --doc:
โ โโโ AskUserQuestion: Present all 5 core questions from decision-framework.md
โ โโโ Q1: What is this agent's identity and mission? (2-3 invocation examples)
โ โโโ Q2: What tools does it need access to?
โ โโโ Q3: Single focused task, or multiple stages/operations?
โ โโโ Q4: Does it need structured diagnostic output?
โ โโโ Q5: Restricted permissions or full access?
โโโ If complexity detected in answers (Q3 = "multiple stages"):
โ โโโ AskUserQuestion: Follow-up questions per decision-framework.md
โ โโโ Q6: Do stages depend on each other's output?
โ โโโ Q7: Do workers need direct communication?
โ โโโ Q8-Q10: Additional context-specific follow-ups
โโโ ROUTING CHECK (after all interview answers received):
โ โโโ If Q3 = "multiple stages" AND (Q6 = "dependent" OR Q7 = "direct comms"):
โ โ โโโ STOP PIPELINE. Present redirect message to user:
โ โ "This use case requires a pipeline skill that orchestrates multiple sub-agents.
โ โ Sub-agents are single-purpose โ they can't spawn other sub-agents.
โ โ
โ โ Use /create-skill instead. It will generate:
โ โ - An orchestrating skill (SKILL.md) with pipeline stages
โ โ - Dedicated sub-agent files (.claude/agents/*.md) for each stage
โ โ
โ โ The generated sub-agents will have deterministic behavior locked into their
โ โ system prompts, and the orchestrating skill handles sequencing, error handling,
โ โ and synthesis."
โ โ Do NOT proceed to Stage 1. Return to user.
โ โโโ Otherwise: Continue to Stage 1
โโโ Determine agent name (from input or derived from description)
โ โโโ Target: .claude/agents/{agent-name}.md
โโโ Set working directory: tmp/create-subagent/{agent-name}/
โ โโโ All generation and refinement happens here to avoid .claude/ edit approval storms
โ Files are deployed to the target directory only after validation passes (Stage 5)
โโโ Token budget check (warn if >30% consumed)
Interview behavior: Maximum 2 AskUserQuestion rounds. Present Q1-Q5 together in round 1. Follow-ups (if needed) in round 2. Do NOT ask questions one at a time.
Stage 1: Classify (Orchestrator)
Apply the two-decision classification from references/decision-framework.md:
Stage 1: Classify
โโโ Decision A: Tool Permissions
โ โโโ Full access โ no tools: list in frontmatter (inherits all)
โ โโโ Restricted โ tools: [specific list] in frontmatter
โ โโโ If Write/Edit needed โ include quality gate guidance in protocol
โ โโโ If Bash needed โ include allowed/forbidden command lists in protocol
โโโ Decision B: Supporting Configuration
โ โโโ Always: Permissions Setup section
โ โโโ If diagnostics needed (Q4 = yes): diagnostic output section + schema
โ โโโ If diagnostics needed: subagent-output-templating in skills: dependency
โโโ Present classification to user via AskUserQuestion:
โโโ "Tool permissions: {full/restricted: [list]} โ {reason}"
โโโ "Configuration: {list} โ {reason}"
โโโ "Proceed with generation? [Yes / Adjust]"
MANDATORY: Wait for user confirmation before proceeding to Stage 2. If user selects "Adjust", re-classify with their feedback.
Stage 2: Generate (Sonnet sub-agent)
Stage 2: Generate
โโโ Read references/template-single-agent.md
โโโ Construct prompt using 4-part template (GOAL/CONSTRAINTS/CONTEXT/OUTPUT):
โ โโโ GOAL: Generate a complete, structurally correct single-purpose sub-agent
โ โ definition. The agent must use system-prompt register and include all
โ โ required sections (Pre-Flight, Mission, Protocol, Output, Permissions).
โ โโโ CONSTRAINTS:
โ โ โโโ Write in SYSTEM-PROMPT REGISTER โ WHO the agent IS, not WHAT to do
โ โ โโโ Open with identity statement: "You are a..."
โ โ โโโ Use present tense for behavioral descriptions
โ โ โโโ Description MUST be a single line (multi-line breaks discovery)
โ โ โโโ Description MUST use role-based trigger framing
โ โ โโโ Include Pre-Flight Gate with MUST/MUST NOT (binding language)
โ โ โโโ Include DO/DO NOT mission section
โ โ โโโ Include Tool Usage Constraints for every tool in frontmatter
โ โ โโโ Include Permissions Setup section (tool permissions unsolved per #10093)
โ โ โโโ Do NOT add unnecessary files (no README, CHANGELOG, LICENSE)
โ โ โโโ Do NOT use emojis in generated content
โ โ โโโ Keep agent under 250 lines
โ โโโ CONTEXT:
โ โ โโโ Classification from Stage 1 (both decisions)
โ โ โโโ User's interview answers (identity, mission, tools from Q1-Q5)
โ โ โโโ Template: references/template-single-agent.md
โ โ โโโ Agent conventions: references/agent-conventions.md
โ โ โโโ Content guidance: references/content-guidance.md
โ โ โโโ Instruction: "Read 1-2 existing agents from the codebase for structural
โ โ โ reference (use Glob to find .claude/agents/*.md)"
โ โ โโโ Target output path: .claude/agents/{agent-name}.md (final deployment location)
โ โ โโโ Working directory: tmp/create-subagent/{agent-name}/
โ โโโ OUTPUT:
โ โโโ Write agent file to {working-directory}/{agent-name}.md
โ โโโ Return summary: file path with line count
โโโ Spawn: Task(description="Generate agent file", subagent_type="general-purpose",
โ model="sonnet", prompt=...)
โโโ Read generator output (file path + summary)
โโโ Verify file was created (Read {working-directory}/{agent-name}.md)
Stage 3: Validate (Orchestrator)
Stage 3: Validate
โโโ FIRST: Invoke /anthropic-validator (this is the PRIMARY validation โ NOT optional)
โ โโโ Use the Skill tool: Skill(skill="anthropic-validator", args="{working-directory}/{agent-name}.md")
โ โโโ Do NOT substitute manual review for this step
โ โโโ Do NOT proceed past this node until the Skill tool has been invoked
โโโ Read validator output
โโโ Check for critical/high findings:
โ โโโ 0 critical AND 0 high โ proceed to Stage 5 (skip Stage 4)
โ โโโ Any critical or high โ proceed to Stage 4 (refine)
โโโ THEN: Manual checks (these supplement the validator, they do NOT replace it)
โ โโโ Check description is single-line (read agent file, verify no multiline description)
โ โโโ Check system-prompt register (body opens with identity, not task steps)
โ โโโ Check Permissions Setup section exists
โโโ Stage 3 exit gate:
โโโ [ ] /anthropic-validator was invoked via the Skill tool (not manual review)
โโโ [ ] Validator output was read and findings counted
โโโ If either is unchecked, Stage 3 is NOT complete โ go back and invoke the validator
Stage 4: Refine (Sonnet sub-agent, conditional, max 2 retries)
This stage only runs if Stage 3 found critical or high issues.
Stage 4: Refine (attempt {N} of 2)
โโโ Construct prompt using 4-part template:
โ โโโ GOAL: Fix all critical and high findings from anthropic-validator
โ โโโ CONSTRAINTS:
โ โ โโโ Only fix the specific issues identified โ do not restructure
โ โ โโโ Preserve the existing agent content and identity
โ โ โโโ Description must remain single-line
โ โ โโโ Must remain in system-prompt register
โ โโโ CONTEXT:
โ โ โโโ Validator findings (critical and high items with descriptions)
โ โ โโโ Current generated file (read from {working-directory}/{agent-name}.md)
โ โ โโโ Agent conventions: references/agent-conventions.md
โ โโโ OUTPUT: Edit file at {working-directory}/{agent-name}.md to fix findings
โโโ Spawn: Task(description="Fix validator findings", subagent_type="general-purpose",
โ model="sonnet", prompt=...)
โโโ Re-run Stage 3 (validate)
โโโ If still failing after 2 retries:
โ โโโ Proceed to Stage 5 with caveats noted
โโโ Token budget check
Stage 5: Deploy & Present (Orchestrator)
Stage 5: Deploy & Present
โโโ Deploy: Move {working-directory}/{agent-name}.md to .claude/agents/{agent-name}.md
โ โโโ This is the ONLY point where the file is written to .claude/
โ โโโ Clean up: Remove {working-directory}/ after successful copy
โโโ Read generated agent file from .claude/agents/{agent-name}.md for summary
โโโ Present to user:
โ โโโ "Generated agent at: .claude/agents/{agent-name}.md"
โ โโโ "Lines: {count}"
โ โโโ "Architectural decisions:"
โ โ โโโ "Tool permissions: {full/restricted: [list]} โ {reason}"
โ โ โโโ "Configuration: {list} โ {reason}"
โ โโโ "Validation: {pass/fail with details}"
โ โโโ If caveats: "Unresolved issues: {list}"
โ โโโ "Permissions to configure:"
โ โ โโโ {List tool permissions that must be added to settings.json}
โ โโโ "Next steps:"
โ โโโ "1. Review and customize the identity and expertise sections"
โ โโโ "2. Adjust tool permissions in .claude/settings.json"
โ โโโ "3. Test by invoking via Task tool: Task(subagent_type=\"{name}\", prompt=\"...\")"
โ โโโ "4. Add project-specific protocol steps as needed"
โ โโโ "5. Configure Stop hook if diagnostic output is needed"
โโโ Note: This is a scaffold, not production-ready output (generate-and-customize contract)
Stage 6: Diagnostics (REQUIRED)
MANDATORY: Write diagnostic output after every invocation. This cannot be skipped.
Stage 6: Diagnostics
โโโ Write to: $PROJECT_DIR/logs/diagnostics/create-subagent-{YYYYMMDD-HHMMSS}.yaml
โ โโโ Use templates/diagnostic-output.yaml schema
โโโ Include:
โโโ Input: description/name/doc path
โโโ Interview: questions asked, rounds completed
โโโ Routing: redirected (true/false), reason if redirected
โโโ Classification: both decisions
โโโ Generation: file created, line count, model used
โโโ Validation: pass/fail, findings count, retry count
โโโ Outcome: success/partial/failure/redirected
Error Handling
Scenario
Action
Generator sub-agent returns empty output
Re-spawn once with reinforced instructions. If still empty, STOP: "Generation failed. Please try with a more detailed description."
anthropic-validator finds critical issues
Stage 4 retry (max 2). After 2 retries, present with caveats.
anthropic-validator unavailable
Skip validation, note in diagnostics, warn user: "Validation skipped โ run /anthropic-validator manually."