Skip to content

Lesson 14 ยท Claude Code and Agents

Claude Code Skills, Hooks, MCP and Subagents

Extend Claude Code with skills, run guaranteed checks with hooks, connect tools through MCP and delegate side work to subagents, with safety notes for each.

Once the basics work, you can shape Claude Code around your team. Four extension points solve four different problems. Picking the right one matters more than using all of them.

Which extension do you need?

Skill Reusable know-how
Hook Runs every time
MCP Outside tools
Subagent Separate context
1 / 2

Skills

A skill is a folder with a SKILL.md file: YAML front matter followed by instructions. Claude loads it when relevant, or you call it with /skill-name. Unlike CLAUDE.md, the body loads only when used. Project skills live in .claude/skills/<name>/, personal ones in ~/.claude/skills/<name>/. Older custom commands in .claude/commands/ still work.

MARKDOWN
---
name: release-notes
description: Draft release notes from recent commits. Use when asked for a changelog.
disable-model-invocation: true
---

Draft release notes for $ARGUMENTS.
1. Read the commits since the previous tag.
2. Group them as Added, Changed and Fixed.
3. Don't mention changes you cannot find in the commits.
4. Save nothing. Show me the draft.

disable-model-invocation: true means that only you can start it, which suits workflows with side effects. Be aware that a skill's allowed-tools field can pre-approve tools, and that skills can run commands. Read skills from other people before using them.

Hooks

An instruction asks Claude to do something. A hook is a command that Claude Code runs itself at a set point, so it does not depend on the model remembering. Events include PreToolUse (before a tool call, and able to block it), PostToolUse (after success), Notification and SessionStart. This settings fragment formats files after edits:

JSON
{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [{ "type": "command", "command": "./scripts/format.sh" }]
      }
    ]
  }
}

The script receives JSON on standard input, with fields such as tool_name and tool_input. For a PreToolUse hook, exit code 2 blocks the action, and the message written to standard error is the reason. On most events, other non-zero exit codes do not block, so a crashing guard may let the action through unless configured otherwise. Test your hooks, and use /hooks to see what is configured. Hooks run commands on your system, so review any hook that comes with a repository.

This stand-in shows the logic of a guard. A real hook script would read standard input and exit with the code.

Python Stand-in: logic of a PreToolUse guard hook

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the third case. The guard decides to block when it cannot understand the input. Also remember that a guard on edit tools does not stop a shell command from writing the same file.

MCP servers

The Model Context Protocol lets Claude Code use external tools and data, such as an issue tracker. You add servers from the command line. The names and URLs below are placeholders.

Terminal
# A remote server over HTTP
claude mcp add --transport http tracker https://mcp.example.com/mcp

# A local server started as a process; its command follows --
claude mcp add --transport stdio notes -- node ./notes-server.js

claude mcp list

The scope decides who gets a server: local (the default, only you in this project), project (shared through a .mcp.json file) or user (all your projects). Keep keys out of shared files; .mcp.json supports environment variables such as ${API_KEY}. Inside a session, /mcp shows status and handles sign-in.

Connect only to servers you trust. A server that fetches outside content can expose you to prompt injection. Interactive sessions ask you to approve project servers, but the documentation warns that claude -p runs load them without asking, so control this in automation.

Subagents

A subagent works in its own context window, with its own instructions and tool limits, then returns a result. Use one when a side task would flood your main conversation, such as searching a large codebase. Built-in ones include Explore, Plan and a general-purpose agent. Define your own as a Markdown file in .claude/agents/ or ~/.claude/agents/:

MARKDOWN
---
name: code-reviewer
description: Reviews changes for bugs and missing tests. Use after edits.
tools: Read, Grep, Glob
model: sonnet
---

You review code. Report concrete problems with file and line.
Say clearly when you found nothing. Do not edit files.

Only name and description are required. A subagent does not see your conversation history, so the task it receives must be complete. Its report can be wrong, and running many subagents uses more of your allowance or budget.

For custom applications, Anthropic also offers the Claude Agent SDK, which lets you build agents on the capabilities behind Claude Code.

Choosing in practice

Here are typical needs and a sensible first choice for each:

Need First choice Why
"Always remember our test command" CLAUDE.md Short fact needed in every session
"Follow our ten-step release checklist" Skill Long procedure, used now and then
"No edits to the generated folder" Permission deny rule or hook Must be enforced
"Format files after each edit" Hook Must happen every time
"Read tickets from our tracker" MCP server Needs an outside system
"Search the whole codebase for usages" Subagent Produces lots of output that you do not need to keep

Whatever you add, test it on purpose. Trigger the hook with an input that it should block. Ask a question that should activate the skill, and one that should not. Check what an MCP server can write as well as read. A control that you have never seen working is only a hope.

Commit shared configuration to version control and review changes to it like code. A change in a hook script, a server definition or a skill can change what runs on every teammate's computer.

Review third-party extensions

Plugins and shared configurations can bundle skills, hooks and servers together. Before you install one, find out who maintains it, read the scripts it runs and check which servers it contacts. Review it again after updates, because a later version can behave differently from the one that you checked.

Common mistake: adding many skills, servers and agents at once. Each adds context, cost or risk. Add one when you meet a real, repeated problem, then confirm that it helps.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. You want a formatter to run after every file edit by Claude's edit tools. What fits?

    Hooks run at fixed points and do not depend on the model remembering.
  2. 2. In a PreToolUse hook, which exit code blocks the action?

    Exit 2 blocks; exit 0 raises no objection.
  3. 3. Which MCP scope is shared with your team through .mcp.json?

    Project scope is stored in a file at the project root.
  4. 4. What is true of a subagent's context?

    It works separately and returns a result to the main session.

Summary

  • Skills hold reusable instructions that load when needed.
  • Hooks run commands reliably and can block actions.
  • MCP connects outside tools; trust and scope matter.
  • Subagents isolate side work, and their results still need checking.

Next: Your First Claude API Request

Your progress is saved in this browser. No account needed.