---
title: "Skill shell commands skip your PreToolUse hooks · Junaid Qadir"
description: "A skill's inline shell commands run while it loads, where PreToolUse hooks never fire. Claude Code 2.1.332 adds PreSkillShellCommand to close the gap."
url: "https://junaidqadir.com/blog/skill-shell-commands-skip-your-pretooluse-hooks"
date: "2026-11-28"
tags: ["ai", "claude-code", "developer-experience", "tools"]
---

[AI & Tools](https://junaidqadir.com/blog/category/ai-tools/)

# Skill shell commands skip your PreToolUse hooks

On this page

1.  [The commands your hook was not seeing](https://junaidqadir.com/blog/skill-shell-commands-skip-your-pretooluse-hooks#the-commands-your-hook-was-not-seeing)
2.  [The entry to add](https://junaidqadir.com/blog/skill-shell-commands-skip-your-pretooluse-hooks#the-entry-to-add)
3.  [The docs’ own test](https://junaidqadir.com/blog/skill-shell-commands-skip-your-pretooluse-hooks#the-docs-own-test)
4.  [Five ways to get it wrong](https://junaidqadir.com/blog/skill-shell-commands-skip-your-pretooluse-hooks#five-ways-to-get-it-wrong)
5.  [If you would rather have none of it](https://junaidqadir.com/blog/skill-shell-commands-skip-your-pretooluse-hooks#if-you-would-rather-have-none-of-it)
6.  [Check your own hooks](https://junaidqadir.com/blog/skill-shell-commands-skip-your-pretooluse-hooks#check-your-own-hooks)

A `PreToolUse` hook that blocks `rm -rf` sees every Bash command Claude asks to run in a Claude Code session. It does not see the commands a skill runs while it loads.

Claude Code 2.1.332, released on November 25, 2026, has an event for those. From the [changelog](https://code.claude.com/docs/en/changelog) (checked November 27, 2026): “Added a `PreSkillShellCommand` hook event that can refuse a skill or command’s inline shell commands as it loads”.

If you have a blocking script on `PreToolUse`, update to 2.1.332 and register the same script on `PreSkillShellCommand`, with `"onFailure": "block"`. The entry is below.

## The commands your hook was not seeing

A skill file can contain shell commands that run before Claude reads it. The [skills docs](https://code.claude.com/docs/en/skills#inject-dynamic-context) (checked November 27, 2026) describe the syntax: “The `` !`<command>` `` syntax runs shell commands before the skill content is sent to Claude.” Claude Code “runs the command and replaces the line with its output before Claude sees the skill content”. The docs’ first example skill starts with the output of `git diff HEAD`.

Claude never asks for these commands. They are not tool calls, and `PreToolUse` is an event about tool calls. The [hooks reference](https://code.claude.com/docs/en/hooks#preskillshellcommand) (checked November 27, 2026) says it without decoration: “PreToolUse hooks don’t fire for injected commands.”

They are not unchecked. Injected commands go through a permission check first, and the new hook “gets the commands that passed”. But a team that wrote a hook because the permission rules were not enough had a hole exactly where a skill from a plugin or a cloned repository does its setup.

## The entry to add

The hooks reference gives this for `.claude/settings.json` on macOS and Linux:

```json
{
  "hooks": {
    "PreSkillShellCommand": [
      {
        "matcher": "Bash|PowerShell",
        "hooks": [
          { "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/block-rm.sh", "args": [], "onFailure": "block" }
        ]
      }
    ]
  }
}
```

`block-rm.sh` is the docs’ own example script, the same one they use for `PreToolUse`:

```bash
#!/bin/bash
# .claude/hooks/block-rm.sh
COMMAND=$(jq -r '.tool_input.command')

if echo "$COMMAND" | grep -q 'rm -rf'; then
  jq -n '{
    hookSpecificOutput: {
      hookEventName: "PreToolUse",
      permissionDecision: "deny",
      permissionDecisionReason: "Destructive command blocked by hook"
    }
  }'
else
  exit 0  # no decision; normal permission flow applies
fi
```

The script does not need editing for the new event. The reference says: “To use one script on both events, leave `hookEventName` as `PreToolUse`.”

The hook’s input has `tool_name` and `tool_input.command`, as on `PreToolUse`, plus three fields that say where the command came from: `command_name` (the skill that is loading), `command_source` (such as `userSettings`, `projectSettings`, `policySettings`, `plugin` or `builtin`) and `invoked_by` (`"user"`, `"claude"` or `"other"`). A hook can be strict with plugin skills and lenient with your own.

## The docs’ own test

Nothing was run for this post. The hooks reference describes a test that deletes nothing: create `.claude/skills/hook-test/SKILL.md` containing the single line

```text
!`echo 'rm -rf'`
```

then start a session and type `/hook-test`. With the hook in place, the docs say you see:

```text
Not run in /hook-test: echo 'rm -rf' (blocked by hook: Destructive command blocked by hook)
```

The skill still loads. Claude reads `[not run: blocked by hook: <reason>]` where the command’s output would have been.

## Five ways to get it wrong

All of these are from the same section of the hooks reference.

1.  **Adding the hook before updating.** “Update before you add the hook, because earlier versions run injected commands without calling it.” A settings file that names the event on 2.1.331 gets a warning dialog, `Unknown hook event "PreSkillShellCommand" was ignored`, and no protection.
2.  **Leaving `onFailure` unset in exec form.** If the hook crashes or times out, the command runs, and the terminal reports it as `Ran anyway in /<name>`. The one exception the reference gives is a Code Mode session where Claude has already run code, in which a timeout blocks by default. Set `"onFailure": "block"` and do not depend on it.
3.  **Putting the hook in the skill’s frontmatter.** “A skill’s injected commands run without the hooks in its own frontmatter on its first load in a session and on loads inside a subagent.” Define it in a settings file or a plugin.
4.  **Expecting it to approve or rewrite commands.** “You can block a command from this hook, but you can’t approve or change one.” Returning `"ask"`, `"defer"` or any `updatedInput` blocks the command, the same as `"deny"`.
5.  **Moving the script instead of copying it.** In auto mode, a command that needs approval does not run while the skill loads. “Claude can run it afterward as a tool call, which fires `PreToolUse` and not this event, so keep your script on both events.”

`bypassPermissions` does not switch the hook off either. The reference says it “also runs in `bypassPermissions` mode”.

## If you would rather have none of it

There is a blunter switch. The skills docs: “set `"disableSkillShellExecution": true` in settings. Each command is replaced with `[shell command execution disabled by policy]` instead of being run. Bundled and managed skills are not affected.”

The 2.1.332 changelog entry also lists “Added skills from MCP servers (beta)”. The skills docs disagree by one version and say they need 2.1.331 or later. Either way, those are not a new way in. The skills docs list what does not apply to them: “`!` commands: they don’t run.”

## Check your own hooks

Open your settings files and list every hook under `PreToolUse` with a `Bash` matcher. Each one that exists to block something needs a twin under `PreSkillShellCommand`.

While you have them open, read how each script matches the command. The [Code Mode post](https://junaidqadir.com/blog/claude-code-code-mode-fix-your-hooks-first/) covered a hook that only looked at the start of the command string and what got past it. A script with that bug has it on both events now.

[Ai](https://junaidqadir.com/blog/tag/ai/)[Claude code](https://junaidqadir.com/blog/tag/claude-code/)[Developer experience](https://junaidqadir.com/blog/tag/developer-experience/)[Tools](https://junaidqadir.com/blog/tag/tools/)

---

Markdown version of https://junaidqadir.com/blog/skill-shell-commands-skip-your-pretooluse-hooks
Site guide for agents: https://junaidqadir.com/llms.txt
Full index: https://junaidqadir.com/sitemap-index.xml
