What this unit solvesThese four mechanisms transform Claude Code from “a conversational agent” into “an automated system that fits your workflow.” They are commonly misused: tasks that require guaranteed behavior are written as Skills and left for the model to remember; subtasks that should be isolated are jammed into the main context; configurations that should be packaged are copied by hand. This unit first gives you the selection criteria for “when to use which one,” then unpacks the format, placement, priority order, and security boundaries for each mechanism individually. Deep production details are left for Part IV — this unit establishes the selection overview.
Learning objectives
- Explain what problem each of Skill / Hook / Subagent / Plugin solves, and given a task, determine which one to reach for.
- Read and understand the main frontmatter fields of a
SKILL.mdand a subagent definition. - List the main Hook events and handler types, and describe one practical example of a deterministic gate.
- Safely install a plugin from the official and community marketplaces, and know what to scan before installing.
1. Decide first: selecting among the four mechanisms
The four mechanisms are not parallel substitutes — they answer different questions. Read the selection table first, then continue to the per-mechanism details:
Selection principle: Use Hook for “must happen,” Skill for “reusable process,” Subagent for “isolated context,” Plugin for “package and distribute.” They are orthogonal but composable — a single plugin can carry a skill, a hook, and a subagent at the same time.
Interactive selection tool
Answer a few questions below and get a mechanism recommendation:2. Skills: reusable processes
A Skill is a reusable process defined in aSKILL.md file (YAML frontmatter + Markdown body). Unlike CLAUDE.md, which is fully loaded at session start, Skills use progressive disclosure: only the description enters context when the session begins; the full SKILL.md body is loaded as a message only when the Skill is triggered [1]. This lets you install dozens of Skills without bloating the context window.
Main frontmatter fields (all optional; only description is strongly recommended) [1]:
A minimal SKILL.mdPlace it at
~/.claude/skills/tidy-refs/SKILL.md (personal) or .claude/skills/tidy-refs/SKILL.md (project). Claude only reads these instructions after the Skill is triggered.~/.claude/skills/ > project .claude/skills/ > plugin (plugin skills use the plugin-name:skill-name namespace and do not conflict with other layers) [1].
Dynamic context injection: SKILL.md can contain commands that execute before the Skill loads and whose output replaces the command inline — letting you inject live information (git status, date) into the process [1]. The syntax is a leading backtick-escaped command on its own line; multi-line blocks are also supported:
disableSkillShellExecution: true in settings.json.
Relationship with legacy commands: .claude/commands/<name>.md is still supported and generates the same /name slash command. When a Skill and a command share the same name, the Skill wins [1]. For the trade-offs between Commands and Skills see 04-3 and 04-4.
3. Hooks: deterministic event-driven gates
A Hook is a custom command attached to a lifecycle event. The fundamental difference between Hooks and Skills / CLAUDE.md is enforceability: CLAUDE.md says “please follow this,” and a Hook says “I will make sure this happens.” Use Hooks for anything that must be guaranteed; do not write it into instructions and hope for model compliance. Events: Claude Code had approximately 30 hook events as of 2026-06 [2]. The ones you will reach for first:
The full event list (including
PermissionRequest, SubagentStart / SubagentStop, PreCompact, and others) is in the official docs and 04-6.
Handler types: command (run a shell command or script), http (POST event JSON to a URL), mcp_tool (call an MCP tool), prompt (evaluate with an LLM), agent (agentic verifier with tools) [2].
Protocol: a Hook receives a JSON payload via stdin (containing session_id, tool_name, tool_input, and more). Exit code 2 is a blocking error (stderr is shown to Claude and the action is blocked); exit 0 triggers parsing of the stdout JSON for a decision [2]. To block a specific tool call in PreToolUse, return:
A PostToolUse hook that auto-formats on saveAttach a PostToolUse hook in The hook script reads the modified file path from the stdin JSON (
settings.json pointing to a script, with matcher Edit|Write:tool_input.file_path) and runs the formatter against it. Note that Claude Code does not provide a $CLAUDE_FILE_PATHS environment variable for this (as of 2026-05) [2] — the path must come from stdin JSON, not from the environment.4. Subagents: child agents with isolated context
A Subagent is a child agent defined in.claude/agents/*.md (YAML frontmatter + system prompt) and managed via /agents. Its core value is context isolation: dispatch an exploration-heavy or read-heavy subtask to a subagent with a clean context window, and the main agent receives only the final conclusion — saving main-thread tokens and preventing irrelevant content from diluting the main context (connects to 01-4) [3].
Main frontmatter fields (only name and description are required) [3]:
Placement and priority (highest to lowest): managed policy >
--agents CLI flag > project .claude/agents/ > user ~/.claude/agents/ > plugin [3].
Built-in subagents: Explore (Haiku, read-only, skips CLAUDE.md, for search and analysis), Plan (read-only planning), general-purpose (full tools, complex multi-step tasks) [3]. One important constraint: subagents cannot generate subagents (no nested delegation).
A read-only review subagentGiving it only read-only tools is least-privilege in practice. The main agent delegates and receives only the issue list — it never has the review process’s extensive file reads diluting its own context. For full subagent production details see 04-5.
5. Plugins and marketplaces: packaging and distribution
A Plugin packages skills, agents, hooks, and MCP servers into a single installable unit, letting a team install a consistent configuration in one step. Marketplaces and installation (as of 2026-05) [4]:- Official marketplace
claude-plugins-officialis available automatically on startup:/plugin install <name>@claude-plugins-official, browsable atclaude.com/plugins. - Community marketplace
anthropics/claude-plugins-community: first run/plugin marketplace add anthropics/claude-plugins-community, then/plugin install <name>@claude-community. - Arbitrary marketplace:
/plugin marketplace add owner/repo(GitHub), a Git URL, or a local path (the repo must contain.claude-plugin/marketplace.json).
.claude-plugin/plugin.json at the repo root is the manifest (the only file in that directory). Components go in the outer skills/, agents/, commands/, hooks/hooks.json, .mcp.json, .lsp.json, monitors/monitors.json, and bin/, plus a plugin-level settings.json (only agent and subagentStatusLine keys take effect) [4].
The official documentation explicitly warns: do not put commands/, agents/, skills/, or hooks/ inside the .claude-plugin/ directory — only plugin.json goes there.
Full directory layout:
my-plugin/
.claude-plugin/
plugin.json · the only file that belongs here
skills/
agents/
hooks/
commands/
.mcp.json
settings.json · only agent / subagentStatusLine keys take effect
Tool comparison
Mapping the four mechanisms across tools reveals uneven coverage (as of 2026-05; exact mechanisms are subject to each vendor’s current documentation; see 02-6 for deeper comparison):The comparison table gives coordinates onlyNaming and maturity of mechanisms varies significantly across vendors; precise details are subject to each vendor’s current official documentation. Claude Code provides approximately 30 hook events and built-in subagent context isolation [2, 3]; most other tools lean toward “instructions / rules” layers without an equivalent deterministic event mechanism. For deeper comparison see 02-6.
Hands-on exercises
1
Write a minimal Skill
Following the example in Section 2, create a
SKILL.md under ~/.claude/skills/ (for example, “clean up references in the lab’s citation format”) with only a description and the procedure steps. Trigger it and confirm that Claude actually follows the steps.2
Add a PostToolUse Hook to run lint / formatting after every save
Following the example in Section 3, attach a PostToolUse hook in
settings.json with an Edit|Write matcher, pointing to a script that reads tool_input.file_path from the stdin JSON. Edit a file and confirm the hook actually fires.3
Build a read-only review subagent
Following the example in Section 4, create a subagent in
.claude/agents/ that is given only Read / Grep tools. Use /agents to confirm it loads, then dispatch it to review some content and receive only the conclusion.Common pitfalls
Self-check
The bar for passing this unit
- Given a recurring task (for example, “run tests before every commit and block failing commits”), can you determine whether to use a Skill, a Hook, or a Subagent? What is your reasoning?
- What is the difference in effect between
disable-model-invocation: trueanduser-invocable: falseon a Skill? - If you want Claude Code to always run formatting after every save, which hook event do you use? Why not put this in CLAUDE.md?
- What tool permissions should a review-only subagent have? What principle does giving it write tools violate?
- Before installing a plugin from the community marketplace, what categories of risk signals do you scan for?
Sources and further reading
Factual claims are grounded in official documentation; fast-changing items are annotated as of 2026-05.-
[1] Anthropic, “Skills,” Claude Code Docs. (
SKILL.mdfrontmatter fields; progressive disclosure — loads on demand; placement priority: enterprise > personal > project > plugin;!`command`dynamic injection anddisableSkillShellExecution; Skill wins over a same-named.claude/commands/entry) https://code.claude.com/docs/en/skills (as of 2026-05) -
[2] Anthropic, “Hooks,” Claude Code Docs. (~30 hook events; handler types: command / http / mcp_tool / prompt / agent; stdin JSON protocol, exit code 2 blocks, exit 0 + JSON decision;
PreToolUsepermissionDecision: deny; matcher syntax; no$CLAUDE_FILE_PATHSenvironment variable — path comes from stdin JSONtool_input.file_path) https://code.claude.com/docs/en/hooks (as of 2026-05) -
[3] Anthropic, “Subagents,” Claude Code Docs. (
.claude/agents/*.mdfrontmatter; placement priority: managed >--agents> project > user > plugin; built-in Explore / Plan / general-purpose; context isolation returns only the conclusion; subagents cannot be nested;isolation: worktree) https://code.claude.com/docs/en/sub-agents (as of 2026-05) -
[4] Anthropic, “Plugins,” Claude Code Docs. (official marketplace
claude-plugins-officialavailable automatically; communityanthropics/claude-plugins-community;/plugin install,/plugin marketplace add; plugin structure:.claude-plugin/plugin.json+ outerskills/agents/hooks/hooks.json.mcp.json; onlyplugin.jsongoes in.claude-plugin/) https://code.claude.com/docs/en/plugins (as of 2026-05)