Claude Code hooks security: are hooks safe, and how to audit them
A Claude Code hook is a shell command that runs with your full user permissions, so anyone who can add one to a settings file, plugin or repository you trust can run code as you. Type /hooks to see every active hook and where it came from.
Rather skip the manual setup? One command wires every agent you have installed to desktop toasts, phone push, and Slack, Discord or Telegram:
Updated 2026-11-18 · also see the Claude Code notifier and the full docs
Are Claude Code hooks safe? The short answer
Hooks are safe when you know where each one came from, and unsafe when you don't. A command hook is a shell command with your full user permissions, so it can read or change anything your account can and can make network requests. The risk is who gets to add one: a cloned repository, a plugin or a skill can all carry hooks. Claude Code gives you the tools to check, covered below.
- List every hook. Type
/hooksin Claude Code. It shows each hook, where it came from and the full text of what it runs. - Read the sources. Open
~/.claude/settings.json, each project's.claude/settings.jsonand.claude/settings.local.json, and each enabled plugin'shooks/hooks.json. - Review a repository before you trust it. After a
git pull, read the diff of.claude/as well as the code. - Switch hooks off for untrusted code. Pass
claude --settings '{"disableAllHooks": true}', or have an admin setallowManagedHooksOnly.
What a hook is allowed to run
A Claude Code command hook runs a shell command and passes it the event as JSON on stdin. The Claude Code docs put it plainly: command hooks execute shell commands with your full user permissions, and can modify, delete or access any file your user account can. A hook process also inherits Claude Code's environment, apart from the OTEL_* exporter variables and, when CLAUDE_CODE_SUBPROCESS_ENV_SCRUB is set to 1, the variables Claude Code strips. So an API key exported in your shell is visible to every hook.
- What it receives. Every event carries
session_id,transcript_pathandcwd. Tool events add the tool name and its input, so aPreToolUsehook sees the command or file path Claude is about to use. - What it can change. A hook can do more than watch. A
PreToolUsehook can deny a tool call or rewrite its input, so a hook can change what Claude does as well as read it. - Other handler types. Besides
command, a hook can behttp(the event JSON is sent as a POST request to a URL),mcp_tool,promptoragent.
Where Claude Code hooks come from
| Location | Applies to | Shared with others |
|---|---|---|
~/.claude/settings.json | All your projects | No |
.claude/settings.json | One project | Yes, it can be committed to the repo |
.claude/settings.local.json | One project | No, gitignored when Claude Code saves a setting to it |
| Managed policy settings | The whole organization | Yes, set by an admin |
A plugin's hooks/hooks.json | While the plugin is enabled | Yes, bundled with the plugin |
| Skill frontmatter | The rest of the session once the skill is invoked | Yes, defined in the skill file |
| Subagent frontmatter | While that subagent is running | Yes, defined in the subagent file |
Entries add up. User, project and local hooks are merged rather than replacing each other, and none of them can remove a managed hook. Hooks from settings files, managed policy and plugins also run inside subagents.
The real risks
- A repository you cloned. A project's
.claude/settings.jsoncan hold hooks and is meant to be committed. In an interactive session, Claude Code holds back hooks from every settings file until you accept the workspace trust dialog for the folder, or for a parent folder whose trust extends to it. Once you accept, the repository's hooks run. In aclaude -por SDK session no dialog ever appears and the folder counts as trusted, so the repository's hooks run straight away. - Hooks that change under you. Claude Code picks up edits to hooks in settings files automatically. After a
git pullin a repository you already trust, read the diff of.claude/as well as the code. - Plugins. An enabled plugin's hooks run with the same permissions as hooks you wrote yourself. Read a plugin's
hooks/hooks.jsonbefore you enable it. - Secrets. A hook sees your whole environment, the session's
transcript_pathand the inputs of tool calls. A command can hand any of that to another program. Claude Code's own advice for hook authors includes skipping sensitive files such as.env,.git/and keys. - Network exfiltration. A command hook is an ordinary command, so it can make network requests. An
httphook posts the event JSON to the URL it names. Two settings narrow the second kind:allowedHttpHookUrlslimits which URLs an HTTP hook may call, andhttpHookAllowedEnvVarslimits which environment variables go into hook headers.
How to audit the hooks you have
- List them. Type
/hooksin Claude Code. It is a read-only browser. It labels each hook with where it comes from (user settings, project settings, local settings, a plugin or the current session) and shows the full text of what it runs. - Read the files. Open
~/.claude/settings.json, then.claude/settings.jsonand.claude/settings.local.jsonin each project, then thehooks/hooks.jsonof each enabled plugin. To remove a hook, delete its entry. Claude Code has no way to disable one hook and keep it in the config. - Switch them all off while you look. Set
disableAllHookstotruein a settings file. It also turns off a custom status line and a custom file suggestion command.
{
"disableAllHooks": true
}Claude Code reads the value left after settings precedence, so a project's .claude/settings.json that sets "disableAllHooks": false overrides a true in your user settings. To turn hooks off for one run whatever the project says, pass the setting on the command line, which takes precedence over project and local settings:
claude --settings '{"disableAllHooks": true}'How to lock hooks down
For code you didn't write, the permissions docs suggest three options before you run claude -p there. Each stops the project's own hooks from running:
# read only your user settings, not the project's
claude -p --setting-sources user "your prompt"
# read no hooks, skills, commands, subagents, plugins or .mcp.json servers from the project
claude -p --bare "your prompt"
# turn hooks off for this run
claude -p --settings '{"disableAllHooks": true}' "your prompt"Setting disableAllHooks in your user settings alone is not enough here, because the project's settings take precedence over yours.
For a team, an admin sets allowManagedHooksOnly in managed settings:
{
"allowManagedHooksOnly": true
}- Still runs: hooks from managed settings, hooks the Agent SDK registers in process, and hooks from plugins your managed settings force-enable through
enabledPlugins. - Blocked: user, project and local hooks, hooks from other installed plugins, and hooks declared in agent frontmatter.
- Also narrowed:
statusLine,fileSuggestionandsubagentStatusLineare read from managed settings only. - Cannot be undone from below: only
disableAllHooksset at the managed level can disable managed hooks.
The setting's reference entry lists the rest, including how command-sourced plugins are treated.
Claude Agent SDK hooks
The Agent SDK has hooks of its own: callback functions you register in your code with options.hooks, which run in your process. When the SDK collects the hooks for an event, it also includes shell command hooks from settings files, if the matching settingSources (TypeScript) or setting_sources (Python) entry is enabled. The SDK hooks docs say it is enabled for default query() options. So an SDK agent started in a folder can run that folder's project hooks.
When the folder isn't yours, set settingSources without project settings. Under allowManagedHooksOnly, hooks the SDK registers in process still run, and user, project and local settings hooks do not.
Codex CLI, Gemini CLI and Cursor
- Codex CLI. Hooks live in
~/.codex/hooks.json,~/.codex/config.toml,<repo>/.codex/hooks.jsonand<repo>/.codex/config.toml, in plugins, and in managedrequirements.toml. Before a non-managed hook runs, Codex requires you to review and trust the exact hook definition. It records trust against the hook's hash, so new or changed hooks are skipped until you trust them. Run/hooksto inspect sources, trust hooks or disable individual non-managed hooks. Project hooks load only when the project's.codex/layer is trusted. To turn hooks off, sethooks = falseunder[features]inconfig.toml. Admins can setallow_managed_hooks_only = trueto ignore user, project, session and plugin hooks. The docs also say to treat tool hooks as a guardrail, not a complete enforcement boundary. - Gemini CLI. Hooks live in
settings.json:.gemini/settings.jsonin the project,~/.gemini/settings.json,/etc/gemini-cli/settings.json, and installed extensions. The docs say hooks execute arbitrary code with your user privileges and that project-level hooks are particularly risky in untrusted projects. Gemini CLI fingerprints project hooks. If a hook's name or command changes, for example after agit pull, it is treated as a new, untrusted hook and you are warned before it runs./hooks panellists them,/hooks disable-allturns them all off and/hooks disable <name>turns one off. Hooks run with a sanitized environment. - Cursor. Hooks live in
.cursor/hooks.jsonin a project and~/.cursor/hooks.jsonfor you. Enterprise installs add a system-widehooks.json(/Library/Application Support/Cursor/on macOS,/etc/cursor/on Linux and WSL,C:\ProgramData\Cursor\on Windows), and Enterprise teams can sync hooks from the web dashboard. Project hooks run in any trusted workspace. The Hooks tab in Customize and the Hooks output channel show what is configured and what ran. Cursor reloadshooks.jsonwhen you save it, so removing an entry is how you stop a hook.
What anotifier's own hooks do
anotifier is a set of hooks, so it should pass the same audit. This section follows the source of anotifier 1.8.0: src/notify.mjs and setup/patch-config.mjs. npx anotifier setup edits your user-level files only, never a project's settings:
| Agent | File setup edits | Events it registers |
|---|---|---|
| Claude Code | ~/.claude/settings.json | Notification, Stop, UserPromptSubmit (a turn timer, 1.8.0 and later), and the statusLine command |
| Codex CLI | ~/.codex/hooks.json and ~/.codex/config.toml | Stop, SessionStart, PermissionRequest, UserPromptSubmit (1.8.0 and later) |
| Cursor | ~/.cursor/hooks.json | stop |
| Gemini CLI | ~/.gemini/settings.json | AfterAgent, Notification, BeforeAgent (1.8.0 and later) |
| Antigravity CLI | ~/.gemini/config/hooks.json | Stop |
Every entry runs node "<path>/src/notify.mjs" --source <agent>, a local script in the anotifier package. For Claude Code, setup also points statusLine at src/statusline.mjs, which drives the usage and context warnings. If you already had a statusline, anotifier wraps it and still prints your line. disableAllHooks switches this statusline off too. Installed as a Claude Code plugin instead, the same Notification, Stop and UserPromptSubmit hooks come from the plugin's hooks/hooks.json.
For Codex, setup also sets hooks = true in config.toml and writes the trusted_hash of each of its own hooks, so Codex does not ask you to review them. If you edit one by hand, Codex skips it until you trust it again in /hooks.
When a hook fires, notify.mjs does this:
- Reads the event JSON from stdin and your settings from
~/.anotifier/config.json, including any per-folderprojectsrules (1.8.0 and later). Those rules live only in your own config file, never in a repository, so a cloned project cannot redirect your alerts. - On
UserPromptSubmit(andBeforeAgentfor Gemini CLI) it only writes the turn's start time (keyed by the session id) to~/.anotifier/turns.json, prints{}and exits: no config, no toast, no network. The hook has a 5-second timeout and logs and ignores every error. - For Claude Code, it can read the session transcript so a toast or webhook shows Claude's last message. That is the
richContentsetting: on for toast and webhook, off for ntfy. Other agents get generic text. - Shows a desktop toast by running a local program: PowerShell 7 with BurntToast on Windows,
osascripton macOS,notify-sendon Linux, and PowerShell through Windows interop on WSL. If you set an event'stoastSoundto the path of an audio file (1.8.0 and later), it also starts a local player for that file: Windows sound playback,afplay,pw-play,paplayoraplay. - Only if you turn on
suppressWhenFocused(off by default), it asks your operating system which window is in front before each alert, by running a local helper: PowerShell on Windows and WSL,xdotoolandpson Linux,lsappinfoon macOS. Nothing about the window leaves your machine. - Writes small lock files,
turns.jsonand anerrors.logunder~/.anotifier/, and always exits 0 so it can't fail your agent's turn.
The only network calls come from these channels. Each one is off unless you turned it on, except the version check:
| Destination | When | What is sent | Turn it off |
|---|---|---|---|
Your ntfy server (default https://ntfy.sh) | ntfy enabled with a topic | The notification title and text. Claude's last message only with ntfy.richContent | ntfy.enabled: false |
| Your webhook URL | Webhook enabled with a URL | JSON with title, message, source, project, event and timestamp in the generic format. For Claude Code the message is Claude's last message unless webhook.richContent is false | webhook.enabled: false |
| Your Sentry DSN | sentry.enabled with a sentry.dsn | Hook and channel errors | sentry.enabled: false |
posthog.devino.ca | You opted in to usage stats. At most once a day from hooks | Counts and which features are on. Never message text, project names, paths, topics or URLs | anotifier telemetry off, or DO_NOT_TRACK=1 |
registry.npmjs.org | At most once every 24 hours | A plain request for the latest anotifier version | updateCheck.enabled: false stops the hook's check |
Setup itself downloads the notification icon from claude.ai once and, on Windows, installs the BurntToast PowerShell module for your user. Apart from the calls above, the hook path makes no network calls of its own. The README lists every usage-stats field.
To inspect and remove it:
npx anotifier@latest status # which agents are wired, and with which events
npx anotifier@latest telemetry # usage stats on or off, and what is waiting to be sent
npx anotifier@latest uninstall # remove anotifier's hooks from every agentuninstallasks first, backs up each file to~/.anotifier/backups/, and removes only anotifier's entries (the turn timing hook included, withturns.json), its Codex trust hashes and its statusline wrapper, which restores your own statusline. It keeps~/.anotifier/, so delete that folder by hand if you want it gone. On Windows it also removes theagentfocus://click-to-focus protocol that the first toast registers.- A plugin install is separate: remove it from Claude Code's
/pluginmenu.uninstalldoesn't touch it. /hooksin Claude Code and Codex,/hooks panelin Gemini CLI, and the Hooks tab in Cursor show the entries too.
Official docs this page follows
Checked on 2026-10-11. Docs change, so confirm a setting there before you rely on it.
- Claude Code: hooks reference, permissions and workspace trust, allowManagedHooksOnly and disableAllHooks, managed settings
- Claude Agent SDK: hooks
- Codex CLI: hooks
- Gemini CLI: hooks
- Cursor: hooks
Claude Code hooks security: common questions
Are Claude Code hooks safe to use?
They are safe when you know where each one came from. A command hook runs with your full user permissions, so the risk is a hook you did not write: one in a repository you cloned, a plugin or a skill. Type /hooks to list every active hook with its source, read the settings files it points to, and use disableAllHooks or allowManagedHooksOnly for code you do not trust.
Can a Claude Code hook run any command?
Yes. A command hook runs a shell command with your full user permissions, so it can read, change or delete anything your user account can, and it can make network requests. Claude Code's docs say to review and test every hook command before you add it.
Does Claude Code run hooks from a repository I just cloned?
Only after you accept the workspace trust dialog in an interactive session. Until then Claude Code holds back hooks from every settings file. In a claude -p or SDK session there is no dialog and the folder counts as trusted, so the repository's hooks run right away. Use --setting-sources user, --bare or --settings with disableAllHooks set to true for code you didn't write.
How do I see which hooks are active in Claude Code?
Type /hooks. It is a read-only browser that labels each hook with its source (user, project or local settings, a plugin, or the session) and shows the full text of what it runs.
How do I turn off all Claude Code hooks?
Set disableAllHooks to true in a settings file, or pass --settings with {"disableAllHooks": true} for one run. A project's settings take precedence over your user settings, so the flag is the reliable way for a single run. Only the managed settings level can disable managed hooks.
What does allowManagedHooksOnly do?
It is a managed-settings key. When true, only managed hooks run, plus hooks the Agent SDK registers in process and hooks from plugins that managed settings force-enable. User, project and local hooks and other plugins' hooks are blocked.
Do Codex CLI, Gemini CLI and Cursor review hooks before running them?
Codex skips new or changed non-managed hooks until you trust them, and loads project hooks only for a trusted project. Gemini CLI fingerprints project hooks and warns before a changed one runs. Cursor runs project hooks in a trusted workspace.
Is anotifier's hook safe to run?
It is a local Node script you can read. It runs with your permissions like any hook, sends notifications only to the channels you turned on (ntfy, a webhook, and Sentry if you set a DSN), and makes a version check against the npm registry at most once a day. Usage stats are off unless you opt in. Run npx anotifier status to see what is wired and npx anotifier uninstall to remove it.
Try it
One command wires every agent you have installed: Claude Code, Codex CLI, Cursor, and Gemini CLI.
npx anotifier@latest setup