Lesson
Generate Multiple Solutions with Template-Driven Hooks
Load prompt templates from files, inject dynamic values, and generate N structured variations with a single `v(5)` command.
- Access
- Included
- Transcript
- Needs source
Template-driven hooks turn one instruction into multiple structured solutions. Load templates from disk, replace placeholders, and get consistent output formats every time.
The manual variation problem
Getting multiple solutions requires:
- Repeatedly prompting with different angles
- Inconsistent output formats
- Lost context between attempts
Template + hook solution
Store a reusable template with placeholders:
.claude/prompts/variations.md:
Generate $count possible solutions for the following instruction:
Format each solution with this template:
Steps:
1. ...
2. ...
3. ...
Reasoning:
...
Tradeoffs:
...
Instruction: $instruction
Hook to load and fill template:
.claude/hooks/UserPromptSubmit.ts:
import { type UserPromptSubmitHookInput } from "@anthropic-ai/claude-code"
const input = await Bun.stdin.json() as UserPromptSubmitHookInput
// Match v(N) pattern
const match = input.prompt.match(/v\((\d+)\)/)
if (match) {
const count = match[1]
const template = await Bun.file(".claude/prompts/variations.md").text()
// Strip command, keep instruction
const instruction = input.prompt.replace(match[0], "").trim()
// Fill template
const prompt = template
.replace("$count", count)
.replace("$instruction", instruction)
console.log(prompt)
}
Use it
Type your request with the command:
Build a desktop dictation app v(5)
Claude receives the full template with your values filled in, returning 5 structured solutions.
Debug with transcript
View the transformed prompt:
- Press
Ctrl+Oto toggle detailed view - See exactly what Claude received
- Refine templates based on results
Try it
Prompts:
desktop app for capturing dictation v(3)
CLI tool for file organization v(5)