Back to blog
Last updated December 2026·Poyan Karimi

Claude Code Hooks: How They Work and How to Share Them Across a Team

Claude Code hooks are your own commands that Claude Code runs automatically at set points, for example just before it runs a tool or when it finishes a reply. Unlike instructions in a prompt, a hook always runs. That makes hooks the place for rules that must never depend on the model remembering them.

This guide covers the events you can hook into, where hooks are configured, how a hook blocks an action, a working example, and the part most teams get stuck on: getting the same hooks to every developer and keeping them up to date.

What Claude Code hooks are

Anthropic’s hooks guide, checked 1 December 2026, describes hooks as user-defined commands that Claude Code runs at specific points in its lifecycle, which “gives you deterministic control: certain actions always happen rather than relying on the LLM to choose to run them.”

Most hooks are shell commands, but the hooks reference also lists HTTP endpoints, MCP tool calls, short LLM prompts and subagents as hook types. Typical uses:

  • Block commands or file edits that break a company rule, before they run.
  • Check every change, for example by running the formatter or linter after each file edit.
  • Add context when a session starts, such as today’s open issues or the branch rules.
  • Notify a person when Claude Code is waiting for a permission decision.

The events you can hook into

The reference lists more than thirty events. These are the ones most teams start with:

EventWhen it firesCan it block?
SessionStartA session begins or resumesNo, but it can add context
UserPromptSubmitA prompt is submitted, before Claude processes itYes, the prompt
PreToolUseBefore a tool call runs, such as a Bash command or a file editYes, the tool call
PermissionRequestA tool call needs a permission decisionYes, it can decide
PostToolUseAfter a tool call succeedsNo, the tool already ran
NotificationClaude Code sends a notification, for example while waiting for youNo
StopClaude finishes respondingYes, it can ask Claude to continue
SubagentStopA subagent finishesYes
PreCompactBefore the conversation is compactedNo
SessionEndA session endsNo

Tool events take a matcher that picks which tools the hook applies to, for example Bash or Edit|Write. An empty matcher or * matches all.

Where hooks are configured

Hooks live in Claude Code’s settings files, and entries from every level are merged:

FileApplies toShared?
~/.claude/settings.jsonAll your projectsNo, it is yours
.claude/settings.jsonOne projectYes, committed to the repository
.claude/settings.local.jsonOne projectNo, kept out of git
Managed policy settingsThe whole organisationYes, set by an admin
A plugin’s hooks/hooks.jsonWhile the plugin is enabledYes, with the plugin

Here is a minimal configuration that runs a script before every Bash command:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/check-bash.sh",
            "timeout": 30
          }
        ]
      }
    ]
  }
}

Type /hooks in Claude Code to see every hook that is active and where each one comes from: user settings, project settings, a plugin or the managed policy.

How a hook blocks or allows

A command hook gets the event as JSON on standard input and answers with its exit code:

  • Exit 0: success. Claude Code carries on. For a PreToolUse hook this does not approve the call; the normal permission rules still apply.
  • Exit 2: a blocking error. The message on standard error is the reason. For PreToolUse the tool call is blocked; for UserPromptSubmit the prompt is.
  • Any other code: a non-blocking error. The action continues. The docs warn that exit 1 does not block, even though it is the usual Unix failure code: a hook that enforces a rule should use exit 2.

For finer control, a hook can exit 0 and print JSON instead. A PreToolUse hook can then return a permissionDecision of allow, deny or ask, with a reason:

{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "Database writes are not allowed"
  }
}

Example: block risky commands

The script below is the check-bash.sh from the configuration above. It reads the command Claude Code is about to run and blocks recursive deletes and force pushes:

#!/bin/bash
# Reads the tool call as JSON on stdin and blocks risky commands.
cmd=$(jq -r '.tool_input.command')

if echo "$cmd" | grep -qE 'rm -rf|git push --force'; then
  echo "Blocked by company rule: no recursive deletes or force pushes." >&2
  exit 2
fi

exit 0

Claude Code shows the reason to Claude, which then looks for another way to do the task. Keep each hook to one rule with one clear message; a hook that blocks without saying why only teaches people to switch hooks off.

Security: what to know first

From Anthropic's hooks reference

Command hooks execute shell commands with your full user permissions. They can modify, delete, or access any files your user account can access. Review and test all hook commands before adding them to your configuration.

Two more points from the reference. In interactive sessions, hooks wait until you have accepted the workspace trust dialog for the folder. In non-interactive runs (-p or the SDK), Claude Code treats the folder as trusted, so hooks committed in a repository run straight away: check a repository’s .claude settings before you script Claude Code over it. Admins can also limit which hooks run, for example with the managed setting allowManagedHooksOnly.

Sharing hooks across a team

One developer with a good hook is easy. Twenty developers across ten repositories, all with the same, current hooks, is where teams get stuck. The usual options each have a catch:

Way to shareWorks well forThe catch
Commit .claude/settings.jsonRules for one repositoryA copy in every repository. Change a rule and you change it in each one, and the copies drift.
A pluginA packaged set of hooks and toolsEach person installs and updates it, and someone maintains the plugin.
Managed policy settingsRules that must hold for everyoneSet through device management or the admin console, usually by IT, not by the team that owns the rule.
Paste into a wikiNothing for longNobody knows who has which version, and old hooks keep running.

What teams actually need is the same thing they need for skills and guardrails: one place where the rule is owned and versioned, and every developer’s Claude Code picking up the current version without anyone copying files around.

Hooks in Deployed OS

In Deployed OS an admin shares a hook once, or straight from their own Claude Code settings. Each developer asks Claude Code to add it, and Deployed OS gives the install steps and records what was installed, so an update replaces the old version cleanly and a removed hook is removed everywhere. Hooks sit next to the company’s skills and guardrails, in your own company MCP.

How Deployed OS works

How we use hooks ourselves

We build Deployed OS with a coding agent: Claude Code takes an issue, writes the change and opens a pull request, a second AI reviews it, and our tech team decides what merges. We can let it work on its own because it is governed, and hooks are one of three layers that make that possible:

  • Skills tell the agent how we work: our development principles, the same version for the agent that writes and the agent that reviews.
  • Guardrails say what it may never do, such as skipping a failing test. See our guide to AI agent guardrails.
  • Hooks make sure the checks that must run on every step actually do, rather than relying on the agent to remember them.

All three come from one place, so a rule we change reaches every developer and every agent at once. The bigger picture is in our guide to AI agent governance, and how the same idea applies to pull requests is in our post on Claude Ship.

Frequently asked questions

What are Claude Code hooks?

Hooks are commands you define that Claude Code runs automatically at set points in a session, for example before a tool call (PreToolUse), after one (PostToolUse) or when Claude finishes responding (Stop). Because they always run, they suit rules that must not depend on the model remembering them.

Where do you configure Claude Code hooks?

In Claude Code settings files: ~/.claude/settings.json for all your projects, .claude/settings.json for one project and shared through git, .claude/settings.local.json for one project and not shared, managed policy settings for the whole organisation, and a plugin’s hooks/hooks.json. Entries from every level are merged.

How does a Claude Code hook block an action?

A command hook that exits with code 2 blocks the action, and its standard error becomes the reason. For PreToolUse that blocks the tool call. Exit code 1 does not block. A hook can also exit 0 and return JSON with a permissionDecision of allow, deny or ask.

Are Claude Code hooks safe?

They run with your full user permissions, so Anthropic advises reviewing and testing every hook command before adding it. In non-interactive runs Claude Code treats the folder as trusted, so hooks committed in a repository run straight away. Admins can restrict hooks through managed settings.

How do you share Claude Code hooks across a team?

Common ways are committing .claude/settings.json in each repository, packaging hooks in a plugin, or setting them in managed policy settings. Each has a catch: copies drift, plugins need updating, and managed settings usually sit with IT. A central place such as a company MCP can share one versioned hook to every developer.

Found this useful? Send it to someone who needs it.

Deployed OS

See what your AI can reach.

Deployed OS puts your company's skills, systems and guardrails in your own company MCP. Each employee connects once, in the AI they already use, and you decide what each team can reach. Leave your email and we'll be in touch shortly.

Proof from the field

All cases

Keep reading