Skip to content
Agentic Control Plane

Claude Code Hooks: Events, Decisions and Skip-Permissions

David Crowe David Crowe · · Updated · 14 min read
claude-code hooks permissions reference
Share X HN LinkedIn

Just want the answer? A PreToolUse hook is a command Claude Code runs before every tool call. It reads JSON on stdin and blocks the call with exit code 2 or with a JSON deny. It fires in every permission mode. One entry in ~/.claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      { "matcher": "Bash|Edit|Write|mcp__.*",
        "hooks": [ { "type": "command", "command": "node ~/.acp/govern.mjs", "timeout": 10 } ] }
    ]
  }
}

Install the ACP hook in one command →  ·  what it writes →

Claude Code’s hooks reach further than any other coding agent’s. They cover every built-in tool and every MCP tool, they can allow, deny, ask or rewrite a call, and they run in every permission mode. People often get that last part wrong and say the bypass flag turns hooks off. It doesn’t. This page covers what hooks are, what they receive, what they can answer, and where they stop.

Where hooks live

Hooks are declared in settings, and settings have scopes:

Scope File Notes
User ~/.claude/settings.json Applies to every project on the machine
Project .claude/settings.json Checked in, shared with the repo
Project (local) .claude/settings.local.json Per-machine overrides, not committed
Managed Organization-deployed settings The scopes above can’t override it
Plugin hooks/hooks.json in the plugin Ships with the plugin
Skill / subagent Frontmatter Applies only to that skill or subagent

Two managed-settings switches matter for a team. allowManagedHooksOnly runs only the managed hooks and ignores the rest. disableAllHooks turns every hook off, along with the custom status line. Both are files on the machine, so anyone who can write to the config can remove a hook. That is true of any client-side control, including ACP’s. It’s why teams roll hooks out from managed settings and keep the decision somewhere the endpoint can’t edit.

The events

Claude Code fires hooks on far more than tool calls. The list today: SessionStart, Setup, UserPromptSubmit, UserPromptExpansion, PreToolUse, PermissionRequest, PermissionDenied, PostToolUse, PostToolUseFailure, PostToolBatch, Notification, MessageDisplay, SubagentStart, SubagentStop, TaskCreated, TaskCompleted, Stop, StopFailure, TeammateIdle, InstructionsLoaded, ConfigChange, CwdChanged, DirectoryAdded, FileChanged, WorktreeCreate, WorktreeRemove, PreCompact, PostCompact, PreModelSwitch, PostModelSwitch, Elicitation, ElicitationResult, SessionEnd.

Two of them do the control work. PreToolUse runs before a tool executes and can stop it. PostToolUse runs after, sees the result, and is where output scanning happens. The rest are for observing and lifecycle. PermissionRequest fires when Claude Code is about to show a permission prompt, which is a different moment from running a tool.

The PreToolUse contract

Input, as JSON on stdin:

{
  "hook_event_name": "PreToolUse",
  "session_id": "…",
  "tool_use_id": "…",
  "tool_name": "Bash",
  "tool_input": { "command": "git push --force origin main" },
  "permission_mode": "default",
  "cwd": "/Users/you/repo",
  "transcript_path": "/Users/you/.claude/projects/…/session.jsonl"
}

tool_input holds the arguments as the model wrote them: a command for Bash, a file_path and content for Edit and Write, the tool’s own schema for MCP tools. permission_mode is the session’s mode, including bypassPermissions. That is how you can see hooks run there.

Output, by exit code or JSON:

You return Effect
Exit 0, no stdout No decision; the normal permission flow applies
Exit 2, reason on stderr Blocked; the reason goes back to the model
Exit 0 + JSON permissionDecision: "deny" Blocked, with permissionDecisionReason shown to the model
Exit 0 + JSON permissionDecision: "allow" Runs without a prompt
Exit 0 + JSON permissionDecision: "ask" Forces a prompt, even for an allowed tool
Exit 0 + JSON updatedInput: {…} The call runs with the rewritten arguments

The JSON looks like {"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": "…"}}. A systemMessage at the top level is shown to the user. A fourth value, defer, exists for print mode under the Agent SDK. The older top-level decision: block form isn’t what the current docs describe, so use hookSpecificOutput.

Matchers narrow which tools a hook sees. Use a plain name (Bash), alternation (Edit|Write) or a regex (mcp__.*). MCP tools are named mcp__<server>__<tool>, so mcp__github__.* is one server and mcp__.* is every MCP tool in the session. With no matcher, the hook sees every call.

Timeouts. Command hooks default to ten minutes. Set timeout per hook to shorten that. If a hook times out or errors, the normal permission flow applies and the call goes ahead. Claude Code v2.1.295 and later accept onFailure: "block", which turns a failed hook into a block. That is how you get a fail-closed hook.

A minimal working hook

This one denies a force-push to main and allows everything else:

#!/usr/bin/env node
let raw = ""; for await (const c of process.stdin) raw += c;
const ev = JSON.parse(raw);
const cmd = ev.tool_name === "Bash" ? String(ev.tool_input?.command ?? "") : "";
if (/git\s+push\b.*(--force|-f)\b.*\bmain\b/.test(cmd)) {
  process.stdout.write(JSON.stringify({ hookSpecificOutput: {
    hookEventName: "PreToolUse", permissionDecision: "deny",
    permissionDecisionReason: "force-push to main is blocked by policy" } }));
}

Register it under PreToolUse with a Bash matcher and it holds in every mode. It is only as good as the regex, though. Command strings have many spellings, and the rule lives on one machine.

What the ACP hook does with the same contract

On Claude Code, ACP runs as a plugin. The one-command installer’s ~/.acp/govern.mjs hook is the fallback when the plugin isn’t there. Either way it registers PreToolUse and PostToolUse entries and records which harness made each call. It does three things the minimal hook can’t:

  • It classifies the command instead of matching text. A command becomes a key (Bash.git.push, Bash.rm, Bash.curl.api.github.com) before the rule is looked up, so the rule is about the action, not the spelling. A separate safety floor tells a force-push from a plain push and holds the force-push for your approval.
  • It sets the tier from the permission mode. Rules are written per tier: interactive, subagent, background and api. A session started with --dangerously-skip-permissions is reported as background. auto mode counts as interactive with the plugin (the fallback hook reports it as subagent). An unattended session gets the unattended rules.
  • It decides what to do when the gateway is down. The plugin lets interactive sessions continue with a loud [ACP] UNGOVERNED notice, and keeps subagent, background and API sessions blocked until the gateway answers. The safety floor still runs on your machine either way. Set ACP_FAIL_MODE=closed or write closed to ~/.acp/failmode and interactive sessions are blocked too (plugin 0.30.1 and later).

A new workspace starts in audit mode, which records everything and holds only what the safety floor catches. Your rules start blocking after /acp-enforce.

In --local mode the same hook calls an on-device engine instead of the gateway. Policy sits in ~/.acp/policy.json and every decision goes to ~/.acp/audit.jsonl, with no account. What the installer writes, file by file.

Skip-permissions mode

--dangerously-skip-permissions puts the session in bypassPermissions. That auto-allows everything Claude Code’s own permission system would have asked about. It does not turn off hooks. PreToolUse fires before any permission-mode check, in every mode, and a hook deny blocks the call under the flag. Deny rules at every settings scope and the rm -rf / circuit breaker still apply too. The flag removes the human confirmation, so the deny rules and hooks you set up beforehand are the whole boundary. What the flag actually turns off.

Subagents

Tool calls inside a subagent pass through the same PreToolUse and PostToolUse hooks as the parent. SubagentStart and SubagentStop fire around the subagent itself, and a subagent definition can carry hooks of its own. The ACP hook sees the same permission_mode on subagent calls, so a fan-out under a skip-permissions parent is checked against the background rules, not the interactive ones.

Limits

  • Hooks see tool calls, not tokens. Cost lives on the model path. See the cost tracking reference.
  • Hooks are files on the machine. Write access to settings is the ability to remove them. Managed settings and allowManagedHooksOnly narrow that. A decision made at a gateway the machine can’t edit goes further, though disableAllHooks still turns a client-side hook off.
  • A hook only judges what it’s shown. A script the agent writes and then runs is one Bash call, and the hook has to judge it from the command text. The deny-list bypass catalog lists the spellings.

Comparing to Codex hooks

Codex CLI’s hooks have the same shape and a narrower reach. They cover shell commands first, and on current builds apply_patch and MCP calls too. Hosted tools such as web search don’t reach a hook. Both keep hooks running unattended. The Codex CLI hooks reference has the detail, and the side-by-side has the table.

Frequently asked questions

Do Claude Code hooks run with --dangerously-skip-permissions?

Yes. PreToolUse hooks fire before any permission-mode check, in every mode. The hook input even carries permission_mode: bypassPermissions. A hook that returns permissionDecision deny blocks the call under the flag. What the flag removes is the interactive prompt.

Where do Claude Code hooks live?

In settings files: ~/.claude/settings.json for the user, .claude/settings.json for the project, .claude/settings.local.json for local overrides, and managed settings for an organization. Plugins ship hooks in hooks/hooks.json, and skills and subagents can declare hooks in their frontmatter. allowManagedHooksOnly restricts execution to the managed scope.

How does a PreToolUse hook block a tool call?

Two ways. Exit with code 2 and put the reason on stderr. Or exit 0 with JSON on stdout: hookSpecificOutput.permissionDecision set to deny, and permissionDecisionReason explaining why. allow skips the prompt, ask forces one, and updatedInput rewrites the call before it runs.

Can a hook match MCP tools?
Yes. MCP tools are named mcp__server__tool, so a matcher of mcp__github__.* covers one server and mcp__.* covers all of them. Built-in tools match by name, with alternation (Edit Write) and regex allowed.
Do hooks apply to subagents?

Yes. Tool calls made inside a subagent pass through the same PreToolUse and PostToolUse hooks, and SubagentStart and SubagentStop fire around the subagent itself. Subagent definitions can also carry their own hooks.

What is the hook timeout?

Command hooks default to ten minutes, and a per-hook timeout field shortens that. The ACP plugin gives the gateway a short budget. If the gateway doesn’t answer, an interactive session continues with an UNGOVERNED warning, while subagent, background and API sessions stay blocked.

Where to read more

Running Claude Code? One command adds a hook. Each tool call is recorded, the session's model calls are priced, and a force-push, destructive SQL or curl | sh waits for your OK in the session.

macOS · Linux · WSL
curl -fsSL https://agenticcontrolplane.com/install.sh | bash
Windows · PowerShell
irm https://agenticcontrolplane.com/install.ps1 | iex

What the installer writes  ·  Claude Code guide  ·  free up to 5 agents

Share X HN LinkedIn
Get the next data drop
What agents actually cost, new tool-surface captures, and the occasional incident post-mortem — sent when we publish something worth your inbox, not on a schedule. Unsubscribe anytime.
Share: Twitter LinkedIn
Related posts

← back to blog