-
Notifications
You must be signed in to change notification settings - Fork 0
Skill: develop-skill-hooks — patterns for enforcing skill context via hooks #21
Copy link
Copy link
Open
Description
Summary
Create a skill that teaches how to build Claude Code hooks that enforce skill context injection. Covers the pattern of using PreToolUse hooks to detect when an agent is about to do something (e.g., write tests) and injecting relevant skill content via additionalContext if the skill hasn't been invoked yet.
Motivation
Discovered during development of claude-coding-plugin. Skills often don't auto-invoke when they should. Hooks can guarantee the agent has the right context before taking action, without relying on the agent to remember to invoke a skill.
Proven pattern to document
PreToolUsehook onEdit|Writewithiffield for path matching (e.g.,tests/**)- Read
session_idfrom stdin JSON - Track injection state per session in
$CLAUDE_PLUGIN_DATA/sessions/<session_id>/ - On first match: read SKILL.md, return exit 0 with
additionalContextcontaining skill content (10k char limit) - Create marker file so injection is one-time per session
Key findings to include
additionalContextin hook response injects text into agent context without blocking the tool call- No
SkillInvokedhook event exists — cannot detect skill invocation, so direct injection is more reliable iffield uses permission-rule syntax:ToolName(glob-pattern)- Session ID comes via stdin JSON, not env vars
- Marker files under
$CLAUDE_PLUGIN_DATAfor plugin hooks,$XDG_CACHE_HOMEfor standalone hooks
Scope
- The skill itself (SKILL.md)
- Example hook script (shell or python)
- Placement in the
coding/collection
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels