Skills: Triggers & Auto-Activation

Last updated: 2026-08-31

A good Skill should be like air — there when you need it, out of the way when you don't. Triggers are the "when you need it" switch.


1. Trigger Types

(1) Keyword Trigger

The most common trigger method, matching keywords in user input:

YAML
triggers:
  - keyword: "review|code review"
  - keyword: "debug|troubleshoot"
Match Rule Description Example
Exact Match Exactly equals keyword "deploy"
Fuzzy Match Contains the keyword "review" matches "please review this"
Regex Match Regular expression "fix.*bug"
Multi-Keyword Any match triggers "refactor|restructure"

(2) File Type Trigger

Auto-activates based on the extension or path of files being operated on:

YAML
triggers:
  - file_pattern: "**/*.py"
  - file_pattern: "src/components/**/*.tsx"

(3) Context Condition Trigger

Activates based on project environment or conversation state:

YAML
triggers:
  - context: "git_diff_available"
  - context: "test_failed"
  - context: "has_package_json"

2. Trigger Priority

When multiple Skills match simultaneously, selection follows priority:

TEXT 📖 Display only
Priority from high to low:
1. Manual explicit call (user explicitly requests)
2. Keyword exact match
3. Context condition match
4. File type fuzzy match
5. Default fallback Skill

(1) Priority Configuration

YAML
triggers:
  - keyword: "urgent fix"
    priority: 100
  - keyword: "fix"
    priority: 50

(2) Conflict Resolution

When two Skills compete:

TEXT 📖 Display only
User input: "review this Python file for bugs"

Match results:
├── code-review Skill (keyword: "review") → Priority 80
├── python-review Skill (keyword: "review" + file: *.py) → Priority 90 ✅
└── debug Skill (keyword: "bug") → Priority 70

Result: Select python-review because it matches more precisely

3. Combined Triggers

(1) AND Combination

All conditions must be met simultaneously:

YAML
triggers:
  - and:
      - keyword: "deploy"
      - context: "main_branch"

(2) OR Combination

Any condition being met triggers:

YAML
triggers:
  - or:
      - keyword: "test"
      - file_pattern: "**/*test*.py"

(3) NOT Exclusion

Does not trigger when condition is met:

YAML
triggers:
  - keyword: "refactor"
  - not:
      - context: "production_branch"

4. Trigger Practice

▶ Example: Intelligent Scheduling System

Alice designed an auto-trigger system for the team:

YAML
# .claude/skills/auto-test.md
---
name: auto-test
triggers:
  - and:
      - file_pattern: "src/**/*.py"
      - context: "file_modified"
  - not:
      - file_pattern: "src/**/migrations/**"
---

After modifying Python source files, automatically run tests......

Bob commented: "This system means the team doesn't need to remember which Skill to call — just work normally, and the right support comes automatically."

(1) Common Trigger Scenarios

Scenario Trigger Method Example Skill
Opening certain file types File type Python code review
Before committing code Context condition Pre-commit check
Test failure Context condition Auto-debug
Entering specific commands Keyword Deploy, release
PR creation Context condition Code review

❓ FAQ

Q Can too many keywords cause conflicts?
A Yes. We recommend 1-2 core keywords per Skill, avoiding large-scale overlap. Resolve conflicts with priority and precision.
Q Which context conditions are supported?
A Varies by platform; common ones include: git_diff_available, test_failed, branch_name, file_modified, has_config_file, etc.
Q Can I disable a Skill's auto-trigger?
A Yes, set auto_trigger: false in the configuration; the Skill can then only be called manually.

📖 Summary


📝 Exercises

  1. Basic (⭐): Add two different types of triggers to your previously created code-review Skill.
  2. Intermediate (⭐⭐): Design a combined trigger that automatically runs tests when Python test files are modified, but excludes migration files.
  3. Advanced (⭐⭐⭐): Design a team-level trigger scheduling system that handles priority and conflicts among 5+ Skills.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏