Hooks and MCP servers explained
Course contents (20 lessons)
- Meet Claude Code
- What Claude Code is and how it differs from a chat window
- Installing Claude Code and signing in
- Your first session: explore, ask, change
- Asking well and staying in control
- Asking for changes: context, goal, constraints and acceptance criteria
- Reading and approving edits
- Permission modes: how much freedom to give
- Project memory and slash commands
- CLAUDE.md: teaching the tool about your project
- Slash commands and custom commands
- Everyday coding workflows
- The plan-first workflow
- Understanding unfamiliar code
- Debugging with Claude Code
- Refactoring safely
- Writing tests with Claude Code
- Git, small changes, cost and security
- Git workflows: branches, commits and pull request descriptions
- Keeping changes small and reviewable
- Context and cost awareness
- Security habits: secrets, commands and untrusted input
- Extending the tool, teamwork and a final project
- Hooks and MCP servers explained
- Team practices for AI-assisted coding
- 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
| Question | Why 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
| Feature | It is for |
|---|---|
| CLAUDE.md | Knowledge the model should have in every session |
| Custom commands | Reusable prompts you start on purpose |
| Hooks | Automatic actions enforced by the program |
| MCP servers | Access 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