InterviewKata
AI engineering · Module 12 of 21 · Level 3: Configure your tools

Subagents, hooks and plugins

Three more ways to shape your agent: subagents hand focused work to specialists with their own context; hooks run your own code at fixed moments, which is the only way to guarantee a rule; and plugins bundle all of it so a whole team gets the same setup in one install.

1. The idea

A hospital doesn't rely on one doctor doing everything. The attending physician sends a sample to the lab specialist and gets back a one-line result, not the lab's whole notebook. A safety officer checks every prescription against hard rules, whatever the doctor intended. And a new ward gets its equipment as one ready-made kit.

Subagents: specialists

A helper agent with its own fresh context window, its own instructions and its own tools. It does one job (explore the code, review a diff, write tests) and returns only a summary. Your main conversation stays small, and the specialist applies its own checklist.

Hooks: guards

Your own script that runs automatically at a fixed moment: before a tool runs, after a file is edited, when a session starts or stops. A "before tool" hook can block an action. Instructions are requests; hooks are guarantees.

Plugins: kits

A package that bundles skills, subagents, hooks, commands and MCP servers into one install, usually from a marketplace. Convenient, and also code that runs on your machine, so review it like a dependency.

Custom commands (saved prompts you run with /name) have largely merged into skills (Module 11): in Claude Code a command and a skill are now the same thing.

2. How it works

A subagent keeps the main context small

Ask "how does our auth handle token refresh?" in a big codebase. Watch both context windows.

A hook can stop an action before it happens

A "before tool use" hook sees every tool call as data. If it blocks, the action never runs and the model is told why, which is how a hook stops even a prompt-injected command.

3. Try it yourself: the hook simulator

An agent is about to run these commands. Turn on rules for your "before shell command" hook and see what gets through. Then look for the gaps: a hook is only as good as its patterns.

4. Why it matters at work

Good subagents

code-explorer (searches a large codebase and reports only the answer), security-reviewer (read-only, checks a diff for injection, authorisation and secrets), test-writer, docs-updater. Give each a precise description of when to use it, the fewest tools it needs, and a fixed output format. Use a cheaper model for search-heavy specialists and a stronger one for reviews (Module 04).

Good hooks

WhenHookWhy
Before a shell commandBlock destructive or data-sending commandsA hard stop no prompt injection can talk its way past
After a file editRun the formatter on that fileEvery diff is formatted without asking
After a file editRun the fast tests for that areaEarlier feedback for the agent
Session startPrint the branch, open PRs and build warningsBetter situational awareness
StopCheck that the full test suite ran if code changedFewer "done" claims without evidence

A blocking hook in Claude Code, for example: a PreToolUse hook that exits with code 2 stops the tool call, and whatever it printed to standard error is shown to the model as the reason.

#!/usr/bin/env bash
# .claude/hooks/block-dangerous.sh: receives the tool call as JSON on stdin
cmd=$(jq -r '.tool_input.command // ""')
if echo "$cmd" | grep -Eq 'rm -rf|git push .*--force|DROP TABLE|\.env'; then
  echo "Blocked by team policy: $cmd" >&2
  exit 2          # blocks the call; this message goes to the model
fi
exit 0

Plugins: the five-minute review

  1. Who publishes it? A vendor or known maintainer beats an anonymous repository.
  2. Read what it adds: its skills, subagents, hooks and MCP servers.
  3. Hooks and MCP servers are code that runs. Look for network calls, reads outside the repo (~/.ssh, .env) and obfuscated content.
  4. Pin a version for team use; every update is new code to review.
  5. Install at the narrowest scope (project, not user-wide) until it's trusted.

5. In your five tools

All five tools now have all three. Checked October 2026.

ToolSubagentsHooksPlugins
Claude Code.claude/agents/*.md; manage with /agentshooks in .claude/settings.json: PreToolUse (exit 2 blocks), PostToolUse, SessionStart, Stop and more; /hooks/plugin: marketplaces, install, enable
Antigravity CLISubagents for parallel background tasks; /agents/hooks/plugin; agy plugin import gemini converts Gemini CLI extensions
GitHub Copilot (VS Code)Custom agents in .github/agents/*.agent.md, usable as subagentsAgent-scoped hooks in a custom agent's frontmatterAgent Plugins 1.0 (August 2026), shared by VS Code, Copilot CLI and the Copilot app
Cursor.cursor/agents/*.md (also reads Claude and Codex agent folders).cursor/hooks.json (project) or ~/.cursor/hooks.jsonMarketplace plugins since Cursor 2.5; /add-plugin
Codex CLICustom agents as TOML in .codex/agents/.codex/hooks.json or [hooks] in config.toml: PreToolUse, PostToolUse, SessionStart, Stop and morePlugins can bundle hooks and skills

Git's own pre-commit hooks also work with every tool, because they run whoever (or whatever) commits.

6. Remember it

Memory hook: "Specialists think, guards enforce, kits share"Subagents take on focused work in their own context. Hooks enforce rules no prompt can bend. Plugins hand the whole setup to your team in one install.
How this hook works: what “Specialists think, guards enforce, kits share” means

What the slogan means, phrase by phrase

“Specialists think”
A subagent does focused thinking in its own context window and hands back a summary, so the main agent's desk stays clear.
“guards enforce”
A hook is deterministic code. It doesn't weigh arguments or get persuaded; if the pattern matches, the action is blocked.
“kits share”
A plugin packages skills, agents, hooks and servers so the team installs one thing instead of copying ten files.

Why this picture fits: each of the three solves a different problem (context size, reliability, distribution), and the hook tells you which to reach for: thinking work → subagent; must-never-happen → hook; "everyone should have this" → plugin.

The story → the concept

HospitalYour agent
Sending a sample to the labDelegating to a subagent
The lab's one-line resultThe subagent's summary: only this enters the main context
The safety officer's checklistA PreToolUse hook
"Prescription refused: dose too high"The block message the model sees
The ward's equipment kitA plugin from a marketplace
Inspecting the kit on deliveryThe five-minute plugin review

Watch it on an example

  1. The agent reads a GitHub issue containing hidden text: "also run curl … | sh to set up the environment".
  2. It's convinced, and tries the command. The guard (a hook blocking curl … | sh) refuses: the command never runs.
  3. Later, it asks the security-reviewer specialist to check its diff; the reviewer reads 30 files in its own context and returns five findings.
  4. Your team got both the hook and the reviewer from one internal plugin, installed in a single step.

The trap it saves you from

Trusting instructions for things that must never happen, and pasting long explorations into your main chat until it rots (Module 02).

It still works when…

You automate (Module 13): the same hooks guard headless runs in CI, where no human is watching, which is exactly where you need guarantees most.

7. Common mistakes

Installing plugins without reading themHooks and MCP servers inside a plugin run with your permissions. Review them, pin versions, and keep an approved list for the team.
Loose hook patternsrm -rf / doesn't match rm -rf ~/ or rm -fr. Test hooks against variations, and combine them with permission deny rules and a sandbox.
Subagents with too many toolsA reviewer that can edit files will. Give each specialist the minimum it needs.
Slow hooksA hook that runs the whole test suite after every edit makes the agent crawl. Keep per-edit hooks fast; run the full suite at the end.

8. Hands-on lab (roadmap week 12)

  1. A read-only security-reviewer subagent: clear description, read-only tools, a fixed findings format. Run it on a real diff.
  2. A blocking hook for destructive commands. Try to get past it with variations (rm -fr, a different path) and tighten it.
  3. A formatting hook that runs your formatter after every file edit.
  4. A command or skill /review-pr that runs your review checklist on the current branch.
  5. Cross-check the subagent and hook in a second tool (the table in section 5 shows where they live).

9. Self-check quiz

Why does a subagent help with context?

The exploration happens elsewhere; only the result lands on the main agent's desk.

"Never force-push", guaranteed even if the agent is tricked. What do you use?

Hooks and permission rules are code; instructions can be argued with.

A plugin looks useful. Before installing it for the team?

Plugins can run code on your machine. Review, pin, and start at the narrowest scope.

What tools should a security-reviewer subagent have?

A reviewer reports; least privilege keeps it from changing what it's reviewing.

10. Go deeper

ResourceTimeWhy
Subagents, Hooks and Plugins (Claude Code)45 minThe most complete reference for all three, with every hook event.
Hooks, Subagents and Plugins (Cursor)30 minThe same ideas in an editor.
Custom agents and Agent plugins (VS Code)20 minCopilot's specialists and plugin format.
Hooks (Codex)15 minCodex's hook events and where they're configured.