AgentSkillsCN

claude-code-subagent-builder

创建、编辑或审核 Claude Code 自定义代理(子代理),包括文件位置、YAML 前置信息、工具/权限设置、技能预加载以及提示词设计。适用于被要求定义新的 Claude Code 子代理、更新现有子代理,或审查子代理配置的正确性与最佳实践时使用。可通过“创建代理”、“新子代理”、“定义自定义代理”、“审核代理”等短语触发。

SKILL.md
--- frontmatter
name: claude-code-subagent-builder
description: Create, edit, or audit Claude Code custom agents (subagents), including file locations, YAML frontmatter, tool/permission settings, skills preloading, and prompt design. Use when asked to define a new Claude Code subagent, update an existing one, or review subagent configs for correctness and best practices. Triggers on "create agent", "new subagent", "define custom agent", "audit agent".
allowed-tools:
  - Read
  - Write
  - Edit
  - Glob

Claude Code Subagent Builder

Define and refine Claude Code subagents with correct placement, frontmatter, and prompting so delegation is safe, fast, and predictable.

Usage

code
"Create a subagent for code review"
"Define a new agent for log analysis"
"Audit my existing subagents"

Workflow

  1. Clarify the subagent's goal, inputs, outputs, and success criteria.
  2. Choose the scope and location for the subagent file.
  3. Draft YAML frontmatter and the system prompt body.
  4. Constrain tools and permissions; add skills or hooks only when needed.
  5. Test with real tasks and iterate.

Requirements Intake

Ask for:

QuestionPurpose
Primary tasks + 2-3 examplesDefine scope
Expected output formatSet quality bar
Scope (user/project/session)Choose location
Tool access needsSecurity
Permission modeSafety
Skills to preloadCapabilities
Hooks neededAutomation
Display colorUX

Choose Scope and Location

ScopeLocationUse Case
Session--agents CLI JSONTemporary, experiments
Project.claude/agents/Repo-specific, team use
User~/.claude/agents/Personal workflows

Reload after edits: restart or use /agents command.

Author the Subagent File

Frontmatter Fields

FieldRequiredDescription
nameYesUnique, short, action-oriented
descriptionYesRouting hint (WHEN to use)
toolsRecommendedAllowlist, [] for none, omit for all
disallowedToolsOptionalDenylist
modelOptionalOverride model
permissionModeOptionaldefault/acceptEdits/dontAsk/bypassPermissions/plan
skillsOptionalSkills to preload
hooksOptionalHooks to run
colorOptionalcyan/blue/green/magenta/yellow/red/white
disabledOptionalSet true to disable

Template

markdown
---
name: example-helper
description: Handle concise summaries of logs and errors for quick triage.
tools: ["Read", "Grep", "Glob"]
permissionMode: default
color: cyan
---

You are a focused helper that:
- Summarizes error patterns and likely root causes.
- Calls tools only when evidence is needed.
- Outputs a short summary followed by 3-5 bullet findings.

## Constraints
- Maximum 500 tokens output
- Never modify files

## Output Format
1. Summary (1-2 sentences)
2. Findings (3-5 bullets)
3. Recommended next steps

Prompting Guidance

DoDon't
Include all constraints explicitlyAssume inherited global instructions
Specify output formatLeave format ambiguous
State when to use/avoid toolsLet agent decide freely
Include acceptance criteriaSkip validation criteria

Tooling and Permissions

PatternWhen to Use
tools: []Analysis-only, no file access
tools: ["Read", "Glob"]Read-only inspection
disallowedTools: ["Bash"]Remove risky tools
permissionMode: defaultStandard safety (recommended)
permissionMode: dontAskNon-tooling analysis only
permissionMode: planMandatory plan before tools

Avoid: bypassPermissions unless hooks require it in trusted environment.

Test and Iterate

Test Checklist

CheckPass Criteria
Format consistencyOutput matches specified format
Tool usageUses only necessary tools
Constraint adherenceRespects all stated limits
Error handlingGraceful failure on edge cases

Example Test Tasks

code
# For a code-review agent:
"Review the changes in src/components/Button.tsx"

# For a log-analysis agent:
"Summarize errors from the last 24 hours in app.log"

# For a documentation agent:
"Generate API docs for the UserService class"

Error Handling

IssueSolution
Agent file not foundCheck path, suggest correct location
Invalid YAMLReport parse error with line number
Missing required fieldList missing fields, provide template
Permission deniedCheck file permissions, suggest chmod
Agent not loadingVerify frontmatter syntax, restart Claude

References