Create a mod changedplugins/mods/create
Nearest release: v2.1.333, published an hour after 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 30 Nov 2026 17:58 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 30 Nov 2026 18:07 UTC.
Upstream edited
Recorded here
Lines+8added
Lines−10removed
From line
134
where the diff opens
First seen
1 Oct 2026
this site's first read of the page
Recorded edits19to this page, all time
The whole hunk
from line 134, old and new numbered
/
from line 134
134134
135135**4. Write the code**
136136
137This file is the mod's code, called the hooks module. When the mod loads, Claude Code calls the `register` function the file exports and passes it a function named [`on`](https://code.claude.com/docs/en/plugins/mods/reference#the-hook-function). Each call to `on` registers an event handler, called a hook, for the event it names.
137This file is the mod's code, called the hooks module. When the mod loads, Claude Code calls the `register` function the file exports and passes it a function named [`on`](https://code.claude.com/docs/en/plugins/mods/events#how-a-hook-handles-an-event). Each call to `on` registers an event handler, called a hook, for the event it names.
138138
139139Save this as `first-mod/hooks/register.js`:
140140
from line 180
180180
181181The file keeps a count in `calls` and registers four hooks:
182182
183* **[`session.start`](https://code.claude.com/docs/en/plugins/mods/reference#session)** runs when the session starts, before your first prompt, and again each time the mod reloads. It adds the `/tally` command to Claude Code.
184* **[`tool.call`](https://code.claude.com/docs/en/plugins/mods/reference#tools)** runs each time Claude is about to use a tool. It adds one to `calls` and asks Claude Code to draw the interface again.
185* **[`command.run`](https://code.claude.com/docs/en/plugins/mods/reference#commands-and-configuration)** runs when you type `/tally`. It returns the text to print.
186* **[`ui.render`](https://code.claude.com/docs/en/plugins/mods/reference#interface)** runs each time Claude Code draws the spinner. It adds the count after the spinner's word.
183* **[`session.start`](https://code.claude.com/docs/en/plugins/mods/api#add-a-command-or-a-tool)** runs when the session starts, before your first prompt, and again each time the mod reloads. It adds the `/tally` command to Claude Code.
184* **[`tool.call`](https://code.claude.com/docs/en/plugins/mods/events#guard-or-change-a-tool-call)** runs each time Claude is about to use a tool. It adds one to `calls` and asks Claude Code to draw the interface again.
185* **[`command.run`](https://code.claude.com/docs/en/plugins/mods/api#add-a-command)** runs when you type `/tally`. It returns the text to print.
186* **[`ui.render`](https://code.claude.com/docs/en/plugins/mods/interface#pick-where-to-draw)** runs each time Claude Code draws the spinner. It adds the count after the spinner's word.
187187
188188[How the example mod works](#how-the-example-mod-works) explains the three arguments each hook takes and what each one returns.
189189
from line 229
229229
230230Each function you pass to `on` is a hook, which is an event handler. Claude Code passes every hook the same three arguments:
231231
232* **The mods API**, named `$`: every method a mod can call to reach outside itself, in [namespaces](https://code.claude.com/docs/en/plugins/mods/reference.md#mods-api-methods) such as `$.ui` and `$.command`
233* **The event**, named `e`: the [event's input](https://code.claude.com/docs/en/plugins/mods/reference.md#events) as plain data, such as a tool call's name and arguments
232* **The mods API**, named `$`: every method a mod can call to reach outside itself, in [namespaces](https://code.claude.com/docs/en/plugins/mods/api.md) such as `$.ui` and `$.command`
233* **The event**, named `e`: the [event's input](https://code.claude.com/docs/en/plugins/mods/events.md#how-a-hook-handles-an-event) as plain data, such as a tool call's name and arguments
234234* **The next handler**, named [`next`](https://code.claude.com/docs/en/plugins/mods/events#how-a-hook-handles-an-event): a function that passes the event on to the other mods and then to Claude Code's own behavior, and returns the result
235235
236236The hooks in `first-mod` handle their events in these ways:
from line 271
271271
272272If your mod has no `tsconfig.json` of its own, Claude Code adds one at the mod's root that extends the generated one, so your editor and `tsc -p ./first-mod` type-check the mod without more setup.
273273
274The events and methods can change between releases, so trust these files over any page, this one included, when they disagree.
275
276`claude-code/index.d.ts` is the fullest reference for your build, with a comment and an example for every mods API method. To look something up, search the file for its name, such as `'tool.call'`.
274Events and methods can change between releases, so use these files as the reference for your version. To look up an event or method, [search `claude-code/index.d.ts`](https://code.claude.com/docs/en/plugins/mods/reference#look-up) for its name, such as `'tool.call'`.
277275
278276### Check what Claude Code reads from your mod
279277
No line in this hunk matches that.