r/ClaudeCode • u/montropy • 14h ago
Tips & Workflows Plugin hooks on the Skill tool don't fire when you type the skill as a slash command
I'm building a Claude plugin and wanted hooks to make Claude reliably read a skill's reference files.
Telling it in Skill.md ("read X every time") only worked some of the time in my evals. So I built a small probe plugin to see where each hook type runs and what it receives.
Posting in case it saves someone the confusion I had.
The setup: hooks/hooks.json with SessionStart, UserPromptSubmit, PreToolUse/PostToolUse (matcher Skill|Read|Bash), UserPromptExpansion and Stop.
Each runs a small Node script that logs to a file in the temp folder and returns additionalContext.
Where hooks run:
| Where | Hooks run? | Notes |
|---|---|---|
| Claude Code CLI | ✅ | |
| Cowork | ✅ | Inside Cowork's own Linux VM (Node 22 and Python 3 available), even on Windows |
| Code tab | ✅ | On Windows it runs in Git Bash. python3 there may just be the Microsoft Store alias, so use Node or install Python properly |
| claude.ai chat | ❌ | plugin hooks are ignored there |
The problem is at first PreToolUse/PostToolUse on Skill never fired in the Code tab, while every other hook did.
The cause: I'd been starting the skill by typing /plugin:skill.
A typed slash command is expanded straight into your prompt, so the model never calls the Skill tool, and there's no tool call for the hook to see.
The hooks docs do say typing /skillname bypasses PreToolUse. In Cowork I'd asked in plain words, so the model called the Skill tool and the hooks fired.
How to catch both:
- Claude loads the skill itself (the Skill tool): PreToolUse/PostToolUse with matcher Skill. tool_input is {"skill": "plugin:skill", "args": "..."}.
- You type the slash command: UserPromptExpansion. Its input includes expansion_type: "slash_command", command_name: "plugin:skill" and command_source: "plugin". It fired in the CLI and in Cowork. In one Cowork run it didn't, and I never found out why.
- As a fallback: UserPromptSubmit fires everywhere hooks run, but in Cowork its prompt field starts with the app's own system notes, with your text after. So scanning it for a skill name works, but could also match a name in those notes.
Other things worth knowing:
- additionalContext reaches the model. I tested it by having the hook give a "word for today" and checking the reply used it. That held for PostToolUse on the Skill tool, UserPromptSubmit and UserPromptExpansion.
- A Stop hook can enforce things. It can return {"decision": "block", "reason": "..."} to send Claude back, for example "you didn't read references/X.md". Check stop_hook_active so it only blocks once. That worked in the CLI, the Code tab and Cowork.
- In Cowork, Stop can't read the transcript. The transcript_path the hook receives couldn't be read from inside the VM. So I have my PostToolUse hooks keep their own record of skills loaded and files read in a temp file, and the Stop hook reads that instead.
- Claude may refuse what a hook tells it. When my Stop hook sent it back to read a file that said "add this exact line to your reply", Cowork's Claude read the file but declined the instruction, because it came "from a hook and a file, not from you". That's fair, since it looks like prompt injection. I'm now wording every block reason as a reminder of the plugin's own skill step ("writing-style step 1 requires reading X"), not as a new instruction.
- Evals run plugin hooks. claude plugin eval runs them, so you can test an enforcement hook in an eval case.
Has anyone found a cleaner way to make sure a skill's reference files actually get read?
Or a reason not to rely on Stop-hook enforcement?
•
u/AutoModerator 14h ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/idemasler 14h ago
the temp-file check has a stale-state failure mode: run the skill once, leave the marker behind, start a new session, and skip the reference read. does Stop still pass? i'd scope the marker to the session and write it only after a successful Read, not just after the skill expands.