// module 07 · AI agents on developer machines
Enforced hooks and MCP server control
Permission rules match command text; a hook runs your own code on every tool call and can say no. Deployed from managed settings, a `PreToolUse` hook keeps working when the developer sets `disableAllHooks`, and `allowManagedHooksOnly` stops the developer's own hooks from running at all. We ship a small hook that blocks force pushes, `--no-verify`, workflow edits and `.env` reads, and prove it in a container. Then we close the second supply chain on the laptop: which MCP servers and plugin marketplaces Claude Code will load, tested with `claude mcp add` and no model calls.
Learning Objectives
- Write a `PreToolUse` hook that blocks a tool call with exit code 2 and a reason the agent sees
- Deploy the hook from managed settings and show that `disableAllHooks` in user settings doesn't turn it off
- Use `allowManagedHooksOnly` to stop user, project and plugin hooks from running
- Restrict MCP servers with `allowedMcpServers`, `deniedMcpServers` and `allowManagedMcpServersOnly`, matching by URL and exact command
- Restrict plugin sources with `strictKnownMarketplaces`, `blockedMarketplaces` and `disableSideloadFlags`
This lesson is for enrolled learners
Log in, then enroll to read the full lesson, run its lab and take the quiz.
