kylesnowschwartz/prompt-intercept-pattern

20 stars · Last commit 2026-03-31

Claude Code plugin pattern: hook-intercepted commands that run code without an API call

README preview

# Prompt Intercept Pattern

A Claude Code plugin that demonstrates **hook-intercepted commands** — slash commands that run code without consuming an API turn.

![Demo of the prompt intercept pattern](prompt-intercept-pattern.png)

## The pattern

Normal slash commands send their content to Claude as a prompt. This pattern short-circuits that: a `UserPromptSubmit` hook intercepts the prompt, runs your code, and blocks the API call. Claude never sees it.

Three pieces:

1. **Stub command** (`commands/prompt-intercept-pattern.md`) — registers the command in `/help` with autocomplete. `disable-model-invocation: true` prevents programmatic invocation. The file body is never sent to Claude.
2. **Hook config** (`hooks/hooks.json`) — wires `UserPromptSubmit` to the bash script.
3. **Hook script** (`hooks/user_prompt_submit.sh`) — matches the command, does work, outputs `{"decision":"block","reason":"message for user"}`.

```
prompt-intercept-pattern/
├── .claude-plugin/
│   └── plugin.json

View full repository on GitHub →