HookStackGitHub
Back to catalogue
ContextUserPromptExpansion

Inject context on skill invocation

Injects skill-specific additional context whenever a slash command expands into a prompt. A configurable map lets you attach focused instructions (security checklist, style guide, domain rules) to specific skills without editing their definition.

Use cases

  • Attach a security checklist automatically when /security-review is invoked
  • Inject the team coding style guide when /code-review runs
  • Pass domain-specific constraints to any skill without modifying its source

Providers & tags

Claude Code
#skills#context#slash-commands#customization

settings.json fragment

{
  "hooks": {
    "UserPromptExpansion": [
      {
        "hooks": [
          {
            "command": "node $CLAUDE_PROJECT_DIR/.claude/hooks/user-prompt-expansion-skill-context.mjs",
            "type": "command"
          }
        ]
      }
    ]
  }
}

Script · .claude/hooks/user-prompt-expansion-skill-context.mjs

#!/usr/bin/env node
// Injecte du contexte additionnel lors de l'expansion de certains skills (UserPromptExpansion)
import { readFileSync } from 'fs';
import { fileURLToPath } from 'url';

// Associe un nom de skill au contexte à injecter
const CONTEXT_MAP = {
  'code-review': 'Check for security vulnerabilities, adherence to SOLID principles, and the conventions in CLAUDE.md.',
  'security-review': 'Follow OWASP Top 10. Flag hardcoded secrets, injection risks, and insecure dependencies.',
};

export function run(input) {
  const skill = input.command_name ?? '';
  const ctx = CONTEXT_MAP[skill];
  if (!ctx) return null;
  return {
    hookSpecificOutput: {
      hookEventName: 'UserPromptExpansion',
      additionalContext: ctx,
    },
  };
}

/* v8 ignore next 5 */
if (process.argv[1] === fileURLToPath(import.meta.url)) {
  const input = JSON.parse(readFileSync(0, 'utf8'));
  const result = run(input);
  if (result) process.stdout.write(JSON.stringify(result));
}