cc-dev-template 0.1.74 → 0.1.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/install.js +7 -0
- package/package.json +1 -1
- package/src/commands/done.md +29 -2
- package/src/scripts/task-output-guard.js +4 -66
- package/src/skills/agent-browser/SKILL.md +0 -1
- package/src/skills/creating-sub-agents/SKILL.md +18 -0
- package/src/skills/creating-sub-agents/references/create-step-1-understand.md +46 -0
- package/src/skills/creating-sub-agents/references/create-step-2-design.md +181 -0
- package/src/skills/creating-sub-agents/references/create-step-3-write.md +154 -0
- package/src/skills/creating-sub-agents/references/create-step-4-review.md +67 -0
- package/src/skills/creating-sub-agents/references/create-step-5-install.md +76 -0
- package/src/skills/creating-sub-agents/references/fix-step-1-diagnose.md +99 -0
- package/src/skills/creating-sub-agents/references/fix-step-2-apply.md +77 -0
- package/src/skills/creating-sub-agents/references/fix-step-3-validate.md +52 -0
- package/src/skills/creating-sub-agents/references/principles.md +157 -0
- package/src/skills/creating-sub-agents/scripts/find-subagents.js +217 -0
- package/src/skills/creating-sub-agents/scripts/validate-subagent.js +336 -0
- package/src/skills/creating-sub-agents/templates/basic-subagent.md +21 -0
- package/src/skills/creating-sub-agents/templates/domain-specialist.md +52 -0
- package/src/skills/creating-sub-agents/templates/restricted-subagent.md +29 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Step 5: Install and Test
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
Copy the `.md` file to the target location:
|
|
6
|
+
|
|
7
|
+
| Level | Path |
|
|
8
|
+
|-------|------|
|
|
9
|
+
| User | `~/.claude/agents/<name>.md` |
|
|
10
|
+
| Project | `.claude/agents/<name>.md` |
|
|
11
|
+
|
|
12
|
+
Sub-agents loaded via `/agents` are available immediately. Manually created files require a session restart or use `/agents` to reload.
|
|
13
|
+
|
|
14
|
+
## Test
|
|
15
|
+
|
|
16
|
+
### 1. Delegation Tests
|
|
17
|
+
|
|
18
|
+
Verify Claude delegates to the sub-agent at the right times.
|
|
19
|
+
|
|
20
|
+
**Should delegate** — test 3-5 requests that should trigger delegation:
|
|
21
|
+
- The obvious request matching the description
|
|
22
|
+
- A paraphrased version
|
|
23
|
+
- A domain-specific variant
|
|
24
|
+
|
|
25
|
+
**Should NOT delegate** — test 2-3 unrelated requests:
|
|
26
|
+
- A clearly unrelated task
|
|
27
|
+
- A task in a similar domain that a different sub-agent should handle
|
|
28
|
+
|
|
29
|
+
If the sub-agent under-triggers: strengthen the description with more specific phrasing or add "use proactively" if appropriate.
|
|
30
|
+
If the sub-agent over-triggers: make the description more specific or narrow the scope.
|
|
31
|
+
|
|
32
|
+
### 2. Functional Tests
|
|
33
|
+
|
|
34
|
+
Test the sub-agent produces correct output:
|
|
35
|
+
|
|
36
|
+
1. Start a new Claude Code session (or use `/agents` to reload)
|
|
37
|
+
2. Request a task matching the sub-agent's description
|
|
38
|
+
3. Verify:
|
|
39
|
+
- The sub-agent uses only its granted tools
|
|
40
|
+
- The output matches the expected format
|
|
41
|
+
- The sub-agent stays within its defined boundaries
|
|
42
|
+
- It completes without errors or hanging
|
|
43
|
+
|
|
44
|
+
### 3. Explicit Invocation Test
|
|
45
|
+
|
|
46
|
+
Ask Claude to use the sub-agent by name:
|
|
47
|
+
```
|
|
48
|
+
Use the code-reviewer sub-agent to review the authentication module
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 4. Edge Cases
|
|
52
|
+
|
|
53
|
+
- What happens with an empty or trivial input?
|
|
54
|
+
- What happens if the sub-agent encounters an error?
|
|
55
|
+
- Does the output stay concise, or does it dump everything?
|
|
56
|
+
|
|
57
|
+
### 5. Iteration
|
|
58
|
+
|
|
59
|
+
If testing reveals issues, iterate:
|
|
60
|
+
|
|
61
|
+
- Description wrong? Adjust description and retest.
|
|
62
|
+
- Tools too broad or narrow? Adjust `tools` field.
|
|
63
|
+
- Output too verbose? Add output format constraints to the prompt.
|
|
64
|
+
- Prompt unclear? Go back to the write step.
|
|
65
|
+
- Wrong scope entirely? Reconsider whether this should be a skill instead.
|
|
66
|
+
|
|
67
|
+
## Completion
|
|
68
|
+
|
|
69
|
+
Summarize what was created:
|
|
70
|
+
- Sub-agent name
|
|
71
|
+
- Install location
|
|
72
|
+
- Description (when it triggers)
|
|
73
|
+
- Tool access
|
|
74
|
+
- Model
|
|
75
|
+
- Memory scope (if any)
|
|
76
|
+
- Skills preloaded (if any)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Step 1: Diagnose
|
|
2
|
+
|
|
3
|
+
Find the sub-agent, read it, and understand what is wrong.
|
|
4
|
+
|
|
5
|
+
## Find the Sub-Agent
|
|
6
|
+
|
|
7
|
+
If the user named a specific sub-agent, locate it. Otherwise, discover available sub-agents:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
node ~/.claude/skills/creating-sub-agents/scripts/find-subagents.js
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Ask which sub-agent to fix.
|
|
14
|
+
|
|
15
|
+
## Read the File
|
|
16
|
+
|
|
17
|
+
Read the entire `.md` file — frontmatter and body. Sub-agents are single files, so there is only one file to read.
|
|
18
|
+
|
|
19
|
+
Also check for related resources:
|
|
20
|
+
- Hook scripts referenced in frontmatter
|
|
21
|
+
- Skills listed in `skills` field (verify they exist)
|
|
22
|
+
- MCP server configurations
|
|
23
|
+
|
|
24
|
+
## Understand What Is Wrong
|
|
25
|
+
|
|
26
|
+
Ask the user:
|
|
27
|
+
- "What is the sub-agent supposed to do?"
|
|
28
|
+
- "What does it actually do instead?"
|
|
29
|
+
- "Can you show me an example of it failing or misbehaving?"
|
|
30
|
+
|
|
31
|
+
Get specific about expected behavior versus actual behavior.
|
|
32
|
+
|
|
33
|
+
## Diagnose Against Principles
|
|
34
|
+
|
|
35
|
+
Read `references/principles.md` for the full set of principles, then evaluate:
|
|
36
|
+
|
|
37
|
+
### Focus
|
|
38
|
+
- Does the sub-agent have ONE clear job?
|
|
39
|
+
- Is the scope too broad? (trying to review, debug, AND test)
|
|
40
|
+
- Would splitting into multiple sub-agents help?
|
|
41
|
+
|
|
42
|
+
### System Prompt Quality
|
|
43
|
+
- Is there a clear role statement?
|
|
44
|
+
- Are trigger instructions present? ("When invoked, do X")
|
|
45
|
+
- Is the output format defined?
|
|
46
|
+
- Does it contain only tribal knowledge, not public knowledge?
|
|
47
|
+
- Any dead ends where the sub-agent wouldn't know what to do?
|
|
48
|
+
|
|
49
|
+
### Frontmatter Configuration
|
|
50
|
+
- Is `description` specific enough for Claude to delegate accurately?
|
|
51
|
+
- Are `tools` appropriate? (reviewer with Write access? modifier without it?)
|
|
52
|
+
- Is `model` appropriate for the task complexity?
|
|
53
|
+
- If `skills` are listed, do those skills exist?
|
|
54
|
+
- If `memory` is enabled, are memory instructions in the prompt?
|
|
55
|
+
|
|
56
|
+
### Writing Style
|
|
57
|
+
- Second person? ("You should check..." — should be "Check...")
|
|
58
|
+
- Negative framing? ("Don't modify..." — should be "Only modify...")
|
|
59
|
+
- Hedging? ("Maybe consider..." — should be "Analyze...")
|
|
60
|
+
- Over-verbose? (public knowledge Claude already has)
|
|
61
|
+
|
|
62
|
+
### Integration Issues
|
|
63
|
+
- Name conflicts with other sub-agents at same or higher scope?
|
|
64
|
+
- Description overlaps with other sub-agents?
|
|
65
|
+
- Hook scripts exist and are executable?
|
|
66
|
+
|
|
67
|
+
## Summarize Findings
|
|
68
|
+
|
|
69
|
+
Present the diagnosis:
|
|
70
|
+
- List each issue found
|
|
71
|
+
- What principle it violates
|
|
72
|
+
- What the fix would look like
|
|
73
|
+
|
|
74
|
+
## Classify the Fix Type
|
|
75
|
+
|
|
76
|
+
**Surface fixes** — wording, style, description tweaks, missing output format:
|
|
77
|
+
- Fixing second person to imperative
|
|
78
|
+
- Adding output format section
|
|
79
|
+
- Improving description with better trigger language
|
|
80
|
+
- Removing public knowledge
|
|
81
|
+
- Adding missing constraints
|
|
82
|
+
|
|
83
|
+
**Structural changes** — anything that changes the sub-agent's design:
|
|
84
|
+
- Changing tool access strategy
|
|
85
|
+
- Adding/removing skills preloading
|
|
86
|
+
- Adding memory
|
|
87
|
+
- Adding hooks
|
|
88
|
+
- Splitting a broad sub-agent into multiple focused ones
|
|
89
|
+
- Changing scope (project to user or vice versa)
|
|
90
|
+
- Fundamentally rewriting the system prompt
|
|
91
|
+
|
|
92
|
+
Tell the user which type of fix is needed.
|
|
93
|
+
|
|
94
|
+
## Next Step
|
|
95
|
+
|
|
96
|
+
| Fix Type | Action |
|
|
97
|
+
|----------|--------|
|
|
98
|
+
| Surface fixes only | Read `references/fix-step-2-apply.md` |
|
|
99
|
+
| Structural changes needed | Read `references/create-step-2-design.md` to redesign, then `references/fix-step-2-apply.md` to apply |
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Step 2: Apply Fixes
|
|
2
|
+
|
|
3
|
+
Fix the issues identified in diagnosis. Plan changes, confirm, then apply.
|
|
4
|
+
|
|
5
|
+
## If Coming From Design Step
|
|
6
|
+
|
|
7
|
+
If you just read `create-step-2-design.md` for structural changes, use that design as the blueprint. The writing principles below still apply.
|
|
8
|
+
|
|
9
|
+
## Plan Changes First
|
|
10
|
+
|
|
11
|
+
Before editing, state:
|
|
12
|
+
- What specifically changes in the frontmatter
|
|
13
|
+
- What specifically changes in the system prompt body
|
|
14
|
+
- Any external changes needed (hook scripts, skill files)
|
|
15
|
+
|
|
16
|
+
Confirm the plan with the user before making changes.
|
|
17
|
+
|
|
18
|
+
## Writing Principles
|
|
19
|
+
|
|
20
|
+
Apply these while making every change:
|
|
21
|
+
|
|
22
|
+
### System Prompt, Not Step-by-Step Instructions
|
|
23
|
+
|
|
24
|
+
Sub-agent bodies provide context and behavior guidance, not sequential workflows.
|
|
25
|
+
|
|
26
|
+
| Skill-style (wrong for sub-agents) | System prompt style (correct) |
|
|
27
|
+
|---|---|
|
|
28
|
+
| "Step 1: Read the file. Step 2: Parse the JSON. Step 3: Validate." | "When invoked, analyze files for schema compliance. Report violations by severity." |
|
|
29
|
+
|
|
30
|
+
Exception: A brief "When invoked:" numbered list is fine for establishing the high-level workflow. Avoid micromanaging individual steps.
|
|
31
|
+
|
|
32
|
+
### Imperative and Direct
|
|
33
|
+
|
|
34
|
+
| Wrong | Right |
|
|
35
|
+
|-------|-------|
|
|
36
|
+
| "You should analyze the code" | "Analyze the code" |
|
|
37
|
+
| "It might be helpful to check" | "Check" |
|
|
38
|
+
| "Consider looking at" | "Inspect" |
|
|
39
|
+
|
|
40
|
+
### Positive Framing
|
|
41
|
+
|
|
42
|
+
| Negative | Positive |
|
|
43
|
+
|----------|----------|
|
|
44
|
+
| "Don't return verbose output" | "Return concise summaries" |
|
|
45
|
+
| "Avoid files outside your domain" | "Only modify files within your domain" |
|
|
46
|
+
| "Never skip validation" | "Always validate first" |
|
|
47
|
+
|
|
48
|
+
### Tribal Knowledge Only
|
|
49
|
+
|
|
50
|
+
Remove anything Claude already knows. Keep project-specific conventions, internal tool usage, and domain-specific patterns.
|
|
51
|
+
|
|
52
|
+
### Output Format
|
|
53
|
+
|
|
54
|
+
Every sub-agent needs clear output guidance. If missing, add it:
|
|
55
|
+
|
|
56
|
+
```markdown
|
|
57
|
+
Provide feedback organized by priority:
|
|
58
|
+
- Critical issues (must fix)
|
|
59
|
+
- Warnings (should fix)
|
|
60
|
+
- Suggestions (consider improving)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Description Improvement
|
|
64
|
+
|
|
65
|
+
If the description needs fixing:
|
|
66
|
+
- State WHAT the sub-agent does and WHEN to use it
|
|
67
|
+
- Include "use proactively" for auto-triggering sub-agents
|
|
68
|
+
- Keep it specific but not exhaustive
|
|
69
|
+
- Avoid explaining HOW it works
|
|
70
|
+
|
|
71
|
+
## Apply the Changes
|
|
72
|
+
|
|
73
|
+
Make all planned modifications now.
|
|
74
|
+
|
|
75
|
+
For structural changes that involve rewriting the system prompt, reference `references/create-step-3-write.md` for the complete writing guidance.
|
|
76
|
+
|
|
77
|
+
Read `references/fix-step-3-validate.md` when all fixes are applied.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Step 3: Validate and Test
|
|
2
|
+
|
|
3
|
+
## Public Knowledge Audit
|
|
4
|
+
|
|
5
|
+
Go through every changed section. Find each code block, CLI command, and implementation detail.
|
|
6
|
+
|
|
7
|
+
For each one: "Would a fresh Claude instance know how to do this?"
|
|
8
|
+
- If yes: delete it, replace with high-level instruction.
|
|
9
|
+
- If no: keep it — tribal knowledge.
|
|
10
|
+
|
|
11
|
+
## Self-Review
|
|
12
|
+
|
|
13
|
+
Re-read the entire file. Verify:
|
|
14
|
+
|
|
15
|
+
- Role statement is concise?
|
|
16
|
+
- Clear trigger behavior?
|
|
17
|
+
- Output format defined?
|
|
18
|
+
- Issues from diagnosis resolved?
|
|
19
|
+
- Fixes did not introduce new problems?
|
|
20
|
+
- Writing style correct? (imperative, positive, direct)
|
|
21
|
+
- Frontmatter valid and consistent?
|
|
22
|
+
|
|
23
|
+
## Run Validation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
node ~/.claude/skills/creating-sub-agents/scripts/validate-subagent.js [agent-file-path]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Handle results:
|
|
30
|
+
- **Errors:** Fix, re-run, repeat until passing
|
|
31
|
+
- **Warnings:** Evaluate and fix most
|
|
32
|
+
- **Info:** Review — may be acceptable
|
|
33
|
+
|
|
34
|
+
## Test
|
|
35
|
+
|
|
36
|
+
If the fix affected behavior:
|
|
37
|
+
|
|
38
|
+
1. Restart Claude Code or use `/agents` to reload
|
|
39
|
+
2. If description changed: test delegation with matching requests
|
|
40
|
+
3. If prompt changed: invoke the sub-agent and verify behavior
|
|
41
|
+
4. If tools changed: verify the sub-agent can (and cannot) access the right tools
|
|
42
|
+
|
|
43
|
+
## If Issues Remain
|
|
44
|
+
|
|
45
|
+
Go back to `references/fix-step-2-apply.md`.
|
|
46
|
+
|
|
47
|
+
## Completion
|
|
48
|
+
|
|
49
|
+
Summarize what was fixed:
|
|
50
|
+
- Which aspects changed (frontmatter, prompt, hooks)
|
|
51
|
+
- What was wrong and how it was resolved
|
|
52
|
+
- Confirm with the user that the sub-agent now behaves as expected
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Sub-Agent Design Principles
|
|
2
|
+
|
|
3
|
+
## Contents
|
|
4
|
+
|
|
5
|
+
- [Sub-Agents vs Skills](#sub-agents-vs-skills)
|
|
6
|
+
- [The System Prompt Is Everything](#the-system-prompt-is-everything)
|
|
7
|
+
- [Prompt Design for Sub-Agents](#prompt-design-for-sub-agents)
|
|
8
|
+
- [Focus and Constraint](#focus-and-constraint)
|
|
9
|
+
- [Tool Restriction Philosophy](#tool-restriction-philosophy)
|
|
10
|
+
- [Description Quality](#description-quality)
|
|
11
|
+
- [Memory Design](#memory-design)
|
|
12
|
+
- [Key Limitations](#key-limitations)
|
|
13
|
+
- [Anti-Patterns](#anti-patterns)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Sub-Agents vs Skills
|
|
18
|
+
|
|
19
|
+
Sub-agents and skills solve different problems. Choose the right one:
|
|
20
|
+
|
|
21
|
+
| Use a sub-agent when... | Use a skill when... |
|
|
22
|
+
|---|---|
|
|
23
|
+
| The task produces verbose output you want isolated | The task needs access to conversation history |
|
|
24
|
+
| You want to enforce tool restrictions | You want reusable prompts that run inline |
|
|
25
|
+
| The work is self-contained and returns a summary | Follow-up interaction is expected |
|
|
26
|
+
| You want persistent memory across sessions | You need progressive disclosure across steps |
|
|
27
|
+
| You want to route tasks to a cheaper/faster model | The instructions change based on user input |
|
|
28
|
+
| Parallel execution benefits the workflow | The workflow has branching paths |
|
|
29
|
+
|
|
30
|
+
**Key difference:** A skill is instructions Claude reads and follows in the current conversation. A sub-agent is an isolated worker with its own system prompt, tools, and context window.
|
|
31
|
+
|
|
32
|
+
## The System Prompt Is Everything
|
|
33
|
+
|
|
34
|
+
A sub-agent's markdown body IS its system prompt. Unlike skills (where content is instructions loaded on-demand), the sub-agent body is read once at spawn and provides all context for the sub-agent's entire execution.
|
|
35
|
+
|
|
36
|
+
| Aspect | Skill SKILL.md | Sub-Agent .md body |
|
|
37
|
+
|--------|----------------|---------------------|
|
|
38
|
+
| When read | Each time skill is invoked | Once at spawn |
|
|
39
|
+
| Purpose | Route to workflows, provide step-by-step instructions | Provide complete context for focused task |
|
|
40
|
+
| Lifespan | Entire user session (repeated activations) | Single invocation |
|
|
41
|
+
| Context | Shares main conversation context | Isolated context window |
|
|
42
|
+
| Progressive disclosure | Essential — load content on-demand | Not applicable — one file, one prompt |
|
|
43
|
+
|
|
44
|
+
Sub-agents receive only their system prompt plus basic environment details (working directory). They do not receive the full Claude Code system prompt.
|
|
45
|
+
|
|
46
|
+
## Prompt Design for Sub-Agents
|
|
47
|
+
|
|
48
|
+
Sub-agent prompts benefit from context that would be wasteful in skills:
|
|
49
|
+
|
|
50
|
+
**Include in sub-agent prompts:**
|
|
51
|
+
- Role and purpose — the sub-agent needs full context upfront
|
|
52
|
+
- What success looks like — guides decision-making throughout execution
|
|
53
|
+
- Constraints and boundaries — what the sub-agent should NOT do
|
|
54
|
+
- Output format — what to return to the parent conversation
|
|
55
|
+
- Domain knowledge the sub-agent needs to do its job
|
|
56
|
+
|
|
57
|
+
**Omit from sub-agent prompts:**
|
|
58
|
+
- Public knowledge Claude already has (standard tools, common patterns)
|
|
59
|
+
- Step-by-step instructions for obvious tasks
|
|
60
|
+
- Exhaustive examples when one or two suffice
|
|
61
|
+
|
|
62
|
+
The test: does every line in the prompt help the sub-agent do its specific job better? If not, remove it.
|
|
63
|
+
|
|
64
|
+
## Focus and Constraint
|
|
65
|
+
|
|
66
|
+
Design each sub-agent to excel at ONE specific task. A focused sub-agent with clear boundaries outperforms a broad one with vague responsibilities.
|
|
67
|
+
|
|
68
|
+
**Focused (good):** "Reviews code for quality, security, and best practices. Returns actionable feedback."
|
|
69
|
+
|
|
70
|
+
**Broad (bad):** "Helps with various development tasks including code review, debugging, testing, and documentation."
|
|
71
|
+
|
|
72
|
+
When a sub-agent's scope creeps, split it into multiple sub-agents.
|
|
73
|
+
|
|
74
|
+
## Tool Restriction Philosophy
|
|
75
|
+
|
|
76
|
+
Grant only the tools needed for the task. This is a security and focus benefit.
|
|
77
|
+
|
|
78
|
+
| Sub-agent type | Typical tools |
|
|
79
|
+
|---|---|
|
|
80
|
+
| Read-only reviewer | Read, Grep, Glob, Bash |
|
|
81
|
+
| Code modifier | Read, Grep, Glob, Edit, Write, Bash |
|
|
82
|
+
| Research/exploration | Read, Grep, Glob |
|
|
83
|
+
| Full-capability worker | All tools (inherit) |
|
|
84
|
+
|
|
85
|
+
Use `tools` as an allowlist (explicitly grant tools) or `disallowedTools` as a denylist (explicitly remove tools from the inherited set). Choose one approach — do not mix both.
|
|
86
|
+
|
|
87
|
+
For fine-grained control beyond tool-level, use `hooks` with `PreToolUse` to validate specific operations before they execute.
|
|
88
|
+
|
|
89
|
+
## Description Quality
|
|
90
|
+
|
|
91
|
+
The description determines when Claude delegates to the sub-agent. Write it for Claude, not for humans.
|
|
92
|
+
|
|
93
|
+
**Effective descriptions:**
|
|
94
|
+
- State what the sub-agent does and when to use it
|
|
95
|
+
- Include "use proactively" if the sub-agent should auto-activate
|
|
96
|
+
- Be specific enough that Claude can match tasks accurately
|
|
97
|
+
|
|
98
|
+
**Good:**
|
|
99
|
+
```
|
|
100
|
+
Expert code review specialist. Proactively reviews code for quality,
|
|
101
|
+
security, and maintainability. Use immediately after writing or
|
|
102
|
+
modifying code.
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Bad:**
|
|
106
|
+
```
|
|
107
|
+
Helps with code stuff.
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Also bad (too detailed):**
|
|
111
|
+
```
|
|
112
|
+
Uses AST parsing to analyze cyclomatic complexity, checks for OWASP
|
|
113
|
+
top 10 vulnerabilities including SQL injection and XSS, validates
|
|
114
|
+
against the Google style guide...
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
If the description explains too much about HOW, Claude thinks it already knows enough and may not delegate. Focus on WHAT and WHEN.
|
|
118
|
+
|
|
119
|
+
## Memory Design
|
|
120
|
+
|
|
121
|
+
Enable memory when the sub-agent benefits from cross-session learning.
|
|
122
|
+
|
|
123
|
+
| Scope | Location | Use when |
|
|
124
|
+
|---|---|---|
|
|
125
|
+
| `user` | `~/.claude/agent-memory/<name>/` | Knowledge applies across all projects |
|
|
126
|
+
| `project` | `.claude/agent-memory/<name>/` | Knowledge is project-specific, shareable via git |
|
|
127
|
+
| `local` | `.claude/agent-memory-local/<name>/` | Knowledge is project-specific, private |
|
|
128
|
+
|
|
129
|
+
`user` is the recommended default. Use `project` when the sub-agent's knowledge is codebase-specific and the team benefits from sharing it.
|
|
130
|
+
|
|
131
|
+
When memory is enabled, the system automatically includes the first 200 lines of `MEMORY.md` in the sub-agent's prompt and enables Read, Write, and Edit tools for the memory directory.
|
|
132
|
+
|
|
133
|
+
Include memory instructions in the sub-agent's prompt:
|
|
134
|
+
```
|
|
135
|
+
Update your agent memory as you discover patterns, conventions,
|
|
136
|
+
and key decisions. This builds institutional knowledge across sessions.
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Key Limitations
|
|
140
|
+
|
|
141
|
+
- Sub-agents **cannot spawn other sub-agents**. Nesting depth is exactly 1.
|
|
142
|
+
- Sub-agents **do not have access to the Skill tool**. They cannot discover or invoke skills.
|
|
143
|
+
- Sub-agents **do not inherit skills** from the parent conversation. Use the `skills` frontmatter to pre-load skill content.
|
|
144
|
+
- Sub-agents receive a **stripped-down system prompt**, not the full Claude Code system prompt.
|
|
145
|
+
- Background sub-agents **auto-deny permission prompts** not pre-approved at launch. MCP tools are unavailable in background sub-agents.
|
|
146
|
+
|
|
147
|
+
## Anti-Patterns
|
|
148
|
+
|
|
149
|
+
**Over-broad sub-agents.** A sub-agent that "does everything" provides no focus benefit. Split into specialized sub-agents.
|
|
150
|
+
|
|
151
|
+
**Missing output format.** Without clear output guidance, sub-agents may return verbose dumps instead of useful summaries. Always specify what to return.
|
|
152
|
+
|
|
153
|
+
**Granting all tools by default.** Omitting `tools` inherits everything. Be intentional — a code reviewer should not have Write access.
|
|
154
|
+
|
|
155
|
+
**Duplicate sub-agents at different scopes.** A project-level agent with the same name as a user-level agent shadows the user-level one. This causes confusion. Use distinct names or be intentional about overrides.
|
|
156
|
+
|
|
157
|
+
**Putting step-by-step skill logic in a sub-agent prompt.** If the task has branching workflows or progressive disclosure, use a skill instead. Sub-agents are for focused, self-contained work.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* find-subagents.js
|
|
5
|
+
*
|
|
6
|
+
* Discovers all Claude Code sub-agent definitions at user and project levels.
|
|
7
|
+
* Returns sub-agent locations and basic metadata.
|
|
8
|
+
*
|
|
9
|
+
* Usage: node find-subagents.js [--json] [--verbose]
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const os = require('os');
|
|
15
|
+
|
|
16
|
+
const args = process.argv.slice(2);
|
|
17
|
+
const jsonOutput = args.includes('--json');
|
|
18
|
+
const verbose = args.includes('--verbose');
|
|
19
|
+
|
|
20
|
+
const locations = [
|
|
21
|
+
{
|
|
22
|
+
name: 'user',
|
|
23
|
+
path: path.join(os.homedir(), '.claude', 'agents'),
|
|
24
|
+
description: 'User-level sub-agents (~/.claude/agents/)'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'project',
|
|
28
|
+
path: path.join(process.cwd(), '.claude', 'agents'),
|
|
29
|
+
description: 'Project-level sub-agents (.claude/agents/)'
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function parseFrontmatter(content) {
|
|
34
|
+
const match = content.match(/^---\n([\s\S]*?)\n---/);
|
|
35
|
+
if (!match) return null;
|
|
36
|
+
|
|
37
|
+
const frontmatter = {};
|
|
38
|
+
const lines = match[1].split('\n');
|
|
39
|
+
let currentKey = null;
|
|
40
|
+
let inArray = false;
|
|
41
|
+
let arrayValues = [];
|
|
42
|
+
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
// Handle array items
|
|
45
|
+
if (inArray && line.match(/^\s+-\s+/)) {
|
|
46
|
+
arrayValues.push(line.replace(/^\s+-\s+/, '').trim());
|
|
47
|
+
continue;
|
|
48
|
+
} else if (inArray) {
|
|
49
|
+
frontmatter[currentKey] = arrayValues;
|
|
50
|
+
inArray = false;
|
|
51
|
+
arrayValues = [];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const colonIndex = line.indexOf(':');
|
|
55
|
+
if (colonIndex > 0) {
|
|
56
|
+
const key = line.slice(0, colonIndex).trim();
|
|
57
|
+
let value = line.slice(colonIndex + 1).trim();
|
|
58
|
+
|
|
59
|
+
if (value === '' || value === '|' || value === '>') {
|
|
60
|
+
currentKey = key;
|
|
61
|
+
if (value === '') {
|
|
62
|
+
// Could be start of array or multi-line
|
|
63
|
+
inArray = true;
|
|
64
|
+
arrayValues = [];
|
|
65
|
+
}
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
70
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
71
|
+
value = value.slice(1, -1);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
frontmatter[key] = value;
|
|
75
|
+
currentKey = key;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (inArray && currentKey) {
|
|
80
|
+
frontmatter[currentKey] = arrayValues;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return frontmatter;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getBody(content) {
|
|
87
|
+
const match = content.match(/^---\n[\s\S]*?\n---\n([\s\S]*)$/);
|
|
88
|
+
return match ? match[1] : content;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getAgentStats(filePath) {
|
|
92
|
+
if (!fs.existsSync(filePath)) return null;
|
|
93
|
+
|
|
94
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
95
|
+
const frontmatter = parseFrontmatter(content);
|
|
96
|
+
const body = getBody(content);
|
|
97
|
+
const wordCount = body.split(/\s+/).filter(w => w.length > 0).length;
|
|
98
|
+
const lineCount = body.split('\n').length;
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
name: frontmatter?.name || path.basename(filePath, '.md'),
|
|
102
|
+
description: frontmatter?.description || null,
|
|
103
|
+
tools: frontmatter?.tools || '(inherits all)',
|
|
104
|
+
disallowedTools: frontmatter?.disallowedTools || null,
|
|
105
|
+
model: frontmatter?.model || 'inherit',
|
|
106
|
+
permissionMode: frontmatter?.permissionMode || 'default',
|
|
107
|
+
skills: frontmatter?.skills || null,
|
|
108
|
+
memory: frontmatter?.memory || null,
|
|
109
|
+
maxTurns: frontmatter?.maxTurns || null,
|
|
110
|
+
wordCount,
|
|
111
|
+
lineCount,
|
|
112
|
+
frontmatterValid: !!(frontmatter?.name && frontmatter?.description)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function scanLocation(location) {
|
|
117
|
+
const agents = [];
|
|
118
|
+
|
|
119
|
+
if (!fs.existsSync(location.path)) return agents;
|
|
120
|
+
|
|
121
|
+
const entries = fs.readdirSync(location.path, { withFileTypes: true });
|
|
122
|
+
|
|
123
|
+
for (const entry of entries) {
|
|
124
|
+
if (!entry.isFile() || !entry.name.endsWith('.md')) continue;
|
|
125
|
+
|
|
126
|
+
const filePath = path.join(location.path, entry.name);
|
|
127
|
+
const stats = getAgentStats(filePath);
|
|
128
|
+
|
|
129
|
+
if (stats) {
|
|
130
|
+
agents.push({
|
|
131
|
+
file: entry.name,
|
|
132
|
+
path: filePath,
|
|
133
|
+
location: location.name,
|
|
134
|
+
...stats
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return agents;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Main
|
|
143
|
+
const results = {
|
|
144
|
+
timestamp: new Date().toISOString(),
|
|
145
|
+
cwd: process.cwd(),
|
|
146
|
+
locations: {},
|
|
147
|
+
agents: [],
|
|
148
|
+
summary: {
|
|
149
|
+
total: 0,
|
|
150
|
+
byLocation: {}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
for (const location of locations) {
|
|
155
|
+
const agents = scanLocation(location);
|
|
156
|
+
|
|
157
|
+
results.locations[location.name] = {
|
|
158
|
+
path: location.path,
|
|
159
|
+
exists: fs.existsSync(location.path),
|
|
160
|
+
count: agents.length
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
results.agents.push(...agents);
|
|
164
|
+
results.summary.byLocation[location.name] = agents.length;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
results.summary.total = results.agents.length;
|
|
168
|
+
|
|
169
|
+
if (jsonOutput) {
|
|
170
|
+
console.log(JSON.stringify(results, null, 2));
|
|
171
|
+
} else {
|
|
172
|
+
console.log('\n=== Claude Code Sub-Agent Discovery ===\n');
|
|
173
|
+
|
|
174
|
+
for (const location of locations) {
|
|
175
|
+
const info = results.locations[location.name];
|
|
176
|
+
console.log(`${location.description}`);
|
|
177
|
+
console.log(` Path: ${info.path}`);
|
|
178
|
+
console.log(` Exists: ${info.exists ? 'Yes' : 'No'}`);
|
|
179
|
+
console.log(` Sub-agents found: ${info.count}`);
|
|
180
|
+
console.log();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (results.agents.length === 0) {
|
|
184
|
+
console.log('No sub-agents found.\n');
|
|
185
|
+
} else {
|
|
186
|
+
console.log('=== Sub-Agents ===\n');
|
|
187
|
+
|
|
188
|
+
for (const agent of results.agents) {
|
|
189
|
+
console.log(`[${agent.location}] ${agent.name}`);
|
|
190
|
+
console.log(` File: ${agent.path}`);
|
|
191
|
+
console.log(` Tools: ${agent.tools}`);
|
|
192
|
+
console.log(` Model: ${agent.model}`);
|
|
193
|
+
|
|
194
|
+
if (verbose) {
|
|
195
|
+
console.log(` Words: ${agent.wordCount}`);
|
|
196
|
+
console.log(` Lines: ${agent.lineCount}`);
|
|
197
|
+
console.log(` Valid frontmatter: ${agent.frontmatterValid ? 'Yes' : 'No'}`);
|
|
198
|
+
console.log(` Permission mode: ${agent.permissionMode}`);
|
|
199
|
+
if (agent.skills) console.log(` Skills: ${JSON.stringify(agent.skills)}`);
|
|
200
|
+
if (agent.memory) console.log(` Memory: ${agent.memory}`);
|
|
201
|
+
if (agent.maxTurns) console.log(` Max turns: ${agent.maxTurns}`);
|
|
202
|
+
if (agent.disallowedTools) console.log(` Disallowed tools: ${agent.disallowedTools}`);
|
|
203
|
+
|
|
204
|
+
if (agent.description) {
|
|
205
|
+
const truncated = agent.description.length > 80
|
|
206
|
+
? agent.description.slice(0, 80) + '...'
|
|
207
|
+
: agent.description;
|
|
208
|
+
console.log(` Description: ${truncated}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
console.log();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
console.log(`Total: ${results.summary.total} sub-agent(s)\n`);
|
|
216
|
+
}
|
|
217
|
+
}
|