Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Claude Code agentic coding tool — terminal-based assistant for coding, git workflows, and codebase understanding.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/triggering-examples.md
1# Agent Triggering Examples: Best Practices23Complete guide to writing effective `<example>` blocks in agent descriptions for reliable triggering.45## Example Block Format67The standard format for triggering examples:89```markdown10<example>11Context: [Describe the situation - what led to this interaction]12user: "[Exact user message or request]"13assistant: "[How Claude should respond before triggering]"14<commentary>15[Explanation of why this agent should be triggered in this scenario]16</commentary>17assistant: "[How Claude triggers the agent - usually 'I'll use the [agent-name] agent...']"18</example>19```2021## Anatomy of a Good Example2223### Context2425**Purpose:** Set the scene - what happened before the user's message2627**Good contexts:**28```29Context: User just implemented a new authentication feature30Context: User has created a PR and wants it reviewed31Context: User is debugging a test failure32Context: After writing several functions without documentation33```3435**Bad contexts:**36```37Context: User needs help (too vague)38Context: Normal usage (not specific)39```4041### User Message4243**Purpose:** Show the exact phrasing that should trigger the agent4445**Good user messages:**46```47user: "I've added the OAuth flow, can you check it?"48user: "Review PR #123"49user: "Why is this test failing?"50user: "Add docs for these functions"51```5253**Vary the phrasing:**54Include multiple examples with different phrasings for the same intent:55```56Example 1: user: "Review my code"57Example 2: user: "Can you check this implementation?"58Example 3: user: "Look over my changes"59```6061### Assistant Response (Before Triggering)6263**Purpose:** Show what Claude says before launching the agent6465**Good responses:**66```67assistant: "I'll analyze your OAuth implementation."68assistant: "Let me review that PR for you."69assistant: "I'll investigate the test failure."70```7172**Proactive example:**73```74assistant: "Great! Now let me review the code quality."75<commentary>76Code was just written, proactively trigger review agent.77</commentary>78```7980### Commentary8182**Purpose:** Explain the reasoning - WHY this agent should trigger8384**Good commentary:**85```86<commentary>87User explicitly requested code review, trigger the code-reviewer agent.88</commentary>8990<commentary>91After code implementation, proactively use review agent to check quality.92</commentary>9394<commentary>95PR analysis request matches pr-analyzer agent's expertise.96</commentary>97```9899**Include decision logic:**100```101<commentary>102User wrote tests (Test tool used). The test-analyzer agent should check103test quality and coverage before continuing.104</commentary>105```106107### Assistant Response (Triggering)108109**Purpose:** Show how Claude invokes the agent110111**Standard pattern:**112```113assistant: "I'll use the [agent-name] agent to [what it will do]."114```115116**Examples:**117```118assistant: "I'll use the code-reviewer agent to analyze the changes."119assistant: "Let me use the test-generator agent to create comprehensive tests."120assistant: "I'll use the security-analyzer agent to check for vulnerabilities."121```122123## Example Types124125### Type 1: Explicit Request126127User directly asks for what the agent does:128129```markdown130<example>131Context: User explicitly requests security analysis132user: "Check my code for security vulnerabilities"133assistant: "I'll use the security-analyzer agent to perform a thorough security review."134<commentary>135Direct security analysis request triggers the security-analyzer agent.136</commentary>137</example>138```139140### Type 2: Proactive Triggering141142Agent triggers after relevant work without explicit request:143144```markdown145<example>146Context: User just implemented database queries147user: "I've added the user search functionality"148assistant: "Great! Let me review it for security."149<commentary>150Database code written. Proactively trigger security-analyzer to check151for SQL injection and other database security issues.152</commentary>153assistant: "I'll use the security-analyzer agent to check the database code."154</example>155```156157### Type 3: Implicit Request158159User implies need without stating it directly:160161```markdown162<example>163Context: User mentions code is hard to understand164user: "This code is confusing and hard to follow"165assistant: "I can help improve the code clarity."166<commentary>167User indicates complexity issues. Trigger code-simplifier agent to refactor168for better readability.169</commentary>170assistant: "I'll use the code-simplifier agent to suggest improvements."171</example>172```173174### Type 4: Tool Usage Pattern175176Agent triggers based on prior tool usage:177178```markdown179<example>180Context: User made multiple edits to test files181user: "I've updated all the tests"182assistant: "Great! Let me verify test quality."183<commentary>184Multiple Edit tools used on test files. Proactively trigger test-quality-analyzer185to ensure tests follow best practices.186</commentary>187assistant: "I'll use the test-quality-analyzer agent to review the tests."188</example>189```190191## Multiple Examples Strategy192193### Cover Different Phrasings194195```markdown196<example>197user: "Review my code"198[...]199</example>200201<example>202user: "Can you check my implementation?"203[...]204</example>205206<example>207user: "Look over these changes"208[...]209</example>210```211212### Cover Proactive and Reactive213214```markdown215<example>216Context: User explicitly requests review217user: "Review my code for issues"218[...]219</example>220221<example>222Context: After user writes code223user: "I've implemented the feature"224assistant: "Great! Now let me review it."225<commentary>226Code written, proactively review.227</commentary>228[...]229</example>230```231232### Cover Edge Cases233234```markdown235<example>236Context: Typical usage237user: "Check my PR"238[...]239</example>240241<example>242Context: Large PR that needs thorough analysis243user: "This is a big PR, can you do a deep review?"244[...]245<commentary>246Large PR mentioned, use thorough analysis mode.247</commentary>248</example>249```250251## Common Mistakes252253### ❌ Missing Context254255```markdown256<example>257user: "Review my code"258assistant: "I'll use the code-reviewer agent."259</example>260```261262**Why bad:** No context about what led to this request.263264### ✅ With Context265266```markdown267<example>268Context: User just finished implementing authentication269user: "Review my code"270assistant: "I'll use the code-reviewer agent to analyze the auth implementation."271<commentary>272Auth code written, review for security and best practices.273</commentary>274</example>275```276277### ❌ No Commentary278279```markdown280<example>281Context: User requests review282user: "Check my changes"283assistant: "I'll use the reviewer agent."284</example>285```286287**Why bad:** Doesn't explain WHY agent triggers.288289### ✅ With Commentary290291```markdown292<example>293Context: User requests review after making changes294user: "Check my changes"295assistant: "I'll use the code-reviewer agent to analyze the modifications."296<commentary>297Code review request triggers agent to check quality, security, and adherence to standards.298</commentary>299</example>300```301302### ❌ Agent Responds Directly303304```markdown305<example>306user: "Review my code"307assistant: "I found the following issues: [lists issues]"308</example>309```310311**Why bad:** Shows agent's output, not triggering.312313### ✅ Shows Triggering314315```markdown316<example>317user: "Review my code"318assistant: "I'll use the code-reviewer agent to perform the review."319<commentary>320Review request triggers the agent.321</commentary>322</example>323```324325## How Many Examples?326327### Minimum: 2 Examples328329Cover at least:3301. Explicit request3312. One variation or proactive trigger332333### Recommended: 3-4 Examples334335Cover:3361. Explicit request (direct ask)3372. Implicit request (user implies need)3383. Proactive trigger (after relevant work)3394. Edge case or specific scenario340341### Maximum: 6 Examples342343More than 6 makes description too long. Focus on most important scenarios.344345## Template Library346347### Code Review Agent348349```markdown350<example>351Context: User just implemented a new feature352user: "I've added the user registration feature"353assistant: "Great! Let me review the code quality."354<commentary>355Code written, proactively trigger code-reviewer agent.356</commentary>357assistant: "I'll use the code-reviewer agent to analyze the implementation."358</example>359360<example>361Context: User explicitly requests review362user: "Can you review my changes for issues?"363assistant: "I'll use the code-reviewer agent to perform a thorough review."364<commentary>365Explicit review request triggers the agent.366</commentary>367</example>368```369370### Test Generation Agent371372```markdown373<example>374Context: User implemented functions without tests375user: "I've added the data processing functions"376assistant: "Great! Let me generate tests for these."377<commentary>378New code without tests, proactively trigger test-generator agent.379</commentary>380assistant: "I'll use the test-generator agent to create comprehensive tests."381</example>382383<example>384Context: User explicitly asks for tests385user: "Generate tests for my code"386assistant: "I'll use the test-generator agent to create a complete test suite."387<commentary>388Direct test generation request triggers the agent.389</commentary>390</example>391```392393### Documentation Agent394395```markdown396<example>397Context: User added new API endpoints398user: "I've implemented the REST API endpoints"399assistant: "I'll document these endpoints."400<commentary>401New API code, proactively generate documentation.402</commentary>403assistant: "I'll use the api-docs-writer agent to create comprehensive documentation."404</example>405406<example>407Context: User requests documentation408user: "Write docs for this API"409assistant: "I'll use the api-docs-writer agent to generate clear documentation."410<commentary>411Documentation request triggers the agent.412</commentary>413</example>414```415416### Validation Agent417418```markdown419<example>420Context: User ready to commit changes421user: "I'm ready to commit this code"422assistant: "Let me validate it first."423<commentary>424Before commit, proactively validate with validation-agent.425</commentary>426assistant: "I'll use the code-validator agent to check for issues."427</example>428429<example>430Context: User asks for validation431user: "Validate my implementation"432assistant: "I'll use the code-validator agent to verify correctness."433<commentary>434Explicit validation request triggers the agent.435</commentary>436</example>437```438439## Debugging Triggering Issues440441### Agent Not Triggering442443**Check:**4441. Examples include relevant keywords from user message4452. Context matches actual usage scenarios4463. Commentary explains triggering logic clearly4474. Assistant shows use of Agent tool in examples448449**Fix:**450Add more examples covering different phrasings.451452### Agent Triggers Too Often453454**Check:**4551. Examples are too broad or generic4562. Triggering conditions overlap with other agents4573. Commentary doesn't distinguish when NOT to use458459**Fix:**460Make examples more specific, add negative examples.461462### Agent Triggers in Wrong Scenarios463464**Check:**4651. Examples don't match actual intended use4662. Commentary suggests inappropriate triggering467468**Fix:**469Revise examples to show only correct triggering scenarios.470471## Best Practices Summary472473✅ **DO:**474- Include 2-4 concrete, specific examples475- Show both explicit and proactive triggering476- Provide clear context for each example477- Explain reasoning in commentary478- Vary user message phrasing479- Show Claude using Agent tool480481❌ **DON'T:**482- Use generic, vague examples483- Omit context or commentary484- Show only one type of triggering485- Skip the agent invocation step486- Make examples too similar487- Forget to explain why agent triggers488489## Conclusion490491Well-crafted examples are crucial for reliable agent triggering. Invest time in creating diverse, specific examples that clearly demonstrate when and why the agent should be used.492