Hooks and MCP servers explained

11 min read text
Course contents (20 lessons)
  1. Meet Claude Code
  2. What Claude Code is and how it differs from a chat window
  3. Installing Claude Code and signing in
  4. Your first session: explore, ask, change
  5. Asking well and staying in control
  6. Asking for changes: context, goal, constraints and acceptance criteria
  7. Reading and approving edits
  8. Permission modes: how much freedom to give
  9. Project memory and slash commands
  10. CLAUDE.md: teaching the tool about your project
  11. Slash commands and custom commands
  12. Everyday coding workflows
  13. The plan-first workflow
  14. Understanding unfamiliar code
  15. Debugging with Claude Code
  16. Refactoring safely
  17. Writing tests with Claude Code
  18. Git, small changes, cost and security
  19. Git workflows: branches, commits and pull request descriptions
  20. Keeping changes small and reviewable
  21. Context and cost awareness
  22. Security habits: secrets, commands and untrusted input
  23. Extending the tool, teamwork and a final project
  24. Hooks and MCP servers explained
  25. Team practices for AI-assisted coding
  26. Final project: building a small app step by step

Two ways to extend the tool

Out of the box, Claude Code reads files, edits them and runs shell commands. Two features let you go beyond that. Hooks add your own rules and automation around what the tool does. MCP servers give it access to outside systems. Both are powerful, and both are best used sparingly. The exact configuration formats change between versions, so this lesson explains the ideas and leaves the syntax to the official documentation.

Hooks: your commands at fixed moments

A hook is a command that you define, which the tool runs automatically when a particular event happens during a session. Examples of events include: just before the tool runs a command, just after it edits a file, when it finishes a response, or when you submit a prompt. The key point is that hooks are run by the tool program itself, so they happen every time, whether or not the model remembers a rule.

That is the difference from CLAUDE.md. A note in CLAUDE.md is a request that the model usually follows. A hook is enforced by the program.

Good uses

  • Format after edit. Run your code formatter on every file the tool changes, so style never depends on a reminder.
  • Guard rails. Before a command runs, check it against a list of things you never want, such as touching a protected folder, and block it with a message.
  • Quick checks. Run a fast linter or type check after edits, and show the result to the tool so it can fix problems at once.
  • Notifications. Send yourself a desktop notice when a long task finishes or when the tool is waiting for you.
  • Logging. Record the commands that ran, for an audit trail.

How they are configured

Hooks live in the settings files, as a list of events and the commands to run for each. There is a project-level settings file you can share with the team, and a local one for yourself. There is also a menu command inside the tool for viewing hooks. Read the official hooks page before writing one, since the event names and the way the command receives information are defined there.

Cautions

  • A hook runs a real command with your permissions. Anyone who can edit the shared settings file can make it run code on your machine. Review changes to that file like code, especially in repositories you did not write.
  • Keep hooks fast. A slow hook runs on every edit and makes the whole session sluggish.
  • Test a hook by hand outside the tool first.
  • Do not put secrets in the hook's command text.

MCP servers: connecting outside tools

MCP stands for Model Context Protocol, an open standard for connecting AI tools to other systems. An MCP server is a small program that exposes a set of capabilities, such as "search the issue tracker", "read this database schema", "fetch a design file" or "query the monitoring system". When you connect one, the tool can call those capabilities as part of its work.

Think of it like a plug. Without it, the tool knows only your files and the shell. With a server for your issue tracker, you can say:

Read the issue about the failing export, find the code responsible, propose a fix and a test. Do not change anything until I approve the plan.

The tool can fetch the issue itself through the server, instead of you copying the text.

Setting one up

The tool has a command group for managing servers, and an in-session command to see which are connected. The command is claude mcp in the terminal. Servers can be local programs on your machine or remote services. The documentation lists the current options and how to share a server configuration with a team. Follow it for exact steps.

Choosing servers

QuestionWhy it matters
Who made the server?It runs code and sees your requests. Use trusted sources.
What can it do?Read-only access is much safer than write access.
What credentials does it use?Give it the least access possible, never admin keys.
What data flows through it?Anything it returns enters the conversation.

Security with both

Hooks and servers widen what the tool can reach. Apply the same rules as in the security lesson. Prefer read-only access. Treat data coming back from servers, for example an issue text written by a stranger, as untrusted input that may contain instructions meant to mislead the model. Keep permission prompts on for actions that change things in outside systems.

When not to bother

Most people do not need either on day one. Use the tool for a few weeks. If you keep correcting the same formatting issue, add a hook. If you keep copying text from the same outside system, consider a server. Start with one, and keep it only if it saves time.

Do not confuse them with CLAUDE.md and commands

FeatureIt is for
CLAUDE.mdKnowledge the model should have in every session
Custom commandsReusable prompts you start on purpose
HooksAutomatic actions enforced by the program
MCP serversAccess to outside tools and data

The common mistake

The common mistake is installing several servers and hooks at once from examples found online, without understanding them. Each one adds risk and noise. Add one, understand it fully, and then decide about the next.

Try it yourself

Look at your last week of work and write down two repeated annoyances. For each, decide whether the right tool is a line in CLAUDE.md, a custom command, a hook or a server, using the table above. Then read the official page for the one you picked and set it up in a scratch project, not your main one.

This course is free to read. Create a free account to enrol, save your progress and pick up where you left off.

Sign up free I already have an account