Skip to content
hook-intercept-block logo

Hook-Intercept-Block Pattern

hook-intercept-block

This skill should be used when implementing slash commands that execute without Claude API calls. Use when: adding a new /bumper-* command, understanding why commands return "block" responses, debugging UserPromptSubmit hooks, or learning the pattern for instant command execution. Keywords: UserP...

SKILL.md

Full skill instructions

Hook-Intercept-Block Pattern

Pattern for implementing slash commands that execute entirely in the hook handler, bypassing the Claude API call entirely.

Why Use This Pattern

  • No API cost: Commands execute in Go, no Claude API call
  • Faster: Direct execution vs markdown parsing + API round trip
  • Deterministic: No model variance - same input, same output

How It Works

User types: /​bumper-reset
    ↓
UserPromptSubmit hook fires
    ↓
prompt_handler.go matches regex: ^/(?:claude-bumper-lanes:)?bumper-reset\s*$
    ↓
handleReset() executes Go logic
    ↓
Returns JSON to stdout: {"decision":"block","reason":"Baseline reset. Score: 0/​400"}
    ↓
Claude Code shows "reason" to user, skips API call

The Confusing Naming

Claude Code's hook response API uses counterintuitive terminology:

ResponseWhat It Actually Means
decision: "block""I handled this, don't call Claude API" (NOT "blocked/​rejected")
decision: "continue""Let it through to Claude API"
reason: "..."Message shown to user (only with "block")

Key insight: block = "handled and done", not "rejected". The command succeeded.

Implementation Components

  1. Hook config (hooks.json): Routes UserPromptSubmit to handler binary
  2. Handler (internal/​hooks/​prompt_handler.go): Regex matching + dispatch
  3. Command stubs (commands/​*.md): MUST exist for /​help discovery (body ignored)

Adding a New Command

Step 1: Add Regex Pattern

In prompt_handler.go:

var newCmdPattern = regexp.MustCompile(`^/(?:claude-bumper-lanes:)?bumper-foo\s*(.*)$`)

The (?:claude-bumper-lanes:)? makes the plugin namespace optional.

Step 2: Add Dispatch

In HandlePrompt():

if m := newCmdPattern.FindStringSubmatch(prompt); m != nil {
    return handleFoo(sessionID, strings.TrimSpace(m[1]))
}

Step 3: Implement Handler

Use the helper functions for DRY session management:

func handleFoo(sessionID, args string) int {
    sess := loadSessionOrBlock(sessionID)
    if sess == nil {
        return 0
    }

    // ... your logic here ...

    if !saveOrBlock(sess) {
        return 0
    }

    blockPrompt("Success message")
    return 0
}

Step 4: Create Command Stub

Create commands/​bumper-foo.md:

---
description: Does the foo thing
argument-hint: <optional-args>
---

This command is handled by the hook system.

The markdown body is ignored - the hook handles everything. The file MUST exist for the command to appear in /​help.

Step 5: Rebuild

just build-bumper-lanes

Helper Functions

Two helpers reduce boilerplate:

loadSessionOrBlock

func loadSessionOrBlock(sessionID string) *state.SessionState

Returns session state or nil. If nil, error already shown to user via blockPrompt().

saveOrBlock

func saveOrBlock(sess *state.SessionState) bool

Returns true on success. If false, error already shown to user via blockPrompt().

JSON Response Format

The UserPromptResponse struct:

type UserPromptResponse struct {
    Decision string `json:"decision,omitempty"`
    Reason   string `json:"reason,omitempty"`
}

Output via blockPrompt():

func blockPrompt(reason string) {
    resp := UserPromptResponse{
        Decision: "block",
        Reason:   reason,
    }
    out, _ := json.Marshal(resp)
    fmt.Println(string(out))
}

Existing Commands Using This Pattern

All bumper-lanes slash commands use hook-intercept-block:

CommandHandlerPurpose
/​bumper-resethandleReset()Capture new baseline, reset score
/​bumper-pausehandlePause()Disable enforcement
/​bumper-resumehandleResume()Re-enable enforcement
/​bumper-viewhandleView()Set/​show visualization mode
/​bumper-confighandleConfig()Show/​set threshold

Debugging Tips

  1. Command not recognized: Check regex pattern matches user input exactly
  2. No output shown: Ensure blockPrompt() is called and JSON printed to stdout
  3. Command not in /​help: Verify commands/​*.md stub file exists
  4. Binary not updated: Run just build-bumper-lanes after changes

More Other skills

Delegate independent tasks to specialized agents working concurrently with isolated context.

295.4K 206.3K
View

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

179.7K 100.1K
View

Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.

179.7K 89.5K
View

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

179.7K 76.1K
View

Fundamental design principles for writing maintainable, testable Python code.

40.2K 21.9K
View

Modern responsive layouts using container queries, fluid typography, CSS Grid, and mobile-first strategies.

40.2K 20K
View

Generate Playwright tests from scenarios using interactive browser exploration and validation.

39.7K 18.2K
View

Modern React state management with Redux Toolkit, Zustand, Jotai, and React Query for every state category.

40.2K 14.7K
View

GDPR-compliant data handling with consent management, data subject rights, and privacy controls.

40.2K 14.3K
View

Python error handling patterns including input validation, exception hierarchies, and partial failure handling. Use when implementing validation logic, designing exception strategies, handling batch processing failures, or building robust APIs.

40.2K 13.5K
View

Detailed multi-file refactor planning with safety checks and rollback guidance.

39.7K 13K
View