From 96717eb796014dd3909be07dc8981035f1d820ea Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sun, 22 Mar 2026 22:53:40 -0700 Subject: [PATCH] fix: auto-trigger guard in gen-skill-docs.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Inject explicit trigger criteria into every generated skill description to prevent Claude Code from auto-firing skills based on semantic similarity. Generator-only change — templates stay clean. Preserves existing "Use when" and "Proactively suggest" text (both are validated by skill-validation.test.ts trigger phrase tests). Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/gen-skill-docs.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/gen-skill-docs.ts b/scripts/gen-skill-docs.ts index 607f0b04..a9640cdb 100644 --- a/scripts/gen-skill-docs.ts +++ b/scripts/gen-skill-docs.ts @@ -2968,6 +2968,17 @@ function processTemplate(tmplPath: string, host: Host = 'claude'): { outputPath: throw new Error(`Unresolved placeholders in ${relTmplPath}: ${remaining.join(', ')}`); } + // Inject auto-trigger guard into skill descriptions. + // Adds explicit trigger criteria so Claude Code doesn't auto-fire skills + // based on semantic similarity. Preserves existing "Use when" and + // "Proactively suggest" text (both are tested in skill-validation.test.ts). + const triggerGuard = ` MANUAL TRIGGER ONLY: only run this skill when the user explicitly types /${skillName} in their message.\n Do not auto-trigger this skill from semantic similarity alone.\n`; + const descMatch = content.match(/^(description:\s*\|?\s*\n)/m); + if (descMatch && descMatch.index !== undefined) { + const insertAt = descMatch.index + descMatch[0].length; + content = content.slice(0, insertAt) + triggerGuard + content.slice(insertAt); + } + // For codex host: transform frontmatter and replace Claude-specific paths if (host === 'codex') { // Extract hook safety prose BEFORE transforming frontmatter (which strips hooks)