# Hooks and Mods: How Claude Code Automates, Extends, and Governs Its Behavior

- Anno: 2026
- Tipo: tutorial
- Lingua: en
- Pagine: 3
- PDF: https://www.cryptohelvetia.com/api/pdf/hooks-and-mods-how-claude-code-automates-extends-and-governs-its-behavior
- Pagina: https://www.cryptohelvetia.com/ch-intelligence/pdf/2026/hooks-and-mods-how-claude-code-automates-extends-and-governs-its-behavior
- Fonte: CH Intelligence, archivio PDF di CryptoHelvetia

> The document explains how hooks attach actions to defined runtime events so that certain behaviors execute consistently without waiting for the language model to choose them. It also describes how mods, plugins built from JavaScript or TypeScript functions, extend Claude Code with interactive interfaces, middleware-style handlers, and custom commands.

How Claude Code automates, extends, and governs its behavior. An updated reading without code snippets.

### When Claude meets a rule

A coding agent chooses its tools and next steps as it works. Project instructions in CLAUDE.md or AGENTS.md influence those choices; an event hook attaches an action to a defined point in the runtime. Anthropic's central distinction is that hooks make certain actions happen without waiting for the language model to choose them. The event trigger is predictable, although any judgment delegated to a model remains probabilistic. This makes hooks especially useful when an instruction must be executed consistently. [1] [2]

Consider a formatter that runs after Claude edits a file, a check that intercepts writes to protected paths, or a notification when Claude asks for permission. A hook can also audit changes to settings, inject context when a session starts, and check whether a task meets a completion condition before Claude stops. Such controls reduce the need to restate the same operational requests in every conversation. Their effectiveness still depends on the quality of the command or policy they execute. [1]

An event names the point at which the handler fires. PreToolUse can inspect, block, or change a proposed tool call; PostToolUse observes a completed one; PermissionRequest concerns an approval prompt; SessionStart accompanies a new or resumed session; and Stop runs when the agent is ready to finish its turn. The current reference also documents InstructionsLoaded, PostToolBatch, PermissionDenied, task lifecycle events, file and directory changes, model switches, and compaction. Matchers and conditional filters narrow the relevant calls or circumstances. [2]

Hooks may live in a user's settings, a repository's shared settings, local project preferences, or components such as skills and subagents. Anthropic documents several handler types: shell commands, HTTP requests, MCP tool calls, prompt evaluations, and agent-based checks. Structured input and output let a handler return decisions or context. Some command hooks may run asynchronously, which suits background validation but requires care when a result must arrive before an operation proceeds. These are separate choices about scope, execution, and enforcement. [1]

[2]

Predictability applies to the event, not automatically to the surrounding system. Several hooks can respond to one event; a broad matcher may catch unintended calls; a failing handler may have different consequences according to its event and configuration. Permission modes, user consent, and organizational policy therefore need to be considered alongside hooks. For a reliable setup, begin with a small control whose success or failure can be tested, then inspect its behavior using Claude Code's hook browser and logs. [1] [2]

### What Mods bring to Claude Code

Mods extend the same event-driven idea into Claude Code itself. Anthropic defines a mod as a plugin that changes how Claude Code looks and behaves. A mod contains JavaScript or TypeScript functions registered through a hooks module, which the application runs inside its own process. This distinguishes function hooks from settings hooks, which execute outside the application through commands, services, or prompts. A mod can therefore create an interactive feature instead of merely automating a response to an event. [3] [6]

Its event handlers act like middleware. A handler may observe an event and pass it onward, rewrite information before the next handler receives it, or answer the event itself. The order of handlers matters when one changes the input that others would inspect. Mods can intercept tool calls, prompts, model requests, commands, and parts of a turn; related handlers can share in-memory state. This becomes useful for tracking a sequence of file edits, assembling a running activity display, or coordinating decisions across several steps. [4] [6]

The most visible difference is interface control. A mod may draw a pane beside the transcript, an information band above the prompt, buttons, forms, or custom views. It can alter how Claude Code presents tool usage, messages, and its activity indicator. Through the Mods API it can register commands that run without a new model turn, inspect session usage, use persistent stores, access files and processes, make network requests, call models, and exchange messages with accessible sessions. These powers are mediated by the runtime API and depend on the surface hosting the session. [3] [5] [6]

Anthropic's October examples make the idea tangible. Token Weather shows how full the context window has become. Blast Radius pauses selected risky shell commands and presents their likely effects before allowing a choice. Replay Theater lets a developer step through edits from the previous turn. They demonstrate monitoring, intervention, and review as three distinct design patterns. Blast Radius is explicitly a convenience safeguard rather than a comprehensive security barrier: command-text heuristics can miss actions hidden inside scripts, aliases, or substitutions. [7] [8]

Mods are enabled by default from Claude Code CLI 2.1.287 and the bundled Desktop Code runtime 2.1.286. They also work in the VS Code chat extension with the supported extension version, generally 2.1.299 or later; certain managed providers require newer builds. Event handlers can run in supported headless and cloud sessions even when custom visual elements cannot be displayed. These capabilities belong to the Claude Code runtime; similar behavior in Cursor, Codex, or another agent requires its own integration. [3] [6]

### Developers’ ideas and working methods

The strongest workflows assign each responsibility to the smallest suitable mechanism. Put durable working conventions in the project's instruction files. Use a settings hook for a formatter, a protected-path check, or a verifiable test. Use a mod when the feature needs shared state across events, an interactive display, a custom command, or deeper control over tool execution. Use an MCP server when Claude needs tools for an external service. All four mechanisms can coexist in the same plugin or project, while retaining different responsibilities. [1]

[3]

The Ralph approach provides a revealing case of iteration. Geoffrey Huntley originally described Ralph as a repeated shell loop driven by prompts, files, and test results. Anthropic's Ralph Loop plugin instead uses a Stop hook to resubmit a task within the current session. The two approaches differ in how they preserve conversational context, so they should be evaluated separately. Long-running loops benefit from explicit acceptance tests, a maximum number of iterations, and a reliable way to stop. Repeated model calls alone do not establish that a task is complete. [12] [13]

A further development is that Claude Code now includes its own built-in mods. Official examples include the interactive /diff view and the component that loads AGENTS.md as project instructions; managed deployments can also use a security-focused mod. The result is an extensibility architecture increasingly used by Claude Code's own features. For developers managing several repositories, this reinforces the value of keeping policy and project instructions in version-controlled files while making the runtime's actual behavior visible. [3] [11]

The practical workflow has also become clearer. Claude Code can create a mod from a plain-English description using its built-in plugin-authoring skill. A developer can inspect the generated files, validate a plugin to list its hooks and API calls, test its behavior, and reload the plugin during iteration. Anthropic warns that the Mods API evolves: the type declarations generated by the installed version are more authoritative for that installation than examples found online. As of 6 November 2026, the latest official release checked for this paper is v2.1.318, released on 4 November. [9] [10] [14]

Security merits particular attention. A mod executes with its user's permissions and may read secrets, change tool calls, launch processes, contact services, or spend model usage. Claude Code's Bash sandbox does not automatically isolate processes started by a mod. Review the author and source, use claude plugin validate, and favor narrow trials before wider deployment. Organizational policies can limit which mods load and what they may authorize; newer Claude Code releases also add stronger path-based restrictions on writing outside approved working directories. Such controls complement review and testing. [3] [11] [15]

#### DIRECT SOURCES AND FURTHER READING · CLICKABLE LINKS

| [1] Anthropic, Hooks guide | [2] Anthropic, Hooks reference |
| --- | --- |
| [3] Anthropic, Mods overview | [4] Anthropic, Mod event handling |
| [5] Anthropic, Mods API | [6] Anthropic, Mods reference |
| [7] Addy Osmani, Anthropic, Oct 2026 | [8] Anthropic, sample Mods repository |
| [9] Anthropic, Create a Mod | [10] Anthropic, Test a Mod |
| [11] Anthropic, Organization controls | [12] Geoffrey Huntley, Ralph, 2025 |
| [13] Anthropic, Ralph Loop plugin | [14] Anthropic, Claude Code v2.1.318 |

[15] Anthropic, Claude Code v2.1.314
