Claude Code Plugin Hooks: Ship Hooks That Fire for Every User

David IyaDavid Iya December 4, 2026 9 min read

What Claude Code plugin hooks are

Claude Code plugin hooks are hooks that ship inside a plugin instead of living in someone's settings file. You save them in hooks/hooks.json at the plugin root, and anyone who enables the plugin gets them. A hook can run a shell command, send an HTTP request, call an MCP tool, send a prompt to a model or start a subagent at a point in Claude Code's lifecycle, such as after every file edit or before every Bash command.

This is how you hand a whole team the same guardrail or the same formatter without asking each person to edit their settings. The hook installs with the plugin, updates with the plugin and stops when the plugin is disabled. Install the plugin from the + menu in the desktop app or with /plugin in the terminal, and the hooks run in a local desktop session and a terminal session alike.

Add a hook to your plugin

  • Create hooks/hooks.json at the plugin root. The file needs a top-level "hooks" key, and inside it the same event map you would put under hooks in settings.json: an event name such as PostToolUse, a matcher such as Write|Edit, and the hooks to run.
  • Point the command at a script in the plugin. A formatter hook runs scripts/format.sh by its path under ${CLAUDE_PLUGIN_ROOT}, with the variable wrapped in double quotes so a path with a space stays one word. Keep the script at scripts/format.sh and mark it executable.
  • Load the plugin and trigger the event. Ask Claude to edit a file. A PostToolUse hook that exits 0 shows nothing in the transcript, so check that it ran from what the script changed or from the debug log covered below.

The wrapper is the part people get wrong. A hooks file that contains only the event map, without the top-level "hooks" key, fails to load. Because the shape matches settings.json, the fastest way to build a plugin hook is to get it working in your own settings first, then move it into the plugin.

hooks/hooks.json or the manifest hooks key

You can also declare hooks in plugin.json under a hooks key. It takes a path to a .json file, an inline hooks object, or an array that mixes both. Whatever you declare there is merged with hooks/hooks.json when that file exists, so both load.

Where a plugin's hooks can live

LocationShapeUse it when
hooks/hooks.jsonEvent map wrapped in a top-level "hooks" keyDefault. One file, picked up with no manifest entry
Extra file named in the manifestSame wrapper as hooks/hooks.jsonYou want to split hooks into groups, such as config/extra-hooks.json
Inline object in the manifestThe event map itself, with no wrapperOne or two small hooks you would rather keep next to the plugin's metadata

My default is hooks/hooks.json and nothing else. One file is easier for a reviewer to find, and the people installing your plugin will look there first. Paths in the manifest are relative to the plugin root and must start with ./, and a path that resolves outside the plugin root does not load.

When plugin hooks fire

A plugin's hooks do not wait for one of the plugin's skills or commands to be used. Claude Code registers them when a session loads the plugin, and they fire on their events from then on. They also fire inside subagents: when a subagent calls a tool, PreToolUse and PostToolUse run the same hooks as in the main conversation.

That makes the matcher the only thing standing between your hook and every tool call the user makes. A PostToolUse hook with no matcher runs after every tool, including reads and searches. Narrow it to the tools you mean, such as Write|Edit, and have the script exit early for files it does not handle.

Environment, paths and quoting

What a plugin hook process receives

VariablePoints toUse it for
CLAUDE_PLUGIN_ROOTThe installed version of the pluginScripts and config files bundled with the plugin. Read-only in practice, because it changes on update
CLAUDE_PLUGIN_DATA~/.claude/plugins/data/<id>/, kept across plugin updatesCaches, installed dependencies, anything the hook writes
CLAUDE_PROJECT_DIRThe project rootProject-local scripts and config
CLAUDE_PLUGIN_OPTION_<KEY>Each value the user set in the plugin's configurationSettings such as a team name or an API endpoint

Quoting decides whether the hook works on a machine with a space in its home path. When a command has no args, it runs through a shell, so wrap the ${CLAUDE_PLUGIN_ROOT} path in double quotes to keep it one word. When you pass args instead, the command runs in exec form with no shell, and each args element is one argument exactly as written, so no quoting is needed.

  • Use exec form for any hook that runs a bundled script. Set command to node and args to the script path under ${CLAUDE_PLUGIN_ROOT}. That pattern also works on Windows, where exec form needs a real executable and cannot run the .cmd shims in node_modules/.bin.
  • Use shell form only when you need pipes, && or redirects, and quote the path variable.
  • Never write state under ${CLAUDE_PLUGIN_ROOT}. The root moves when the plugin updates. ${CLAUDE_PLUGIN_DATA} survives updates and is deleted by default when the plugin is uninstalled from the last place it is installed.
  • Read user settings from CLAUDE_PLUGIN_OPTION_<KEY> instead of asking people to edit your script. Claude Code plugin userConfig covers how to declare them.

See your hook run

Hooks that succeed are quiet, which is good for users and bad for you while you build. Start Claude Code with claude --debug-file <path> to write the debug log somewhere you choose, or run claude --debug and read the log at ~/.claude/debug/<session-id>.txt. The --debug flag does not print to the terminal.

On v2.1.296 or later, each command hook on a tool event leaves a Hooks: line when it finishes, with the event, the matched tool, the command, the plugin it came from, how it ended and how long it took. That duration is the number I check first. By default a hook blocks Claude until it finishes, so a slow formatter on every edit is something every user of your plugin waits through. If the work does not need to block anything, set "async": true on the command hook to run it in the background.

If your hook blocks an action by exiting with code 2, the blocking error now ends with This hook comes from the <plugin> plugin. That landed in v2.1.281, so on older versions users see the block without your plugin's name on it. Write a stderr message that says what was blocked and how to fix it.

Four reasons a plugin hook does not fire

Diagnosing a silent plugin hook

SymptomCauseFix
Errors tab shows Couldn't load hooks from <path> or Hook load failedInvalid JSON or no top-level "hooks" keyFix the file, then run claude plugin validate
Plugin details show a note beginning Its hooks.json hooks do not runAnother enabled plugin has the same name, and its hooks registered insteadDisable or uninstall the other copy, then run /reload-plugins
Hook loads, no errors, never runsEvent name typo (names are case-sensitive) or a matcher that does not match the tool nameCheck both, then trigger the event on purpose with debug logging on
Hook runs for you but not for a teammateTheir organization sets allowManagedHooksOnly, which blocks hooks from plugins that managed settings do not force-enableHave the admin force-enable the plugin in managed enabledPlugins with the full plugin@marketplace ID

The same-name case is the one I would watch for. Two plugins with the same manifest name from different marketplaces both show as enabled in /plugin, but only one registers its hooks. The note in the Errors tab that names the winning copy needs v2.1.296 or later. Give your plugin a name nobody else is likely to use.

Hooks your users can trust

A plugin hook runs with the user's own privileges on every matching event, without asking. That is exactly why reviewers open hooks/hooks.json before anything else, and why I keep plugin hooks small and boring.

  • Keep each hook to one job, and keep it fast. Format the changed file, not the whole project.
  • Ship readable scripts, not binaries, so a reviewer can see what runs in a minute.
  • Say what each hook does in the README, including any network call it makes.
  • Do not treat a hook as the only guardrail in remote work. In a desktop app SSH session, Desktop sometimes omits a plugin's hooks on the remote machine, and always does when either machine runs Windows. If an organization relies on a hook to block actions there, define it on the remote machine as well.

For the reviewer's side of this, Claude Code plugin security covers what to read before installing someone else's plugin. For rolling vetted hooks out to a team, Claude Code managed plugins covers force-enabling through managed settings.

Free Claude Code drops, straight to your inbox

Short, practical drops on skills, MCP, agents, prompts, and more. No spam, unsubscribe anytime.

Frequently asked questions

Where do hooks go in a Claude Code plugin?

In hooks/hooks.json at the plugin root, under a top-level "hooks" key, in the same shape as the hooks object in settings.json. You can also list extra hook files or inline hooks under the hooks key in plugin.json, and both load.

When do plugin hooks run?

From the moment a session loads the plugin. They do not wait for one of the plugin's skills or commands to be used, and they also fire for tool calls inside subagents. Narrow the matcher to control when they run.

Why does my plugin hook fail when the path has a space?

A shell-form command splits an unquoted path at the space. Wrap ${CLAUDE_PLUGIN_ROOT} in double quotes, or switch to exec form by passing the script path in args, where no quoting is needed.

Where should a plugin hook store data?

In ${CLAUDE_PLUGIN_DATA}, which is kept across plugin updates. ${CLAUDE_PLUGIN_ROOT} changes when the plugin updates, so anything written there can disappear.

How do I check that a plugin hook ran?

Start Claude Code with claude --debug-file <path>, or with claude --debug and read ~/.claude/debug/<session-id>.txt. On v2.1.296 or later, each command hook on a tool event leaves a Hooks: line with its plugin, result and duration.

Why does a plugin hook not run for my teammate?

Common causes are another enabled plugin with the same name registering its hooks instead, or managed settings with allowManagedHooksOnly, which blocks plugin hooks unless managed settings force-enable that exact plugin@marketplace.

Last reviewed by David Iya on December 4, 2026

David Iya

Written by

David Iya

Forbes 30 Under 30 · Y Combinator

Keep reading

Claude CodeGetting Started

What is the difference between Claude Code and regular Claude (claude.ai)?

Regular Claude on claude.ai is a chat window: you type, it answers, and anything it makes comes back as a download. Claude Code works directly on the files in a folder on your computer, creating, editing and renaming them and running commands for you. Here is what each one does, which plan gets you each, and a simple rule for which to open.

Duncan Rogoff 8 min
Read article
Claude CodeClaude Cowork

What is the difference between Claude Code and Claude Cowork?

Claude Code is built for making software: websites, apps and automations. Claude Cowork is built for everyday office work: documents, spreadsheets, research and organizing files. Both come from Anthropic, both are included in the paid Claude plans, and both use the same kind of agent that plans a task and works through it on its own. Here is what each one is, where each one runs, what it costs, and a simple rule for picking one.

Duncan Rogoff 7 min
Read article

Ready to build it yourself?

Join Claude Code Club, the #1 community for learning claude code, for $9/month.

← Back to the blog