How to Extend Claude Code With Mods
Build Claude Code mods to add UI, commands, and event handlers. Follow the tally mod walkthrough, then validate, test, and review mod security.
A Claude Code mod is a plugin whose hooks/hooks.json file has a "modules" key pointing to a JavaScript or TypeScript file, and Claude Code calls the functions in that file when events such as tool.call or ui.render fire.
Settings hooks can block a risky command. Skills can teach Claude a convention. Neither can put a counter next to the spinner, add a /command that runs without a model turn, or change what the terminal draws.
Mods were announced on October 1, 2026. They need Claude Code v2.1.287 or later in the terminal and are on by default. This article covers what a mod can do that the other extension points can’t, then builds, reloads, validates and tests the official tally mod, and ends with what you trust when you install someone else’s mod.
Key Takeaways
- A Claude Code mod is a plugin with a JavaScript or TypeScript hooks module that runs inside the Claude Code process. That is why it can draw panes, add a band above the prompt and change the spinner.
- Every mod hook receives
$(the mods API),e(the event) andnext(which passes the event on). Returning without callingnextmakes the hook handle the event in place of Claude Code. claude plugin validatelists every event a mod hooks and every mods API method it calls without running its code. You can use it to check your own mod or to review someone else’s.- Mods are not sandboxed. They run with your user permissions and can read environment variables and settings files.
- Unless the built-in
sec-defaultguard is loaded, a mod can approve tool calls that your deny rules would block.
What Is a Claude Code Mod?
A Claude Code mod is a plugin that ships a hooks module, which is a .js or .ts file whose exported register function attaches handlers to Claude Code events. The mods overview describes three things a handler can do with an event: watch it, change it, or take it over. Mods also draw interface: they can add a pane, a band above the prompt, or text beside the spinner. You don’t need Node.js, a bundler or a build step, because Claude Code loads .js and .ts files directly.
The docs use “hook” for a mod handler and “settings hook” for the older shell-command hooks configured in settings.json. They are two different mechanisms.
Each hook decides what happens to the event:
event ──► your hook ──► next(e) ──► other mods ──► Claude Code default
│
├─ observe: return next(e) (event passes unchanged)
├─ rewrite: return next({ ...e, … }) (modified copy passes on)
└─ answer: return result, no next() (your hook handles it)
Mods vs Settings Hooks, Skills and MCP Servers
A Claude Code mod differs from the other three extension points in where it runs: a mod’s functions execute inside the Claude Code process, so it is the only one of the four that can draw UI. Settings hooks run as separate commands or requests, skills are instructions Claude reads, and MCP servers are external processes. The overview’s comparison covers the same ground in more detail.
| Mod | Settings hook | Skill | MCP server | |
|---|---|---|---|---|
| Runs as | JS/TS functions inside the Claude Code process | Shell command, HTTP request or prompt, configured in settings | A SKILL.md instruction file Claude reads | Separate process or service exposing tools |
| Can change | Tool calls, prompts, commands, turns, rendered UI | Go/no-go on a tool call or prompt, a tool call’s input, added context | What Claude knows and how it works | Which tools Claude can call |
| Draws UI | Yes | No | No | No |
| You write | JavaScript or TypeScript | A script plus a settings.json entry | Markdown | A server, any language |
| Reach for it when | You need a pane, a prompt band, a custom /command or an event rewrite | An existing script should block, allow or log an event | You keep repeating the same instructions | Claude needs an external system |
Settings hooks can adjust a tool call’s input, so rewriting events is not something only mods can do. Drawing UI is. If you already package conventions as skills, you don’t have to replace them: a single plugin can carry a mod, a skill and an MCP server together.
Build the Tally Mod
The create guide builds first-mod, a mod that counts Claude’s tool calls, shows the count beside the spinner and adds a /tally command. It needs three files.
mkdir -p first-mod/.claude-plugin first-mod/hooks
The manifest at first-mod/.claude-plugin/plugin.json is an ordinary plugin manifest. Mods don’t add any required fields:
{
"name": "first-mod",
"version": "0.1.0",
"description": "Counts Claude's tool calls, shows the count beside the spinner, and adds a /tally command",
"author": { "name": "Your Name" }
}
first-mod/hooks/hooks.json is the file that turns the plugin into a mod. The "modules" array lists the hooks module, with a path relative to hooks.json:
{
"description": "The first-mod hooks module",
"modules": ["./register.js"]
}
first-mod/hooks/register.js exports register(on). Claude Code calls it once when the mod loads, and each call to on attaches one hook:
let calls = 0
export function register(on) {
on('session.start', async ($, e, next) => {
await $.command.register({
name: 'tally',
description: 'Show how many tool calls Claude has made',
})
return next(e)
})
on('tool.call', async ($, e, next) => {
calls += 1
$.ui.invalidate('ui.render')
return next(e)
})
on('command.run', { command: 'tally' }, async () => {
return { text: 'Claude has made ' + calls + ' tool calls since this mod loaded' }
})
on('ui.render', { component: 'Spinner' }, async ($, e, next) => {
return next({ ...e, props: { ...e.props, suffix: ' · tool calls: ' + calls + '…' } })
})
}
Every hook receives three arguments. $ is the mods API, which you use for anything outside the hook’s own code. e is the event’s data. next passes the event to the remaining mods and then to Claude Code’s default behaviour. Each of the four hooks uses these differently:
session.startandtool.callobserve. They do their work and then returnnext(e)unchanged.$.ui.invalidateasks Claude Code to redraw so the new count appears.ui.renderrewrites. The{ component: 'Spinner' }matcher limits it to the spinner, and it passes on a copy of the event with a new suffix.command.runanswers. It returns its own text and never callsnext.
Load the mod for one session without installing it:
claude --plugin-dir ./first-mod
Ask for a task that uses a few tools, and the spinner count goes up as Claude works. For a non-interactive check, run claude -p "/tally" --plugin-dir ./first-mod. The guide expects it to print first-mod: Claude has made 0 tool calls since this mod loaded.
Edit, Reload and Get Types
When you save a mod loaded with --plugin-dir, Claude Code reloads it and calls register again. Module-level variables such as calls start over at zero. session.start also runs again on reload, which is how /tally gets registered again.
To see the reload happen, change the suffix label in the ui.render hook:
on('ui.render', { component: 'Spinner' }, async ($, e, next) => {
return next({ ...e, props: { ...e.props, suffix: ' · tools used: ' + calls + '…' } })
})
Claude Code writes type declarations for your installed version into .claude-plugin/types/. Events and methods can change between releases. When a doc page disagrees with .claude-plugin/types/claude-code/index.d.ts, the generated file is correct.
Validate and Test a Mod
claude plugin validate checks the manifest and runs the same static analysis on the hooks module that Claude Code runs at load time. It does not execute your code.
claude plugin validate ./first-mod
According to the guide, the output for first-mod includes these lines:
❯ ./register.js hooks: session.start, tool.call, command.run{command=tally}, ui.render{component=Spinner}
❯ ./register.js calls: $.command.register, $.ui.invalidate
There are two rules: write every file as an ES module (import, never require), and pass each event name to on as a string literal. Validation does not catch every mistake. The create guide notes that tol.call passes validation and the mod then fails to load, so check event names against the generated types.
To check behaviour, write a test. Test files import from claude-code/testing and run without a session, sign-in or network. This test stubs the tool calls, fires two of them, runs /tally and checks the reply. Save it as first-mod/tests/first-mod.test.ts:
import { expect, test } from 'claude-code/testing'
test('/tally reports the tool calls the mod has seen', async ($, on) => {
on('tool.call', () => ({ result: 'ok' }))
// Fire two tool calls, which the mod's tool.call hook counts
await $.tool.call({ tool: 'Bash', command: 'ls' })
await $.tool.call({ tool: 'Read', file_path: 'README.md' })
// Run /tally and check the text its hook returns
const answer = await $.command.run({ command: 'tally', args: '' })
expect(answer.text).toBe('Claude has made 2 tool calls since this mod loaded')
})
Run claude plugin test from inside first-mod. The report lists each test by name with pass and fail counts.
Or Ask Claude to Write It
You can also describe the mod in an interactive session, for example “show the current git branch above the prompt.” Claude uses the built-in plugin-authoring skill to write it into a per-session folder under ~/.claude/dev-mods/. Claude Code asks before loading it, and each save hot-reloads it as before. The folder belongs to the session, so copy the mod into your own directory if you want to keep it.
Security: What Can a Mod Reach?
Claude Code mods are not sandboxed, so review a mod before you install it. Run claude plugin validate on a mod’s directory first. It lists every event the mod hooks and every API method it calls without running any of its code. You need that information because of what the overview says a mod can reach:
- It runs with your user account’s permissions and is not sandboxed.
- It can read environment variables and settings files, and it sees every prompt and tool call.
- Any process it starts runs outside the sandbox Claude Code applies to Bash commands.
- A mod can redraw much of the interface, but it cannot restyle the permission prompt or change what that prompt tells you.
Whether a mod can override your deny rules depends on whether the built-in sec-default guard is loaded. The admin page says Claude Code loads the built-in guard sec-default@builtin ahead of every user-installed mod in two cases: on machines with managed settings or a managed-mcp.json file, and for Team or Enterprise sign-ins. Individual users without managed settings (on a personal plan, an API key or a cloud provider) don’t get the guard by default. On those setups, a mod can approve tool calls that your own deny rules would block. To check, open /plugin and look for cc-plugin-sec-default on the Installed tab.
There is one more risk. In auto and bypassPermissions modes, mods that Claude writes for you can load without asking. Admins can stop users from loading their own mods by setting the allowManagedModsOnly option of the sec-default guard in managed settings, under pluginConfigs → cc-plugin-sec-default@builtin. Install mods only from authors you trust.
Next Steps
A Claude Code mod is ordinary JavaScript that runs inside Claude Code. That gives it UI and control that hooks, skills and MCP servers lack, and it also means a mod can do anything you can. Build first-mod, make sure claude plugin validate and claude plugin test both pass, then run validate on any third-party mod before you install it.
FAQs
How do I turn off Claude Code mods without uninstalling them?
Disable a single mod's plugin on the Installed tab of /plugin. Start claude --safe-mode to skip every installed mod for one session, which also turns off your other customizations. Set 'disableAllHooks': true in ~/.claude/settings.json to stop installed mods in every session, along with settings hooks and a custom status line. None of these stops the mods built into Claude Code.
Do Claude Code mods work in the VS Code extension and with claude -p?
Yes, mod hooks run in both, but whether the mod's UI appears depends on the surface. Hooks run in the terminal CLI, the Desktop app's Code tab, the VS Code extension, claude -p and the Agent SDK. In claude -p and the Agent SDK, nothing the mod draws appears. The VS Code chat panel shows mod UI only in recent extension versions. Desktop WSL sessions load no plugins, so mods do not run there.
In what order do multiple Claude Code mods run on the same event?
Mods that hook the same event run in load order. The first mod to load sees the event first and the result last, because each hook passes control to the hooks after it through next. Each mod belongs to a priority tier: prepend, user, append or builtin. Mods an admin lists in prependPlugins run before every user-installed mod, and mods in appendPlugins run after them.
Gain Debugging Superpowers
Unleash the power of session replay to reproduce bugs, track slowdowns and uncover frustrations in your app. Get complete visibility into your frontend with OpenReplay — the most advanced open-source session replay tool for developers.
Star on GitHub12k