DEV Community

Cover image for I asked AI for a Claude Code mod that enforces a rule. It only put the rule on screen
uehara
uehara

Posted on

I asked AI for a Claude Code mod that enforces a rule. It only put the rule on screen

The mod passed claude plugin validate, passed its test, and showed "approval: not yet" in Claude Code while Claude worked. It also had no code that could stop a save.

We had asked one of the AI workers in our company's AI office for a mod that holds a save until a person approves it. This is what came back, why every check passed anyway, and the mod that actually refuses.

The short version

  • What we got was a label. The mod hooked only ui.render, the hook that runs when part of the screen is drawn. Nothing in it could refuse an action.
  • Changing the screen and refusing an action are written separately. Refusing happens in tool.call, the hook that runs right before Claude uses a tool, by returning deny.
  • Rebuilt that way, the rule held. Without the approval mark, the save was refused. With it, the same request went through.

The request, and what came back

When an AI does the work, some actions, like saving a draft or sending something, should wait for a person to approve them. So the request was simple: a mod that does not let draft.md be saved until it is approved.

The report that came back said validation passed and the test passed. The mod itself, apart from its test, was three files: plugin.json, hooks/hooks.json and hooks/register.js. Here is all of register.js:

Terminal showing hooks/register.js (output text as is, redrawn as a terminal image). The register function hooks ui.render for the Spinner component, keeps the original props, and appends " · target: sample draft / action: save / approval: not yet" as the suffix before passing the event on with next.

Every time Claude Code draws its spinner, the mod appends a fixed label. That is the whole mod. It does not read the real target or the real approval state, and nothing in it touches a save.

Why every check still passed

Validation listed exactly what it does

Output of claude plugin validate (text as is, the sample folder path replaced with /work/review-mod, plugin directory check lines omitted). One warning for plugin.json: "author: No author information provided". For hooks.json: "./register.js hooks: ui.render{component=Spinner}" and "./register.js calls: nothing on $". It ends with "Validation passed with warnings" and exit code 0.

Validation does not judge whether a mod does what you asked. It lists what the mod handles and what it asks Claude Code to do. Here that was one event, the spinner render, and no calls at all. A hook cannot do anything outside its own code except through the mods API, which is why this list is complete. Nothing on it could refuse a save. The answer was in the output; it just was not a failure.

The test checked the label

Output of claude plugin test (text as is). tests/review.test.ts: "(pass) the display handler keeps the original props", 1 pass, 0 fail, Ran 1 test across 1 file. Exit code 0.

The test hands the handler a spinner with label: 'working' and checks that the label survives and the suffix says "not yet". As the testing docs describe, a test runs without a session, a sign-in or a network. It tells you what the handler returns.

The screen showed the label

We then loaded the mod with --plugin-dir and sent a prompt that takes a few seconds:

Claude Code in a terminal right after sending a prompt with the mod loaded (terminal text copied as is and redrawn; notices from other plugins and local settings omitted). Under the prompt "Without using any tools, write the English words for the numbers one to three hundred, separated by commas." the spinner reads "· Generating · target: sample draft / action: save / approval: not yet". The input box is below.

"Generating" is Claude Code's own spinner word. Everything after it is the mod. Three checks, three passes, and the rule was still only written on the screen.

Drawing and refusing are different hooks

Mods are plugins made of JavaScript or TypeScript handlers that Claude Code calls at set moments (overview). The interface docs list what a mod can draw: a band above the prompt, a pane beside the transcript, a status line, or changes to parts Claude Code draws itself, such as the spinner. To show that side on its own, here is an even smaller mod that adds one row above the prompt:

The area around the Claude Code prompt before and after loading a mod (terminal text copied as is and redrawn; the logo lines and local settings omitted). In "Without the mod", only the prompt sits between the divider lines. In "With the mod", a row reading "[check] target: sample draft / action: save / approval: not yet" sits right above the prompt.

The screen changes. Whether Claude uses a tool does not. Claude does not read the label and wait. Whether a save pauses depends on Claude Code's own permission settings, not on a row that says "approval: not yet".

A hook can observe an event, rewrite it, or answer it so the usual behavior does not run. Adding text to the spinner is a rewrite. Refusing a save is an answer, and it has to happen on the tool side:

  • tool.call runs right before Claude uses a tool. Returning { deny: reason } stops that tool (events docs).
  • tool.check runs later, when Claude Code decides whether the call may run, and can also return deny (reference).

So "show the approval state" is a ui.render job, and "do not save without approval" is a tool.call or tool.check job. We had asked for the second and received the first.

A mod that actually refuses: approval-gate

We built a sample that does the second job. Until a file named draft.approved sits in the same folder as draft.md, it refuses to save draft.md. Here is the whole module:

Terminal showing hooks/register.ts of the sample mod approval-gate (output text as is, redrawn as a terminal image). It sets the target to draft.md and the mark to draft.approved, and registers tool.call hooks for Write, Edit and Bash. For Write and Edit, if the file is draft.md and draft.approved is missing from its folder, it returns deny with "approval-gate: draft.md is not approved yet. It will not be saved until draft.approved is in place."; otherwise it calls next. For Bash, a command that names draft.md is refused while the working folder has no mark. Every hook has a .catch that returns deny with "the approval could not be checked, so nothing is saved."

Three choices matter:

  • Cover every way to write. Write and Edit are not the only way Claude writes a file; a Bash command can too. Any Bash command that names draft.md is refused while there is no mark, even one that only reads. It matches by name, so a command that writes without naming the file is outside what it checks.
  • Refuse when unsure. If checking for the mark throws, .catch refuses with "the approval could not be checked". A failure never turns into a save.
  • Leave everything else alone. Other files save without a mark.

Its checks look different

Output of claude plugin validate for approval-gate (text as is, the folder path is /work/approval-gate, plugin directory check lines omitted). One author warning for plugin.json. For hooks.json: "./register.ts hooks: tool.call{tool=Write}, tool.call{tool=Edit}, tool.call{tool=Bash}", three "gating hook with .catch" lines for Write, Edit and Bash, and "./register.ts calls: $.fs.exists". It ends with "Validation passed with warnings" and exit code 0.

Compare this with the first mod. The hooks are now tool.call for Write, Edit and Bash, not ui.render. The three "gating hook with .catch" lines say each hook that can stop an action has a failure handler. The only call is $.fs.exists, to look for the mark.

Output of claude plugin test for approval-gate (text as is). tests/gate.test.ts with four passes: "refuses to save draft.md while there is no approval mark", "saves once the approval mark is in place", "the Bash way around draft.md is refused too while there is no mark", "files other than draft.md save without a mark". 4 pass, 0 fail, Ran 4 tests across 1 file. Exit code 0.

Four tests, one each for refusing, allowing, the Bash route, and files outside the rule.

Refused without the mark, saved with it

Finally, a live session with approval-gate loaded, in a folder that has draft.md and no mark yet:

Claude Code after asking it to save before the approval mark is in place (terminal text copied as is and redrawn; notices from other plugins and the rest of the reply omitted). For the request to add "TODO: describe the feature." to the end of draft.md, the Update(draft.md) row shows "Error: approval-gate: draft.md is not approved yet. It will not be saved until draft.approved is in place." Claude's reply starts "Conclusion: draft.md has not changed", explains what it tried, and says it could create draft.approved itself but that would get around the check, so it left it alone.

Claude tried an Edit, and the mod refused it on the spot with the reason written in the module. Then, in the same session, a person put draft.approved next to draft.md and asked again:

The same request after the approval mark is in place (terminal text copied as is and redrawn; notices from other plugins and the rest of the reply omitted). Update(draft.md) shows "Added 2 lines": a blank line 4 and "TODO: describe the feature." as line 5. The reply starts "Conclusion: the line is in and draft.md is saved".

No approval, no save. Approval, save. That is the rule we asked for, held by the tool side rather than written on the screen.

In this sample the mark is just a file, and as Claude's own reply in the refused screen says, it could create that file itself. For real work, put the approval somewhere the AI cannot write, or tie it to a record of who approved.

Ask for the two things separately

What was checked Tool Display-only mod approval-gate
What it handles claude plugin validate ui.render only tool.call on Write, Edit, Bash
Handler input and output claude plugin test 1 pass (the label) 4 pass (refuse, allow, Bash route, other files)
What people see Load it into Claude Code The label The refusal reason
Whether the action waits Ask for a save with no approval No code to stop it Refused, then saved once approved

When you ask an AI for a guard, write "show the state" and "refuse the action" as two separate items, and check them separately. If validation lists no tool.call or tool.check hook, the mod cannot refuse anything, however good its screen looks.

Terms

  • Claude Code: Anthropic's tool for handing programming work to an AI.
  • Mod: a Claude Code plugin made of JavaScript or TypeScript handlers that change how Claude Code looks and behaves (how to create one).
  • Hook: a handler Claude Code calls at a set moment. This article uses ui.render (drawing part of the interface), tool.call (right before Claude uses a tool), and tool.check (when Claude Code decides whether a tool call may run).
  • deny: the answer a hook returns to stop a tool. The reason text shows up for Claude and on the screen.
  • AI office: the group of AI workers our company runs. The blog worker built the first mod and ran its first two checks.

Articles on ELN workflow — our in-house plugin suite that enforces AI development quality — will continue as a series. If you are interested, please like and follow.

Our products: https://www.eln.ne.jp/products


EarthLink Network builds its own products to run the whole company on AI — each one born from a need along the way. See the full index of what we build:

→ The 18 products EarthLink Network builds in-house

For more about the company and each product, visit www.eln.ne.jp.

Top comments (0)