Skip to content
sinc-LLMBook a 30-minute call

Engineering reference

A Practical Prompt Hook for Claude Workflows

A first-person account of building a prompt hook, the problem it addressed, and a failure the author had to resolve.

Methods, definitions, and examples for the topic discussed here. Check applicability against the task and operating conditions.

Mario Alexandre  ·  March 26, 2026  ·  token-savings auto-scatter claude-code

I built a hook that receives Claude prompts before execution, structures them as JSON, and injects the structured result as context.

I know that sounds like a clickbait headline. It is not. I will show you the exact numbers. I will show you how the hook works and why it works. Then I will give you the code for free.

Cost review
saved in 7 days — from $2,597.96 projected to $967.01 actual

I run a big Claude Code setup. It uses multi-agent pipelines, vault memory, and tool calls. My token bills were getting very high. I was not doing anything obviously wrong. The problem was harder to see than that.

To measure clarification overhead, count user prompts and assistant responses separately, then inspect why extra responses occurred. Distinguish necessary questions from misunderstandings, corrections and tool-related output.

That back-and-forth costs a lot of money. Every exchange burns tokens on both sides. I ran 21,194 prompts in one week. At that scale, those extra rounds add up to a huge bill.

What I Built

I built what I call an auto-scatter hook. It is a small Python server that sits between me and Claude. Every prompt I type is caught by the hook. The hook sends it to Claude Haiku (the cheap model). Claude Haiku breaks it into 6 structured frequency bands. Then that structured JSON is injected as system context before the main Claude model ever sees my original message.

sinc-LLM signal formula
x(t) = Σ x(nT) · sinc((t - nT) / T)

The six fields state the role, context, supplied data, rules, output structure, and task.

Here is what I measured over 7 days:

Compare baseline and revised responses per prompt, API token use, and total operating costs for the same workload.

Include Haiku scatter calls and main-model calls in the same cost comparison. Record token usage and the applicable provider rates.

Total tokens in 7 days: 7.14 billion. Output tokens alone: 12.9 million. Output tokens are the expensive ones. Scatter cut the wasted output tokens by a large amount.

Why It Works

Here is the key idea. When you send a raw prompt like "fix the auth bug", the model has to figure out many things on its own: who you are, what context you are working in, what data matters, what constraints apply, what format you want, and what the actual task is. If it gets any of those wrong, it asks a clarifying question. You answer. It asks another. You answer again. This keeps going.

The auto-scatter hook does that sorting work upfront for $0.002. It reads your raw prompt and figures out all 6 bands. It hands the model a complete, structured picture before the model starts generating. The model just does the task. No back-and-forth needed.

The Catch-22 I Had to Solve

There was a funny problem early on. The hook was catching every prompt, including the prompts I used to debug the hook itself. When I typed "fix the hook", the hook would catch it and misread it. I ended up in a strange loop where the tool fixing itself was being broken by itself.

I fixed it with a pass-through rule. If the input is already valid sinc JSON (it has the formula, the T field, and the fragments array), the hook does not scatter it. It passes it straight through. That way I could write raw sinc JSON to talk directly to the model when I needed to skip the hook.

I open-sourced the scatter server, hook code, and sinc format specification. Leave a comment for the link. The article also describes a local Qwen2.5-based 7B model and GGUF export.

Evaluate setup time, operating costs, and output checks for your workflow before deciding whether to use the hook.

// Production AI Engineering

Build AI systems that hold up in production.

sinc-LLM designs, audits, and stabilises production AI infrastructure: from vendor evaluation and cost accountability to incident controls and MCP architecture.

See what we do →
Scope and context

sinc-LLM About Blog Services

DOI: 10.5281/zenodo.19152668 · © 2026 sinc-LLM · Mario Alexandre