claude/for
Search
Subscribe
Claude Code

How do I use the PreSkillShellCommand hook in Claude Code?

Claude Code 2.1.332 adds the PreSkillShellCommand hook, which can refuse a skill's inline shell commands as it loads. Here is how to set it up.

PreSkillShellCommand is a hook event that arrived in Claude Code 2.1.332, released on November 25, 2026. It fires before a skill's injected shell command runs, and it can block that command. When it does, the skill still loads, just without the output of the command you stopped.

This guide is independent and unofficial. It follows Anthropic's changelog and documentation, both read on November 30, 2026.

We did not run this. The writing session had no access to the Claude Code CLI, so nothing below is a hands-on result and we show no sample output. The skill, script and settings entry in the walkthrough are our own assembly of documented pieces. Try them in a throwaway folder before you rely on them.

What the changelog says

The Claude Code changelog dates version 2.1.332 to November 25, 2026. One line under Added covers this event:

Added a PreSkillShellCommand hook event that can refuse a skill or command's inline shell commands as it loads; on 2.1.331 and older, a settings file naming it opens a dialog at start

Two facts matter for a beginner. The hook is about shell commands written inside a skill or custom command. And an older Claude Code that meets the name in a settings file shows a dialog at start instead of ignoring it.

What an inline shell command is

A skill is a folder with a SKILL.md file that tells Claude how to do one job. If you have not made one yet, our guide to creating a Claude Code skill starts from zero.

Anthropic's skills documentation describes a feature called injecting dynamic context. You write a shell command after an exclamation mark and backticks, and the output replaces the placeholder before Claude reads the skill. Its own example fetches pull request data with the GitHub CLI.

That is useful, and it is also a place where a command runs on your machine because a text file said so. This hook gives you a checkpoint right there.

What the hook does

The hooks reference lists the event in its lifecycle table as firing "Before a skill's" injected shell command runs, and adds "Can block the command". The table of exit code 2 behavior says what a block looks like for this event:

Blocks the command, and the skill loads without its output

The reference also says the matcher filters on the "tool that runs the command", with Bash and PowerShell as example values. Its common fields table says the if field is "Only evaluated on PreToolUse, PostToolUse, PostToolUseFailure, PermissionRequest, PermissionDenied, and PreSkillShellCommand." Exit code 2 is the one block signal we found documented for this event.

Set it up in four steps

now

Check your version

Run claude --version. Anything older than 2.1.332 shows a dialog at start when a settings file names the event.

now

Create a skill with one inline command

Save the SKILL.md below as .claude/skills/repo-status/SKILL.md in a test folder that is a git repository.

next

Add a script that refuses the command

Save the script below as .claude/hooks/check-skill-command.sh and make it executable.

next

Register the hook, then call the skill

Add the settings entry, then type /repo-status and read what Claude reports.

The skill uses the inline syntax from Anthropic's own example, applied to two harmless Git commands:

---
name: repo-status
description: Summarize the current state of this repository
---

## Current state
- Branch: !`git branch --show-current`
- Changes: !`git status --short`

Summarize this in three bullet points.

The script is the simplest possible blocker. It refuses everything, which is exactly what you want while you test:

#!/bin/bash
echo "Blocked: skill shell commands are not allowed in this folder" >&2
exit 2

Run chmod +x .claude/hooks/check-skill-command.sh. Then put this in .claude/settings.json, using the structure shown in the hooks reference:

{
  "hooks": {
    "PreSkillShellCommand": [
      {
        "matcher": "Bash|PowerShell",
        "hooks": [
          {
            "type": "command",
            "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/check-skill-command.sh"
          }
        ]
      }
    ]
  }
}

The Claude moves worth stealing, by email

Workflows tested on real jobs, sent only when they are worth it. Free.

What you should see

According to the exit code table, the two Git commands do not run, and the skill loads without their output. Claude then has no branch name or change list to summarize, so it should say so or ask you for them.

Our reading of the reference is that the stderr line from the script appears as an error notice. We have not seen it. Run /hooks to confirm the hook is registered: the reference describes it as a read-only browser that labels where each hook comes from.

You do not need to restart for the edit. Anthropic's settings page says Claude Code "applies most edits to the running session without a restart, including edits to permissions, hooks".

Block only some commands

A hook that refuses everything is a smoke test, not a policy. The if field lets you narrow it. Adding "if": "Bash(git push *)" next to type and command should limit the hook to commands that match that pattern.

The reference lists this event among those where if is evaluated, but we did not test how it treats a command inside a skill. Check the result with a skill that holds one matching and one non-matching command.

For the script itself, the pages we read do not describe the JSON your script receives on this event. Our own caution: print that input to a file once, read it, and only then write logic that depends on a field.

Hook or setting: which one to use

Anthropic's skills page documents a blunter tool, a setting named disableSkillShellExecution:

To disable this behavior for skills and custom commands from user, project, plugin, or additional-directory sources, set "disableSkillShellExecution": true in settings. Each command is replaced with [shell command execution disabled by policy] instead of being run.

PreSkillShellCommand hookA script of your own decides, and exit code 2 refuses a command. You can write it to allow some and refuse others.
disableSkillShellExecutionOne switch turns off every inline command from the listed sources. Bundled and managed skills are not affected.

If you only need a blanket ban, the setting is simpler. The same page calls it most useful in managed settings, where users cannot override it. If you want to inspect commands, use the hook.

Where this does not help

  • We did not run it. We cannot confirm the exact message, the order of events or how if matches inside a skill.
  • Older versions complain. On 2.1.331 and older, the changelog says a settings file naming the event opens a dialog at start. If you commit the entry to .claude/settings.json, teammates on old versions see it.
  • Coverage is not spelled out. The pages we read do not say whether the hook fires for bundled skills, plugin skills or the new server:skill skills from MCP servers added in the same release.
  • Hooks can fail open. Whether a crashed hook lets the command through depends on the event and settings. Our guide on making hooks fail closed covers onFailure.
  • It is days old. Check the changelog again before you build a routine on it.

If you want a short note when a hook change like this one affects your setup, the newsletter sends one only when it matters.

What does the PreSkillShellCommand hook do?

It runs before a skill's injected shell command and can block it. Anthropic's hooks reference lists it as firing "Before a skill's" injected shell command runs, with "Can block the command". On a block, the skill loads without that command's output.

Which Claude Code version added PreSkillShellCommand?

Claude Code 2.1.332, dated November 25, 2026 in Anthropic's changelog. On 2.1.331 and older, a settings file that names the event opens a dialog at start. Run claude --version to check what you have.

Does exit code 2 stop the whole skill?

No. The hooks reference says exit code 2 "Blocks the command, and the skill loads without its output". Only the shell command is refused. Claude still receives the rest of the skill's text.

How do I turn off all skill shell commands instead?

Set "disableSkillShellExecution": true in settings. Anthropic's skills page says each command is replaced with [shell command execution disabled by policy] instead of being run. It applies to user, project, plugin and additional-directory skills, and not to bundled or managed ones.

Sources (checked 2026-11-30)

The Claude moves worth stealing, by email

Workflows tested on real jobs, sent only when they are worth it. Free.