published · 6 min read

Should a Hook Force Your Coding Agent to Use a Tool?

How Azdaja's Claude Code hook went from denying the agent's tools to staying off unless a human arms it.

The tool names Read, Grep, Bash, Agent, Task and Skill in large type, each struck through, above the words denied: a skill monopoly.

An AI agent drafted this from my projects, and another agent checked the draft claim by claim against the code and the run records or briefs that were kept. The projects and opinions are mine.

My project Azdaja, a recursive language model layer for coding agents, gives an agent a Python workspace that keeps its variables between steps, for big, exhaustive tasks: label all the records in a large export, judge all the clauses in a hundred contracts. That raises a problem a lot of tool builders will recognise: how do you get the agent to use it? From v0.1.2, Azdaja forced it with a Claude Code hook that, on prompts it judged exhaustive, denied the agent broad Read and Bash access to a large input until it loaded the Azdaja skill. This post is how that hook went from denying tools to staying off unless a human arms it.

The reason to want the agent using Azdaja at all: in a five-pair test in Claude Code on Haiku, where the Azdaja arm could only run one fixed script that already picked out the records that mattered, the Azdaja arm's median uncached tokens were 15.8% lower than the native arm's and its median time about half. That test had no hook and no choice in it. The agent's default approach keeps pulling search output and excerpts into the conversation, and on big jobs that history gets expensive.

Version one: make it the only way

Claude Code has hooks, small programs that run before and after an agent's tool calls and can allow or deny them. Azdaja's first Claude Code integration was just a skill. The v0.1.2 hook ran its own keyword check on prompts as they came in. If a prompt looked like a big, exhaustive task, it let the agent take one small look at the large input (up to 10 lines and 64 KiB) and denied broader Read and Bash access to it until the agent loaded the Azdaja skill. After the skill loaded it went further: every Read, Grep, Bash, Agent, Task or Skill call except a single managed Azdaja transaction was denied, and the hook remembered the skill as loaded for the rest of the session. A comment in my repo still names that design: a skill monopoly. I have no record of a real session reaching it: the hook switched it on only on the Skill tool's "after" event, and in the one Claude Code version I captured, that event never came (more on that below). Under that version, an agent given a flagged prompt about a large input would have been denied, told to load the skill, and denied again.

On paper, the design guaranteed the agent went through Azdaja. In practice, a hook that decides a task is "exhaustive" and starts denying tools will eventually decide wrong. And by design, once the hook saw the skill load, the agent couldn't read even a small file or recover from a failed step with normal tools until a prompt the keyword check didn't flag. Scott Spence's How to Make Claude Code Skills Activate Reliably tested a softer hook, one that only injects text and never denies tools: his forced-eval hook reached 84% activation against 20% for his simple variant, in synthetic API calls on Haiku 4.5. Run later against the real Claude Code binary on Sonnet 4.5, the same hook reached 100% (22 of 22, twice), against 55% and then 50% with no hook.

The evidence that optional tools go unused

Some of the evidence came in around the time my hook first shipped, and some came later. In one benchmark attempt on Codex and OpenCode, with the skill merely available, the Azdaja arms made zero inner model calls and returned no usable answer. Weeks later, after the design below had already shipped, a long contract-review run never once called a second capability I'd made available. Vercel's agent evals found this pattern too: a skill went uninvoked in 56% of cases, skills reached a 79% pass rate with explicit instructions, and an 8KB docs index in AGENTS.md, present on every turn, reached 100%. Forcing doesn't remove the failure; it moves it into the hook, where a wrong guess or a bug blocks the agent instead of just leaving a tool unused. Claude Code's hooks guide starts from the other side: it offers hooks so that certain actions always happen, without relying on the model to choose them.

Version two: off unless a human arms it

Over three releases in three days in mid-September, the design turned around. v0.1.15 did it for another agent host first: hooks inactive unless the host process sets an activation variable. Loading the skill, or just mentioning Azdaja, doesn't count. v0.1.16 did the same for Claude Code and stopped the hook blocking ordinary follow-up work. It acts only when AZDAJA_CLAUDE_ACTIVATION is set to request, session or repository. A new prompt clears leftover state, so an interrupted task is recovered by the next message instead of a timeout. Harmless operations like a plain file copy stay allowed even mid-task.

In the Claude Code hook, the three values behave the same. You get the scope from where you set the variable, which can be a single Claude Code run, a shell session, or a repository through something like direnv.

That doesn't remove the guessing entirely. Inside an armed scope, the hook's keyword check still picks which prompts count as exhaustive, and the model still has to call the skill. What's changed is that a human decided the hook should be armed at all.

Two flows side by side. Version one runs from the keyword check to every tool denied. Version two first asks whether a human set the activation variable, and if not, the hook is off.
The moving markers are illustrations and don't come from a recorded session.

The hook refused its own instructions

Then a live session turned up a bug. With the integration armed, Claude loaded the skill and ran the wrapper script exactly as the skill's own instructions wrote it, and the hook rejected it. The skill rendered the binary as a quoted literal path on every line, and the hook's recogniser only accepted a form that assigned the binary to a variable first. Two halves of my project disagreed about what a valid call looked like, and Claude was caught in the middle: told to retry, then denied again. Those two halves had disagreed for about three weeks before a real session caught it.

Claude sits between the skill's instructions and the hook's recogniser, running the call and being denied in a loop, until the recogniser changes to accept both forms.
The laps are not a count of real retries.

And there was a second problem: in the session I captured (Claude Code 2.1.273), my hook got a "before" event for the Skill tool and never an "after" one, though Claude Code's hooks reference says both fire on every tool call. The hook only marked the skill active on the "after" event, so even a correctly formed call didn't have anything to attach to.

v0.1.17 fixed both. Now the recogniser accepts both forms, still strictly: the exact binary, fixed lifecycle lines, one input, one final answer, nothing appended. Routing now activates on the skill call itself. And the test suite replays that session's event order and payload shapes, with stand-in IDs, through the installed hook command, end to end. If you write agent hooks, release the restriction when a managed step fails, so the agent can recover with its normal tools, and make your instructions and your enforcement the same artifact, or test them against each other.

Turning the hook on

curl -fsSL https://azdaja.dev/install | sh -s -- claude
AZDAJA_CLAUDE_ACTIVATION=request claude   # arms the hook for this Claude Code run only

Use export in a shell, or direnv in a repository, for a wider scope, then run the doctor command the installer prints. Azdaja is free and MIT licensed.

Source and setup: https://github.com/kubet/azdaja