skip to content

Where can Claude Code hooks be declared, and what happens when user settings, project settings and a plugin all define hooks for one event?

level: middleimportance: should knowfreq 11%

answer

  1. four settings files plus three more
  2. lists add up, not override
  3. identical handlers deduplicated
  4. skills and subagents scope their own
  5. a read-only browser shows the source

basics

~20 s

Hooks live in user, project, local and managed settings, a plugin's hooks/hooks.json, and skill or subagent frontmatter. They merge rather than override: every matching hook from every source runs, in parallel, and /hooks shows each one's source.

solid answer

~40 s

Hooks can be declared in `~/.claude/settings.json` (all your projects), `.claude/settings.json` (shared with the repo), `.claude/settings.local.json` (this project, not shared), managed policy settings (organisation-wide), a plugin's `hooks/hooks.json` (while it is enabled), skill frontmatter (from invocation for the rest of the session) and subagent frontmatter (while that subagent runs). Unlike a scalar setting, hook entries merge across levels: user, project, local and plugin hooks all add to the list, and every matching handler runs in parallel. An identical handler defined in more than one settings file runs once; a plugin's or skill's copy stays separate. `/hooks` opens a read-only browser labelling each hook with where it came from.

go deeper

for a junior

Recall the main files: user settings for yourself, .claude/settings.json for the team, settings.local.json for local experiments, and /hooks to see them.

for a middle

Explain that hook lists merge across sources and run in parallel, how duplicates are handled, and the lifetime of skill and subagent frontmatter hooks.

for a senior

Diagnose surprises from scope: a skill hook lingering for the session, plugin subagents ignoring hooks frontmatter, settings hooks firing inside subagents.

for a principal

Plan where a team's hooks live, which belong in the shared repository versus a plugin or managed policy, and how changes to them are reviewed.

## The places a hook can be declared Claude Code reads hook configuration from several sources, each with its own scope: | Location | Scope | Shared? | |---|---|---| | `~/.claude/settings.json` | All your projects | No, local to your machine | | `.claude/settings.json` | One project | Yes, committed to the repository | | `.claude/settings.local.json` | One project | No, gitignored when Claude Code writes it | | Managed policy settings | Organisation-wide | Yes, admin-controlled | | A plugin's `hooks/hooks.json` | While the plugin is enabled | Yes, bundled with the plugin | | Skill frontmatter | From the skill's invocation for the rest of the session | Yes, in the skill file | | Subagent frontmatter | While that subagent runs | Yes, in the agent file | All of them use the same shape: an event name, matcher groups, and handlers. ## Hook lists merge For most scalar settings, the more specific file wins. **Hooks do not work that way.** Entries from user, project, local and plugin sources are combined: a project's `.claude/settings.json` adds its `PreToolUse` hooks to yours rather than replacing them, and neither can remove a managed hook. When an event fires: - every matcher group from every source is checked; - all matching handlers **run in parallel**; - a handler defined identically in more than one settings file runs **once**; - a plugin's or a skill's copy of that same handler stays **separate** and runs as well. How the outcomes of several parallel hooks combine into one decision belongs to the hook input and output contract; the precedence of ordinary settings belongs to the settings-file material. ## Frontmatter hooks are scoped to their component - **Skill hooks** register when you or Claude invoke the skill and keep running for the rest of the session, including later turns. The handler field `once` is honoured only here. - **Subagent hooks** run only while that subagent is active and are removed when it finishes; a `Stop` hook declared there becomes `SubagentStop`. Plugin-shipped subagents ignore the `hooks` frontmatter field, so a plugin author ships hooks in `hooks/hooks.json` instead. - Hooks from settings files, managed settings and plugins also **run inside subagents**: a `PreToolUse` hook in `settings.json` fires before a subagent's tool calls too. Whether a cloned repository's project hooks or skill hooks run before you trust the folder is a workspace-trust question with its own material. ## Seeing what is configured `/hooks` opens a **read-only** browser of the configured hooks, grouped by event. Each entry is labelled with its source, such as user settings, project settings, local settings, a plugin or the current session, and selecting one shows exactly what it runs and where it is defined. An `All events` entry lists every event, including ones with no hooks. Changes are made by editing the file the hook came from (or asking Claude through the `/update-config` skill); direct edits are normally picked up by the file watcher. ## Turning hooks off and organisation limits Two settings bound what runs, each owned by other material and named here only for orientation: 1. `disableAllHooks` turns off hooks after normal settings precedence applies, but set outside managed settings it cannot disable managed hooks. 2. An administrator's `allowManagedHooksOnly` blocks user, project, local and plugin hooks; `/hooks` then says that only managed hooks run. ## Choosing where to put a hook - **A personal convenience**, such as a desktop alert: `~/.claude/settings.json`. - **A team rule everyone should get**: `.claude/settings.json`, reviewed like code. - **A local experiment**: `.claude/settings.local.json`. - **Behaviour tied to one workflow**: the skill or subagent that owns it, so it is active only when needed. - **A reusable bundle across repositories**: a plugin's `hooks/hooks.json`. Two practical cautions follow from the table. Cloud sessions do not read your local `~/.claude/settings.json`, so a hook a team relies on in hosted sessions belongs in the repository's `.claude/settings.json` or in a plugin, not in one person's user settings. And because hooks from every source add up, a new project hook does not silence an old personal one: if a format step runs twice or two guards disagree, `/hooks` shows which file each copy came from.

  • Your user settings and the repo's `.claude/settings.json` define the exact same PreToolUse handler. Does it run twice?
    No. Claude Code deduplicates a handler defined identically in more than one settings file, so it runs once. A plugin's or a skill's copy of the same handler is kept separate and would run in addition.
  • A skill declares a PostToolUse hook. Why is it still firing three turns after the skill finished?
    Skill frontmatter hooks register when the skill is invoked and keep running for the rest of the session, not just the skill's own turn. Set `once: true` on the handler to have Claude Code remove it after its first successful run, or move the logic to a subagent, whose hooks end with it.

  • Project hooks replace the user's hooks for the same event.
  • Hooks in skill frontmatter stop when the skill's turn ends.
  • The same handler in two settings files runs twice.
  • Settings-file hooks never fire inside subagents.
  • /hooks is an editor that writes hooks into settings.json.