Claude Code adds a hook for skills' shell commands
Skills are the part of Claude Code I trust least, and not because of the model. A skill is a Markdown file that can contain a line like !`gh pr diff`, and that command runs before Claude ever sees the skill. Release v2.1.332 (25 Nov) adds a hook for exactly that moment, and it ships next to skills served by MCP servers. Both changes are about who gets to run code while a skill loads.
The gap: injected commands skip PreToolUse
The skills docs describe the syntax: !`<command>` runs a shell command, and its output replaces the placeholder, so Claude receives the data instead of the command. There is also a fenced ```! form for multi-line scripts. Two details matter for security. First, injected commands never prompt for permission; Claude Code checks each one against your permission rules, and a deny rule match aborts the whole invocation. Second, the docs say plainly that PreToolUse hooks don't fire for these commands.
That second point is the one I had wrong. I had a PreToolUse hook on Bash that logs every command, and I assumed it covered everything the agent ran. For a skill loading, it saw nothing. My audit log had a hole exactly where a cloned repo's .claude/skills could reach it.
What v2.1.332 adds
The release notes say it added a PreSkillShellCommand hook event that can refuse a skill or command's inline shell commands as it loads. The hooks reference lists it as a blocking event that runs before the injected command. Its matcher filters on the tool that runs the command (Bash or PowerShell), the if field works on it like on PreToolUse, and exit code 2 blocks the command, so the skill loads without its output.
One compatibility note straight from the release notes: on 2.1.331 and older, a settings file that names this event opens a dialog at start. If you share settings across a team, roll the version first.
There is also an older switch worth knowing. Setting "disableSkillShellExecution": true replaces each command with [shell command execution disabled by policy] for user, project, plugin and additional-directory skills. Bundled and managed skills are not affected, and the docs recommend it in managed settings where users can't override it. The hook is the finer tool: log everything, block selectively. The setting is the blunt one: nothing runs.
Skills from MCP servers
The same release adds skills from MCP servers as a beta; they show as server:skill in the / menu. The docs cover the trust side. Because the server supplies the content, ! commands don't run in these skills. Claude Code also ignores allowed-tools, hooks, model, shell and several other frontmatter fields in them, and @ references aren't attached. That is a sensible default: a remote server shouldn't get to widen its own permissions through frontmatter.
What I'm changing
- Bump to 2.1.332 everywhere before touching shared settings.
- Add a
PreSkillShellCommandhook that appends to the same audit log my Bash hook writes to, so skill loading is no longer invisible. - Turn on
disableSkillShellExecutionin managed settings for machines that open untrusted repos, and keep it off on my own box.
I haven't written the blocking rules yet, so I'm not going to pretend to have a tested policy. The takeaway is simpler: if your safety story for a coding agent is "a hook on Bash", check which code paths it actually sees. Skill loading was one it didn't, and now there is a hook for it.