Skip to content

Commit 0e83403

Browse files
sjnimsclaude
andcommitted
docs: address documentation gaps vs official Claude Code docs
Add missing features, fix inaccuracies, and expand coverage across all skills to match the official Claude Code documentation. Agent development: add maxTurns, memory, mcpServers, hooks fields; execution modes; agent teams; new advanced-agent-fields.md reference. Hook development: add TeammateIdle/TaskCompleted events; once and statusMessage handler fields; event-specific matchers; decision control output schemas; async hooks; two new patterns. Marketplace: add enterprise features (strictKnownMarketplaces, private repo auth, reserved names); ref/sha pinning; hostPattern source type. Plugin structure: fix outputStyles from inline JSON to path-based field; add plugin validation commands; add npm/pip source types. Skill development: add visual output generators; Skill() permission syntax; update context budget to 2%/16KB. MCP integration: fix allowedServers/blockedServers to correct allowedMcpServers/deniedMcpServers with matcher types; add claude mcp serve, list_changed, output limits. LSP integration: add socket transport example; initializationOptions example; full config with all optional fields. Component patterns: add new agent fields, hook events, agent hook type. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f217fe9 commit 0e83403

15 files changed

Lines changed: 933 additions & 52 deletions

File tree

docs/component-patterns.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Agents require YAML frontmatter with:
1414
- `disallowedTools`: Comma-separated list of blocked tools (optional, denylist — use one or the other)
1515
- `skills`: Comma-separated list of skills the agent can load (optional)
1616
- `permissionMode`: acceptEdits/dontAsk/bypassPermissions/plan (optional)
17+
- `maxTurns`: Number limiting agentic turns (optional)
18+
- `memory`: user/project/local for persistent memory (optional)
19+
- `mcpServers`: Scoped MCP server access (optional)
20+
- `hooks`: Lifecycle hooks scoped to agent (optional)
1721

1822
## Skills
1923

@@ -65,8 +69,8 @@ disallowedTools: Bash, Write # Denylist
6569

6670
Hooks defined in `hooks/hooks.json`:
6771

68-
- Events: PreToolUse, PermissionRequest, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification
69-
- Types: `prompt` (LLM-driven) or `command` (bash scripts)
72+
- Events: PreToolUse, PermissionRequest, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification, TeammateIdle, TaskCompleted
73+
- Types: `prompt` (LLM-driven), `command` (bash scripts), or `agent` (multi-step with tools)
7074
- Use matchers for tool filtering (e.g., "Write|Edit", "\*")
7175

7276
### Plugin hooks.json Format

plugins/plugin-dev/skills/agent-development/SKILL.md

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: agent-development
3-
description: This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", "disallowedTools", "block tools", "agent denylist", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
3+
description: This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", "disallowedTools", "block tools", "agent denylist", "maxTurns", "agent memory", "mcpServers in agent", "agent hooks", "background agent", "resume agent", "agent teams", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
44
---
55

66
# Agent Development for Claude Code Plugins
@@ -310,6 +310,60 @@ permissionMode: acceptEdits
310310

311311
**Security note:** Use restrictive modes (`plan`, `acceptEdits`) for untrusted agents. `bypassPermissions` should only be used for fully trusted agents.
312312

313+
### maxTurns (optional)
314+
315+
Limit the maximum number of agentic turns before the agent stops:
316+
317+
```yaml
318+
maxTurns: 50
319+
```
320+
321+
**Use cases:**
322+
323+
- Prevent runaway agents from consuming excessive resources
324+
- Set reasonable bounds for task complexity
325+
- Higher values (50-100) for complex multi-file tasks; lower values (10-20) for focused checks
326+
327+
If omitted, the agent runs until it completes or the user interrupts.
328+
329+
### memory (optional)
330+
331+
Enable persistent memory across sessions:
332+
333+
```yaml
334+
memory: user
335+
```
336+
337+
**Scopes:** `user` (~/.claude/agent-memory/), `project` (.claude/agent-memory/), `local` (.claude/agent-memory-local/)
338+
339+
When enabled, the agent's first 200 lines of `MEMORY.md` are auto-injected into its system prompt. The agent can read/write its memory directory to learn across sessions. See `references/advanced-agent-fields.md` for details.
340+
341+
### mcpServers (optional)
342+
343+
Scope MCP servers to this agent:
344+
345+
```yaml
346+
mcpServers:
347+
slack:
348+
```
349+
350+
Reference an already-configured server by name, or provide inline config. Restricts which MCP servers the agent can access. See `references/advanced-agent-fields.md` for configuration examples.
351+
352+
### hooks (optional)
353+
354+
Define lifecycle hooks scoped to this agent:
355+
356+
```yaml
357+
hooks:
358+
PreToolUse:
359+
- matcher: Bash
360+
hooks:
361+
- type: command
362+
command: "${CLAUDE_PLUGIN_ROOT}/scripts/validate-bash.sh"
363+
```
364+
365+
Supports all hook events. Note: `Stop` hooks in agent frontmatter are auto-converted to `SubagentStop` at runtime. Hooks activate when the agent starts and deactivate when it finishes. See `references/advanced-agent-fields.md` for full details.
366+
313367
### Fields NOT Available for Agents
314368

315369
Some frontmatter fields are specific to skills and do not apply to agents:
@@ -501,6 +555,10 @@ Ensure system prompt is complete:
501555
| disallowedTools | No | Comma-separated tool names | Bash, Write |
502556
| skills | No | Array of skill names | [testing, security] |
503557
| permissionMode | No | Permission mode string | acceptEdits |
558+
| maxTurns | No | Number | 50 |
559+
| memory | No | user/project/local | user |
560+
| mcpServers | No | Object or server names | { "slack": {} } |
561+
| hooks | No | Hook event config | { PreToolUse: [...] } |
504562

505563
> **Note:** Agents use `tools` to restrict tool access. Skills use `allowed-tools` for the same purpose. The field names differ between component types.
506564
@@ -524,12 +582,36 @@ Ensure system prompt is complete:
524582
- ❌ Write vague system prompts
525583
- ❌ Skip testing
526584

585+
## Execution Modes
586+
587+
Agents can run in foreground (blocking) or background (concurrent) mode:
588+
589+
- **Foreground** (default): Blocks the main conversation until the agent completes
590+
- **Background**: Runs concurrently; permissions must be pre-approved at spawn time since the user can't be prompted
591+
592+
Background agents that need an unapproved permission will fail. Plan tool restrictions accordingly.
593+
594+
**Resuming agents:** Each Task invocation creates a fresh agent. To continue with full prior context, ask Claude to "resume that agent" — it will restore the previous transcript.
595+
596+
**Restricting spawnable agents:** Use `Task(agent_type1, agent_type2)` syntax in settings.json allow rules to control which agent types can be spawned. Omitting `Task` entirely prevents subagent spawning.
597+
598+
**Built-in agent types:** Explore (read-only, Haiku), Plan (read-only research), general-purpose (all tools), Bash (terminal commands), statusline-setup (Haiku), Claude Code Guide (Haiku).
599+
600+
## Agent Teams (Experimental)
601+
602+
Agent teams enable multi-agent coordination where a team lead spawns and manages multiple independent Claude Code sessions as teammates. Requires `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`.
603+
604+
Teams provide shared task lists, inter-agent messaging, and parallel execution. Use `permissionMode: delegate` to restrict a lead to coordination-only tools.
605+
606+
This is an advanced feature — see the [official agent teams documentation](https://code.claude.com/docs/en/agent-teams) for details.
607+
527608
## Additional Resources
528609

529610
### Reference Files
530611

531612
For detailed guidance, consult:
532613

614+
- **`references/advanced-agent-fields.md`** - Detailed docs for maxTurns, memory, mcpServers, hooks, execution modes, and agent teams
533615
- **`references/system-prompt-design.md`** - Four system prompt patterns (Analysis, Generation, Validation, Orchestration) with complete templates and common pitfalls
534616
- **`references/triggering-examples.md`** - Example block anatomy, four example types, template library, and debugging guide
535617
- **`references/agent-creation-system-prompt.md`** - The exact prompt used by Claude Code's agent generation feature with usage patterns
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
# Advanced Agent Fields
2+
3+
This reference covers agent frontmatter fields beyond the core fields (name, description, model, color, tools, disallowedTools, skills, permissionMode). These enable turn limits, persistent memory, scoped MCP access, lifecycle hooks, and advanced execution patterns.
4+
5+
## maxTurns
6+
7+
Limit the maximum number of agentic turns (API round-trips) before the agent stops.
8+
9+
```yaml
10+
maxTurns: 50
11+
```
12+
13+
### Choosing Values
14+
15+
| Task Type | Suggested Range | Rationale |
16+
| ----------------------------- | --------------- | ------------------------------- |
17+
| Quick checks, linting | 5-15 | Focused, fast completion |
18+
| Code review, analysis | 20-40 | Needs to read multiple files |
19+
| Complex refactoring, creation | 50-100 | Multi-file changes with testing |
20+
21+
If omitted, the agent runs until it completes or is interrupted. Set `maxTurns` to prevent runaway agents from consuming excessive resources, especially for background agents where there's no user to interrupt.
22+
23+
## memory
24+
25+
Enable persistent memory that survives across sessions.
26+
27+
```yaml
28+
memory: user
29+
```
30+
31+
### Scopes
32+
33+
| Scope | Directory | Use When |
34+
| --------- | ------------------------------------------ | -------------------------------- |
35+
| `user` | `~/.claude/agent-memory/<agent-name>/` | Personal preferences, defaults |
36+
| `project` | `.claude/agent-memory/<agent-name>/` | Codebase-specific knowledge |
37+
| `local` | `.claude/agent-memory-local/<agent-name>/` | Gitignored project-specific data |
38+
39+
### How It Works
40+
41+
When `memory` is set:
42+
43+
1. System prompt includes instructions for reading/writing the memory directory
44+
2. First 200 lines of `MEMORY.md` are auto-injected into the agent's system prompt
45+
3. Read, Write, and Edit tools are automatically enabled (even if not in `tools` list)
46+
4. Agent should curate `MEMORY.md` if it exceeds 200 lines
47+
48+
### Best Practices
49+
50+
- Use `user` scope as the default for most agents
51+
- Use `project` or `local` for codebase-specific learning
52+
- Include memory management instructions in the agent's system prompt (e.g., "After completing a task, update your MEMORY.md with key learnings")
53+
54+
## mcpServers
55+
56+
Scope MCP servers to the agent, controlling which external services it can access.
57+
58+
### Reference by Name
59+
60+
Reference an already-configured MCP server:
61+
62+
```yaml
63+
mcpServers:
64+
slack:
65+
```
66+
67+
The agent inherits the full configuration of the named server from the project/user MCP settings.
68+
69+
### Inline Configuration
70+
71+
Provide full server config scoped to the agent:
72+
73+
```yaml
74+
mcpServers:
75+
custom-api:
76+
command: "${CLAUDE_PLUGIN_ROOT}/servers/api-server"
77+
args: ["--config", "${CLAUDE_PLUGIN_ROOT}/config.json"]
78+
env:
79+
API_KEY: "${API_KEY}"
80+
```
81+
82+
### Use Cases
83+
84+
- Restrict a code review agent to only read-only MCP tools
85+
- Give a deployment agent access to CI/CD servers but not database servers
86+
- Provide agent-specific server configuration
87+
88+
## hooks
89+
90+
Define lifecycle hooks scoped to the agent. These hooks activate when the agent starts and deactivate when it finishes.
91+
92+
### Format
93+
94+
```yaml
95+
hooks:
96+
PreToolUse:
97+
- matcher: Write
98+
hooks:
99+
- type: command
100+
command: "${CLAUDE_PLUGIN_ROOT}/scripts/validate-write.sh"
101+
timeout: 10
102+
Stop:
103+
- hooks:
104+
- type: prompt
105+
prompt: "Verify all tasks are complete before stopping."
106+
```
107+
108+
### Supported Events
109+
110+
All hook events are supported in agent frontmatter. Key behavior difference:
111+
112+
- **`Stop`** hooks are automatically converted to **`SubagentStop`** at runtime, since agents are subprocesses
113+
- Hooks only run while the agent is active and are cleaned up when the agent finishes
114+
115+
### Comparison with hooks.json
116+
117+
| Aspect | `hooks.json` | Agent frontmatter `hooks` |
118+
| -------- | ------------------------------------------ | ----------------------------------------------- |
119+
| Scope | Global (always active when plugin enabled) | Agent-specific (active only during agent run) |
120+
| Events | All hook events | All events (Stop auto-converts to SubagentStop) |
121+
| Location | `hooks/hooks.json` file | YAML frontmatter in agent .md file |
122+
| Use case | Plugin-wide validation | Agent-specific safety checks |
123+
124+
## Execution Modes
125+
126+
### Background vs Foreground
127+
128+
- **Foreground** (default): Blocks the main conversation until the agent completes. User can interact if the agent requests permission.
129+
- **Background**: Runs concurrently with the main conversation. All permissions must be pre-approved at spawn time since the user cannot be prompted.
130+
131+
Background agents that encounter an unapproved permission request will fail. Design tool restrictions (`tools`, `permissionMode`) accordingly when agents may run in background.
132+
133+
### Resuming Agents
134+
135+
Each Task tool invocation creates a new agent instance with a fresh context. To continue with the full prior context preserved, ask Claude to "resume that agent" or "continue that subagent" — it will restore the previous transcript.
136+
137+
Agent transcripts are stored at `~/.claude/projects/{project}/{sessionId}/subagents/agent-{agentId}.jsonl`.
138+
139+
### Restricting Spawnable Agent Types
140+
141+
Use `Task(agent_type1, agent_type2)` syntax in settings.json allow rules to control which agent types can be spawned:
142+
143+
```json
144+
{
145+
"permissions": {
146+
"allow": ["Task(code-reviewer, test-runner)"]
147+
}
148+
}
149+
```
150+
151+
- `Task(type1, type2)` — only these agent types can be spawned
152+
- `Task` (no parentheses) — allow any subagent
153+
- Omitting `Task` entirely — cannot spawn any subagents
154+
155+
## Built-in Agent Types
156+
157+
Claude Code includes several built-in agent types that can be referenced in the `agent` field of skills or used as targets for `Task()` restrictions:
158+
159+
| Agent Type | Model | Tools | Purpose |
160+
| ------------------- | ------- | --------- | ----------------------------------- |
161+
| `Explore` | Haiku | Read-only | Fast codebase exploration/search |
162+
| `Plan` | Inherit | Read-only | Codebase research during planning |
163+
| `general-purpose` | Inherit | All | Complex multi-step tasks |
164+
| `Bash` | Inherit | Bash | Terminal commands in isolation |
165+
| `statusline-setup` | Haiku | Read/Edit | Status line configuration |
166+
| `Claude Code Guide` | Haiku | Read-only | Documentation and feature questions |
167+
168+
## Agent Teams (Experimental)
169+
170+
Agent teams enable multi-agent coordination where a team lead spawns and manages multiple independent Claude Code sessions as teammates. This is an experimental feature requiring `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`.
171+
172+
### Key Concepts
173+
174+
- **Team lead**: Main session that creates the team, spawns teammates, and coordinates work
175+
- **Teammates**: Independent Claude Code instances with their own context windows
176+
- **Shared task list**: Coordinated work items that teammates claim and complete
177+
- **Messaging**: Direct messages and broadcasts between team members
178+
179+
### Delegate Mode
180+
181+
Use `permissionMode: delegate` to restrict a team lead to coordination-only tools (spawn, message, shut down teammates, manage tasks). This prevents the lead from implementing tasks itself.
182+
183+
### Quality Gates
184+
185+
Use `TeammateIdle` and `TaskCompleted` hooks to enforce quality standards in team workflows.
186+
187+
For complete documentation, see the [official agent teams guide](https://code.claude.com/docs/en/agent-teams).

plugins/plugin-dev/skills/hook-development/SKILL.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: hook-development
3-
description: This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", "scoped hooks", "frontmatter hooks", "hook in skill", "hook in agent", "agent hook type", or mentions hook events (PreToolUse, PermissionRequest, PostToolUse, PostToolUseFailure, Stop, SubagentStop, SubagentStart, Setup, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
3+
description: This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", "scoped hooks", "frontmatter hooks", "hook in skill", "hook in agent", "agent hook type", "async hooks", "once handler", "statusMessage", "hook decision control", "TeammateIdle hook", "TaskCompleted hook", or mentions hook events (PreToolUse, PermissionRequest, PostToolUse, PostToolUseFailure, Stop, SubagentStop, SubagentStart, Setup, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification, TeammateIdle, TaskCompleted). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
44
---
55

66
# Hook Development for Claude Code Plugins
@@ -772,6 +772,17 @@ echo "$output" | jq .
772772
| SessionEnd | Session ends | Cleanup, logging |
773773
| PreCompact | Before compact | Preserve context |
774774
| Notification | User notified | Logging, reactions |
775+
| TeammateIdle | Teammate goes idle | Quality gates in teams |
776+
| TaskCompleted | Task marked done | Completion verification |
777+
778+
### Handler Configuration Fields
779+
780+
Beyond `type`, `timeout`, and `matcher`, hook handlers support:
781+
782+
- **`once`** (boolean): Run only once per session, then auto-removed. Useful for one-time initialization in scoped hooks.
783+
- **`statusMessage`** (string): Display text shown in the UI while the hook runs.
784+
785+
See `references/advanced.md` for detailed decision control output schemas and event-specific matchers.
775786

776787
### Best Practices
777788

0 commit comments

Comments
 (0)