Create a mod changedplugins/mods/create
Nearest release: v2.1.332, published 2 hours before upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 25 Nov 2026 00:56 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 25 Nov 2026 01:07 UTC.
Upstream edited
Recorded here
Lines+9added
Lines−3removed
From line
294
where the diff opens
First seen
1 Oct 2026
this site's first read of the page
Recorded edits17to this page, all time
#### Pass `$` to your functions
The whole hunk
from line 294, old and new numbered
/
from line 294
294294
295295Check the `hooks:` line for the events your module hooks, each with its filter in braces, and `calls:` for every mods API method it calls. If your module reads or sets environment variables, look for `env reads:` and `env writes:` lines too, and `state reads:` and `state writes:` if it uses [`$.state`](https://code.claude.com/docs/en/plugins/mods/interface#keep-state). You also see one line for each hook that can refuse an action, such as `gating hook without .catch: tool.call`, which says whether that hook has a [`.catch` handler](https://code.claude.com/docs/en/plugins/mods/events#handle-a-hook-that-fails).
296296
297If an event you meant to handle is missing from the `hooks:` lines, Claude Code won't call that hook either. The usual cause is a misspelled event name, which the command reports as an error such as `"tool.calls" is not an event`.
297If an event you meant to handle is missing from the `hooks:` lines, Claude Code won't call that hook either. Check each event name against [the types for your build](#get-the-types-for-your-build), because validation doesn't catch every typo. For example, `tool.calls` fails with `"tool.calls" is not an event`, but `tol.call` passes validation and the mod then doesn't load.
298298
299299Follow these rules so that static analysis can find every hook and call:
300300
301* Write each mods API call in full: `$`, the namespace, then the method, as in `$.store.get('notes')`. You can pass `$` to a function declared at the top level of the same file, and for a function of yours named `loadNotes`, the `calls:` line then reads `$.store.get (via loadNotes)`. Passing `$` to a method, a function defined inside the hook, or a function you import from another of your files fails validation. The `read` and `update` functions that [`$.state`](https://code.claude.com/docs/en/plugins/mods/interface#keep-state) uses are the imports that can take it. Don't assign `$` or one of its namespaces to a variable, destructure it, or index it with a computed name. `const ui = $.ui` fails with `$.ui is used as a value`.
301* Write each mods API call in full: `$`, the namespace, then the method, as in `$.store.get('notes')`. Don't assign `$` or one of its namespaces to a variable, destructure it, or index it with a computed name. `const ui = $.ui` fails with `$.ui is used as a value`.
302302* Write the event name in each `on` call as a string literal, such as `'tool.call'`. A variable, or a loop over a list of names, fails with `the event name passed to on() is not a string literal`.
303303* Inside `register`, don't declare a second variable or parameter named `on`. Validation fails with `"on" is declared again (shadowed)`.
304304* Import only from files inside the plugin directory, by relative path. The one bare import allowed is `claude-code`, for types and a few helpers.
from line 305
305305* Use `import` declarations at the top of the file, as in `import { name } from './file.js'`. A dynamic `import()` fails with `a dynamic import(); a hooks module imports its own files with an import declaration`.
306306* Write every file as an ES module, with `import` and not `require`. The [reference](https://code.claude.com/docs/en/plugins/mods/reference.md#files) lists the file extensions Claude Code loads.
307307
308#### Pass `$` to your functions
309
310You can pass `$` to a function declared at the top level of your hook's file, and to the `read` and `update` functions that [`$.state`](https://code.claude.com/docs/en/plugins/mods/interface#keep-state) uses. For a function named `loadNotes` that calls `$.store.get`, the `calls:` line reads `$.store.get (via loadNotes)`. Passing `$` to a method or to a function defined inside the hook fails validation.
311
312On Claude Code v2.1.299 or later, you can also pass `$` to a function you import from another of your files. Declare it there with the `function` keyword, as in `export function loadNotes($) { ... }`. An imported arrow function fails with `a name bound to a function expression, outside the hook's own file`.
313
308314### Test the mod
309315
310316You can write automated tests for a mod and run them from your shell with `claude plugin test`, with no session, sign-in, or network. A test fires the events your hooks handle and checks what the hooks did.
from line 364
358364
359365Before you do, check the plugin's `name`: `claude plugin validate` fails a name that [looks like one of Anthropic's own](https://code.claude.com/docs/en/plugins/manifest-reference.md#name), such as one that starts with `claude-`. The events and methods can change between releases, so your README is the place to say which Claude Code version you tested with.
360366
361Keep developing against the directory with `--plugin-dir`, not against an installed copy. Claude Code caches an installed plugin by version, so your edits don't reach the installed copy until you increment the version and install again.
367Keep developing against the directory with `--plugin-dir`, not against an [installed copy](https://code.claude.com/docs/en/plugins/loading.md#in-place-and-copied-plugins).
362368
363369## Next steps
364370
No line in this hunk matches that.