Exercise 02: Restrict a Skill by Path
Create a skill that auto-activates only when the user is working with database migration files. This exercise focuses on the paths field and writing a skill body that enforces structural conventions.
Goal
The skill should:
-
Auto-activate when the user opens, edits, or references a file matching:
migrations/**(any file under a migrations directory)*.sql(any SQL file in the project root)db/migrate/**(Rails-style migration directory)
-
Check migration file naming conventions:
- Timestamp-prefixed format:
YYYYMMDDHHMMSS_description.sql(e.g.,20260513143207_add_user_roles.sql) - Sequential format:
NNNN_description.sql(e.g.,0042_add_user_roles.sql) - Report non-conforming names as a warning
- Timestamp-prefixed format:
-
Warn about potentially dangerous SQL operations:
DROP TABLEwithout a preceding check (likeDROP TABLE IF EXISTS)DELETEwithout aWHEREclauseUPDATEwithout aWHEREclauseTRUNCATEon any table- Column removal (
DROP COLUMN) — flags for attention, not necessarily wrong
-
Look for a rollback or a comment marking the migration as irreversible.
What to write
Create SKILL.md in a new directory. Think through:
- Which
pathspatterns cover all three migration directory conventions above? - Should this be
user-invocable: falseor left as default? - Does this skill need any
allowed-tools? - Should
disable-model-invocationbe set?
Output format
The skill should produce a checklist:
Migration review: 20260513143207_add_user_roles.sql
[ ] Naming convention: PASS / FAIL: <reason>[ ] Rollback present: YES / NO / MARKED IRREVERSIBLE[ ] Dangerous operations: NONE / WARNING: <list each one with line number>Validation
- Create a test migration file with at least one dangerous operation and a non-conforming name.
- Open that file in Claude Code.
- Confirm the skill activates automatically (without you typing
/skill-name). - Confirm the output matches the expected checklist format.
- Also confirm the skill does NOT activate when you open a regular TypeScript or Python file.
Solution
A worked solution is in solutions/02-migration-guard/SKILL.md.