Claude Code 智能体开发权威指南
简介
Claude Code 官方生态的 Agent 开发指南,提供从描述设计到内存优化的完整最佳实践,帮助开发者构建高效、可自动委托的自定义智能体。
原始描述
Design and build custom Claude Code agents with effective descriptions, tool access patterns, and self-documenting prompts. Covers Task tool delegation, model selection, memory limits, and declarative instruction design. Use when: creating custom agents, designing agent descriptions for auto-delegation, troubleshooting agent memory issues, or building agent pipelines.
通过你的 Agent 添加
安装目录:agent-development/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
agent-development 是一个纯文档型技能,专注于指导用户设计和构建 Claude Code 自定义 Agent。其核心用法包括:
-
Agent 描述设计:使用 "MUST BE USED when..." 和 "Use PROACTIVELY for..." 等强触发模式,确保 Claude 能自动识别并委托任务给子 Agent。
-
工具权限最小化:遵循"不需要 Bash 就不给 Bash"原则,根据 Agent 职责精确分配工具集(如只读审计型 Agent 仅授予 Read/Glob/Grep),避免权限滥用和频繁的命令行审批干扰。
-
模型选择策略:Opus 用于创意工作(页面构建、设计),Sonnet 作为大多数 Agent 的默认选择,Haiku 仅用于质量不重要的脚本执行。
-
内存管理配置:通过设置
NODE_OPTIONS="--max-old-space-size=16384"将 Node.js 堆内存从 4GB 提升至 16GB,解决大规模并行 Agent 的内存崩溃问题。 -
声明式提示设计:描述"做什么"而非"怎么做",避免在提示中硬编码具体工具调用命令,让模型自主决定最佳执行路径。
-
流水线 Agent 编排:设计可并行执行的 Agent 工作流,每个 Agent 处理独立任务项,通过结构化报告返回结果,由人工审查后批量提交。
显著优点
- 权威性极强:源自 Claude Code 官方生态系统,作者 Jeremy Dawes 为资深开发者,内容经过实战验证
- 系统性完整:覆盖 Agent 开发全生命周期,从描述设计、工具权限、模型选择到内存优化、流水线编排
- 实操性突出:提供大量可直接复制的 YAML 模板、配置代码和检查清单,降低落地门槛
- 安全导向明确:强调最小权限原则,提供 Allowlist 配置模式,帮助用户在便利与安全间取得平衡
- 反模式警示:详细列举常见陷阱(如"As we discussed earlier..."等上下文依赖表述),加速开发者成长
潜在缺点与局限性
- 无自动化执行:纯文档型技能,所有配置需手动完成,无法一键部署 Agent 模板
- Claude Code 专属:最佳实践深度绑定 Claude Code 的 Task 工具机制,迁移到其他 Agent 框架需大幅调整
- 并行规模受限:即使优化内存,仍建议 Heavy Creative Agent 并行数控制在 1-2 个,大规模批处理场景存在瓶颈
- 版本依赖风险:部分配置(如
.claude/settings.json 格式)可能随 Claude Code 版本迭代而变化
适合的目标群体
- Claude Code 重度用户:希望从"单轮对话"进阶到"多 Agent 协作"的高级用户
- 平台/工具开发者:需要为团队构建标准化 Agent 工作流的工程负责人
- AI 应用架构师:设计复杂 Agent 管道(如代码审查、文档生成、批量数据处理)的系统设计者
- 效率极客:追求"重复性任务自动化+关键节点人工审查"工作模式的开发者
使用风险
- 配置误操作风险:文档中的环境变量和权限配置示例若被盲目复制,可能导致系统环境变更或过度授权
- 内存优化副作用:16GB 堆内存设置对低配置机器可能造成系统资源紧张
- Agent 描述过度优化:强触发词设计不当可能导致 Claude 过度委托,增加 token 消耗和响应延迟
- 流水线调试复杂度:并行 Agent 失败时,问题定位需人工介入检查多个独立执行上下文
- 无自动化执行:纯文档型技能,所有配置需手动完成,无法一键部署 Agent 模板
- Claude Code 专属:最佳实践深度绑定 Claude Code 的 Task 工具机制,迁移到其他 Agent 框架需大幅调整
- 并行规模受限:即使优化内存,仍建议 Heavy Creative Agent 并行数控制在 1-2 个,大规模批处理场景存在瓶颈
- 版本依赖风险:部分配置(如
.claude/settings.json格式)可能随 Claude Code 版本迭代而变化
适合的目标群体
- Claude Code 重度用户:希望从"单轮对话"进阶到"多 Agent 协作"的高级用户
- 平台/工具开发者:需要为团队构建标准化 Agent 工作流的工程负责人
- AI 应用架构师:设计复杂 Agent 管道(如代码审查、文档生成、批量数据处理)的系统设计者
- 效率极客:追求"重复性任务自动化+关键节点人工审查"工作模式的开发者
使用风险
- 配置误操作风险:文档中的环境变量和权限配置示例若被盲目复制,可能导致系统环境变更或过度授权
- 内存优化副作用:16GB 堆内存设置对低配置机器可能造成系统资源紧张
- Agent 描述过度优化:强触发词设计不当可能导致 Claude 过度委托,增加 token 消耗和响应延迟
- 流水线调试复杂度:并行 Agent 失败时,问题定位需人工介入检查多个独立执行上下文
- 配置误操作风险:文档中的环境变量和权限配置示例若被盲目复制,可能导致系统环境变更或过度授权
- 内存优化副作用:16GB 堆内存设置对低配置机器可能造成系统资源紧张
- Agent 描述过度优化:强触发词设计不当可能导致 Claude 过度委托,增加 token 消耗和响应延迟
- 流水线调试复杂度:并行 Agent 失败时,问题定位需人工介入检查多个独立执行上下文
技能正文
name: agent-development description: | Design and build custom Claude Code agents with effective descriptions, tool access patterns, and self-documenting prompts. Covers Task tool delegation, model selection, memory limits, and declarative instruction design.
Use when: creating custom agents, designing agent descriptions for auto-delegation,
troubleshooting agent memory issues, or building agent pipelines.
license: MIT
Agent Development for Claude Code
Build effective custom agents for Claude Code with proper delegation, tool access, and prompt design.
Agent Description Pattern
The description field determines whether Claude will automatically delegate tasks.
Strong Trigger Pattern
---
name: agent-name
description: |
[Role] specialist. MUST BE USED when [specific triggers].
Use PROACTIVELY for [task category].
Keywords: [trigger words]
tools: Read, Write, Edit, Glob, Grep, Bash
model: sonnet
---
Weak vs Strong Descriptions
Weak (won't auto-delegate)
Strong (auto-delegates)
"Analyzes screenshots for issues"
"Visual QA specialist. MUST BE USED when analyzing screenshots. Use PROACTIVELY for visual QA."
"Runs Playwright scripts"
"Playwright specialist. MUST BE USED when running Playwright scripts. Use PROACTIVELY for browser automation."
---
name: agent-name
description: |
[Role] specialist. MUST BE USED when [specific triggers].
Use PROACTIVELY for [task category].
Keywords: [trigger words]
tools: Read, Write, Edit, Glob, Grep, Bash
model: sonnet
---
| Weak (won't auto-delegate) | Strong (auto-delegates) |
|---|---|
| "Analyzes screenshots for issues" | "Visual QA specialist. MUST BE USED when analyzing screenshots. Use PROACTIVELY for visual QA." |
| "Runs Playwright scripts" | "Playwright specialist. MUST BE USED when running Playwright scripts. Use PROACTIVELY for browser automation." |
Key phrases:
- "MUST BE USED when..."
- "Use PROACTIVELY for..."
- Include trigger keywords
Delegation Mechanisms
- Explicit:
Task tool subagent_type: "agent-name" - always works
- Automatic: Claude matches task to agent description - requires strong phrasing
Task tool subagent_type: "agent-name" - always worksSession restart required after creating/modifying agents.
Tool Access Principle
If an agent doesn't need Bash, don't give it Bash.
| Agent needs to... | Give tools | Don't give |
|---|---|---|
| Create files only | Read, Write, Edit, Glob, Grep | Bash |
| Run scripts/CLIs | Read, Write, Edit, Glob, Grep, Bash | — |
| Read/audit only | Read, Glob, Grep | Write, Edit, Bash |
Why? Models default to cat > file << 'EOF' heredocs instead of Write tool. Each bash command requires approval, causing dozens of prompts per agent run.
Allowlist Pattern
Instead of restricting Bash, allowlist safe commands in .claude/settings.json:
{
"permissions": {
"allow": [
"Write", "Edit", "WebFetch(domain:*)",
"Bash(cd *)", "Bash(cp *)", "Bash(mkdir *)", "Bash(ls *)",
"Bash(cat *)", "Bash(head *)", "Bash(tail *)", "Bash(grep *)",
"Bash(diff *)", "Bash(mv *)", "Bash(touch *)", "Bash(file *)"
]
}
}
Model Selection (Quality First)
Don't downgrade quality to work around issues - fix root causes instead.
| Model | Use For |
|---|---|
| Opus | Creative work (page building, design, content) - quality matters |
| Sonnet | Most agents - content, code, research (default) |
| Haiku | Only script runners where quality doesn't matter |
Memory Limits
Root Cause Fix (REQUIRED)
Add to ~/.bashrc or ~/.zshrc:
export NODE_OPTIONS="--max-old-space-size=16384"
Increases Node.js heap from 4GB to 16GB.
Parallel Limits (Even With Fix)
Agent Type
Max Parallel
Notes
Any agents
2-3
Context accumulates; batch then pause
Heavy creative (Opus)
1-2
Uses more memory
Recovery
source ~/.bashrc or restart terminal
NODE_OPTIONS="--max-old-space-size=16384" claude
- Check what files exist, continue from there
Sub-Agent vs Remote API
| Agent Type | Max Parallel | Notes |
|---|---|---|
| Any agents | 2-3 | Context accumulates; batch then pause |
| Heavy creative (Opus) | 1-2 | Uses more memory |
source ~/.bashrcor restart terminalNODE_OPTIONS="--max-old-space-size=16384" claude- Check what files exist, continue from there
Sub-Agent vs Remote API
Always prefer Task sub-agents over remote API calls.
| Aspect | Remote API Call | Task Sub-Agent |
|---|---|---|
| Tool access | None | Full (Read, Grep, Write, Bash) |
| File reading | Must pass all content in prompt | Can read files iteratively |
| Cross-referencing | Single context window | Can reason across documents |
| Decision quality | Generic suggestions | Specific decisions with rationale |
| Output quality | ~100 lines typical | 600+ lines with specifics |
// ❌ WRONG - Remote API call
const response = await fetch('https://api.anthropic.com/v1/messages', {...})
// ✅ CORRECT - Use Task tool
// Invoke Task with subagent_type: "general-purpose"
Declarative Over Imperative
Describe what to accomplish, not how to use tools.
Wrong (Imperative)
### Check for placeholders
```bash
grep -r "PLACEHOLDER:" build/*.html
### Right (Declarative)
```markdown
### Check for placeholders
Search all HTML files in build/ for:
- PLACEHOLDER: comments
- TODO or TBD markers
- Template brackets like [Client Name]
Any match = incomplete content.
What to Include
Include
Skip
Task goal and context
Explicit bash/tool commands
Input file paths
"Use X tool to..."
Output file paths and format
Step-by-step tool invocations
Success/failure criteria
Shell pipeline syntax
Blocking checks (prerequisites)
Micromanaged workflows
Quality checklists
Self-Documentation Principle
"Agents that won't have your context must be able to reproduce the behaviour independently."
### Check for placeholders
```bash
grep -r "PLACEHOLDER:" build/*.html
### Right (Declarative)
```markdown
### Check for placeholders
Search all HTML files in build/ for:
- PLACEHOLDER: comments
- TODO or TBD markers
- Template brackets like [Client Name]
Any match = incomplete content.
| Include | Skip |
|---|---|
| Task goal and context | Explicit bash/tool commands |
| Input file paths | "Use X tool to..." |
| Output file paths and format | Step-by-step tool invocations |
| Success/failure criteria | Shell pipeline syntax |
| Blocking checks (prerequisites) | Micromanaged workflows |
| Quality checklists |
Self-Documentation Principle
"Agents that won't have your context must be able to reproduce the behaviour independently."
"Agents that won't have your context must be able to reproduce the behaviour independently."
Every improvement must be encoded into the agent's prompt, not left as implicit knowledge.
What to Encode
Discovery
Where to Capture
Bug fix pattern
Agent's "Corrections" or "Common Issues" section
Quality requirement
Agent's "Quality Checklist" section
File path convention
Agent's "Output" section
Tool usage pattern
Agent's "Process" section
Blocking prerequisite
Agent's "Blocking Check" section
Test: Would a Fresh Agent Succeed?
| Discovery | Where to Capture |
|---|---|
| Bug fix pattern | Agent's "Corrections" or "Common Issues" section |
| Quality requirement | Agent's "Quality Checklist" section |
| File path convention | Agent's "Output" section |
| Tool usage pattern | Agent's "Process" section |
| Blocking prerequisite | Agent's "Blocking Check" section |
Before completing any agent improvement:
- Read the agent prompt as if you have no context
- Ask: Could a new session follow this and produce the same quality?
- If no: Add missing instructions, patterns, or references
Anti-Patterns
Anti-Pattern
Why It Fails
"As we discussed earlier..."
No prior context exists
Relying on files read during dev
Agent may not read same files
Assuming knowledge from errors
Agent won't see your debugging
"Just like the home page"
Agent hasn't built home page
Agent Prompt Structure
| Anti-Pattern | Why It Fails |
|---|---|
| "As we discussed earlier..." | No prior context exists |
| Relying on files read during dev | Agent may not read same files |
| Assuming knowledge from errors | Agent won't see your debugging |
| "Just like the home page" | Agent hasn't built home page |
Effective agent prompts include:
## Your Role
[What the agent does]
## Blocking Check
[Prerequisites that must exist]
## Input
[What files to read]
## Process
[Step-by-step with encoded learnings]
## Output
[Exact file paths and formats]
## Quality Checklist
[Verification steps including learned gotchas]
## Common Issues
[Patterns discovered during development]
Pipeline Agents
When inserting a new agent into a numbered pipeline (e.g., HTML-01 → HTML-05 → HTML-11):
| Must Update | What |
|---|---|
| New agent | "Workflow Position" diagram + "Next" field |
| Predecessor agent | Its "Next" field to point to new agent |
Common bug: New agent is "orphaned" because predecessor still points to old next agent.
Verification:
grep -n "Next:.*→\|Then.*runs next" .claude/agents/*.md
The Sweet Spot
Best use case: Tasks that are repetitive but require judgment.
Example: Auditing 70 skills manually = tedious. But each audit needs intelligence (check docs, compare versions, decide what to fix). Perfect for parallel agents with clear instructions.
Not good for:
- Simple tasks (just do them)
- Highly creative tasks (need human direction)
- Tasks requiring cross-file coordination (agents work independently)
Effective Prompt Template
For each [item]:
1. Read [source file]
2. Verify with [external check - npm view, API call, etc.]
3. Check [authoritative source]
4. Score/evaluate
5. FIX issues found ← Critical instruction
For each [item]:
1. Read [source file]
2. Verify with [external check - npm view, API call, etc.]
3. Check [authoritative source]
4. Score/evaluate
5. FIX issues found ← Critical instruction
Key elements:
- "FIX issues found" - Without this, agents only report. With it, they take action.
- Exact file paths - Prevents ambiguity
- Output format template - Ensures consistent, parseable reports
- Batch size ~5 items - Enough work to be efficient, not so much that failures cascade
Workflow Pattern
1. ME: Launch 2-3 parallel agents with identical prompt, different item lists
2. AGENTS: Work in parallel (read → verify → check → edit → report)
3. AGENTS: Return structured reports (score, status, fixes applied, files modified)
4. ME: Review changes (git status, spot-check diffs)
5. ME: Commit in batches with meaningful changelog
6. ME: Push and update progress tracking
1. ME: Launch 2-3 parallel agents with identical prompt, different item lists
2. AGENTS: Work in parallel (read → verify → check → edit → report)
3. AGENTS: Return structured reports (score, status, fixes applied, files modified)
4. ME: Review changes (git status, spot-check diffs)
5. ME: Commit in batches with meaningful changelog
6. ME: Push and update progress tracking
Why agents don't commit: Allows human review, batching, and clean commit history.
Signs a Task Fits This Pattern
Good fit:
- Same steps repeated for many items
- Each item requires judgment (not just transformation)
- Items are independent (no cross-item dependencies)
- Clear success criteria (score, pass/fail, etc.)
- Authoritative source exists to verify against
Bad fit:
- Items depend on each other's results
- Requires creative/subjective decisions
- Single complex task (use regular agent instead)
- Needs human input mid-process
Quick Reference
Agent Frontmatter Template
---
name: my-agent
description: |
[Role] specialist. MUST BE USED when [triggers].
Use PROACTIVELY for [task category].
Keywords: [trigger words]
tools: Read, Write, Edit, Glob, Grep, Bash
model: sonnet
---
Fix Bash Approval Spam
- Remove Bash from tools if not needed
- Put critical instructions FIRST (right after frontmatter)
- Use allowlists in
.claude/settings.json
Memory Crash Recovery
export NODE_OPTIONS="--max-old-space-size=16384"
source ~/.bashrc && claude
.claude/settings.jsonexport NODE_OPTIONS="--max-old-space-size=16384"
source ~/.bashrc && claude
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。