CC-301b · Module 2
Event-Triggered Skills
3 min read
Most skills fire on user prompts — you type a trigger phrase, Claude loads the skill. Event-triggered skills fire on system events: a file is saved, a test fails, a git commit is made, or a build completes. They are the reactive counterpart to prompt-driven skills, and they enable automation patterns that do not require human initiation.
The mechanism is Claude Code hooks. A hook monitors for a specific event — PostToolUse (after Claude edits a file), Stop (after Claude finishes a task), or PreToolUse (before Claude executes a command). When the event fires, the hook runs a script. That script can invoke a skill by writing a message to Claude's input. The chain is: event → hook → script → skill invocation.
The canonical example is a test-on-save skill. A PostToolUse hook detects that Claude edited a .ts file. The hook script checks if a corresponding .test.ts file exists. If it does, the script invokes the test-runner skill, which runs the relevant tests and reports results. If tests fail, the skill feeds the failures back to Claude as a blocking instruction. Claude fixes the code. The hook fires again. The loop continues until tests pass.
Event-triggered skills must be carefully scoped to avoid infinite loops. If a skill triggers on file edits and the skill itself edits files, you get a cycle. The solution is scope guards in the hook: "Only trigger on files in src/, not in .claude/ or node_modules/." "Only trigger on .ts files, not on .json or .md files." "Only trigger once per file per Claude turn, not on every intermediate save." Scope guards are not optional — they are the safety mechanism that prevents event-triggered skills from consuming your entire token budget in a loop.