modscode JA

modscode / Code / Deny a tool call

Deny a tool call (tool.call and deny)

A PreToolUse settings hook blocks with a shell script; in a mod you handle on('tool.call', { tool: 'Bash' }, ...) and return { deny: 'reason' } without calling next. Claude reads the reason and tries something else. Let a call through with next(e), or change it with next({ ...e, command }).

on('tool.call', { tool: 'Bash' }){ deny: '…' }next(e)$.ui.ask

The smallest form

hooks/register.js
export function register(on) {
  on('tool.call', { tool: 'Bash' }, async ($, e, next) => {
    if (/\brm\s+-[a-zA-Z]*(rf|fr)\b/.test(e.command)) {
      // no call to next: the command never runs, and Claude reads this
      return { deny: 'rm -rf is blocked in this project. Delete the files one by one instead.' }
    }
    return next(e)
  })
}

Written by modscode with the API of the official docs. Free to use.

Real mods' code (6)

Quoted as is from public mods on GitHub, at the commit the gallery read. The heading leads to the mod's page (what it does, its good points, its design, what its code reaches); the file name leads to the lines on GitHub.

Check the code yourself before you copy or install it. Mods run unsandboxed, with your permissions. modscode does not vouch for what the code does.

blast-radius deepseek-ai · Terminal + desktop · ★ 244419

See what a risky command would change before it runs.

on("tool.call", { tool: "Bash" }, async ($, e, next) => {
  const risk = classify(String(e.command ?? ""));
  if (risk === null) return next(e);                 // everything else runs as normal

  const report = await measure($, risk, await $.session.cwd());  // git status, git clean -n, du, ...
  held = { command: e.command, risk, report, decision: null };
  const opened = await $.ui.open({ id: "blast-radius", title: "Blast Radius", focus: true });
  if (!opened.isPlaced) held.where = "band";         // too narrow for a pane: draw above the prompt

  while (held.decision === null && !next.signal.aborted) {
    await $.process.run(["sleep", "0.25"]);          // time inside $ calls doesn't count against the hook's time limit
  }
  if (held.decision === "proceed") return next(e);   // let it run
  return { deny: `Blast Radius held this command: the user pressed Cancel. It would have: ${report.summary}.` };
});

MIT licence. Keep its notice when you copy the code. Its code and design

Licence text (MIT)
MIT License

Copyright (c) 2026 DeepSeek

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

ruflo-testgen ruvnet · Hooks only · ★ 73986

Test gap detection, coverage analysis, and automated test generation — drives the testgaps background worker via hooks_worker-dispatch; SPARC Refinement-phase canonical owner

on('tool.call', async ($, e, next) => {
  const label = watched(e.tool, e)
  if (label === undefined) return next(e)
  s.stats.checked++
  s.stats.seen[label] = (s.stats.seen[label] ?? 0) + 1
  const reason = s.opts.guard ? verdict(e.tool, e) : undefined
  if (reason !== undefined) {
    s.stats.blocked++
    s.stats.lastReason = reason.slice(0, 160)
  }
  await flush($, s)
  return reason === undefined ? next(e) : { deny: reason }
})

MIT licence. Keep its notice when you copy the code. Its code and design

Licence text (MIT)
MIT License

Copyright (c) 2024-2026 ruvnet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

ruflo-security-audit ruvnet · Hooks only · ★ 73986

Security review, dependency scanning, policy gates, and CVE monitoring

on('tool.call', async ($, e, next) => {
  const label = watched(e.tool, e)
  if (label === undefined) return next(e)
  s.stats.checked++
  s.stats.seen[label] = (s.stats.seen[label] ?? 0) + 1
  const reason = s.opts.guard ? verdict(e.tool, e) : undefined
  if (reason !== undefined) {
    s.stats.blocked++
    s.stats.lastReason = reason.slice(0, 160)
  }
  await flush($, s)
  return reason === undefined ? next(e) : { deny: reason }
})

MIT licence. Keep its notice when you copy the code. Its code and design

Licence text (MIT)
MIT License

Copyright (c) 2024-2026 ruvnet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

ruflo-sparc ruvnet · Hooks only · ★ 73986

SPARC methodology — Specification, Pseudocode, Architecture, Refinement, Completion phases with gate checks

on('tool.call', async ($, e, next) => {
  const label = watched(e.tool, e)
  if (label === undefined) return next(e)
  s.stats.checked++
  s.stats.seen[label] = (s.stats.seen[label] ?? 0) + 1
  const reason = s.opts.guard ? verdict(e.tool, e) : undefined
  if (reason !== undefined) {
    s.stats.blocked++
    s.stats.lastReason = reason.slice(0, 160)
  }
  await flush($, s)
  return reason === undefined ? next(e) : { deny: reason }
})

MIT licence. Keep its notice when you copy the code. Its code and design

Licence text (MIT)
MIT License

Copyright (c) 2024-2026 ruvnet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

ruflo-workflows ruvnet · Hooks only · ★ 73986

Workflow automation across two surfaces: the 10 workflow_* MCP tools (create/run/execute/status/list/pause/resume/cancel/delete/template) with full state-machine lifecycle (created → running ↔ paused → completed/cancelled), and native Clau…

on('tool.call', async ($, e, next) => {
  const label = watched(e.tool, e)
  if (label === undefined) return next(e)
  s.stats.checked++
  s.stats.seen[label] = (s.stats.seen[label] ?? 0) + 1
  const reason = s.opts.guard ? verdict(e.tool, e) : undefined
  if (reason !== undefined) {
    s.stats.blocked++
    s.stats.lastReason = reason.slice(0, 160)
  }
  await flush($, s)
  return reason === undefined ? next(e) : { deny: reason }
})

MIT licence. Keep its notice when you copy the code. Its code and design

Licence text (MIT)
MIT License

Copyright (c) 2024-2026 ruvnet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

ruflo-x-gateway ruvnet · Hooks only · ★ 73986

Coordinate AI-agent swarms through signed federation messages, channels, and work claims. The remote Claude connector exposes a directory-safe Streamable HTTP MCP surface with OAuth-protected publishing and five ruv:// reference resources.

on('tool.call', async ($, e, next) => {
  const label = watched(e.tool, e)
  if (label === undefined) return next(e)
  s.stats.checked++
  s.stats.seen[label] = (s.stats.seen[label] ?? 0) + 1
  const reason = s.opts.guard ? verdict(e.tool, e) : undefined
  if (reason !== undefined) {
    s.stats.blocked++
    s.stats.lastReason = reason.slice(0, 160)
  }
  await flush($, s)
  return reason === undefined ? next(e) : { deny: reason }
})

MIT licence. Keep its notice when you copy the code. Its code and design

Licence text (MIT)
MIT License

Copyright (c) 2024-2026 ruvnet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Start building

Put a .claude-plugin/plugin.json ({"name": "my-mod"}) and a hooks/hooks.json ({"modules": ["register.js"]}) in a folder, save the code above as hooks/register.js, and run claude --plugin-dir . to load it for one session. claude plugin validate . lists the events it hooks and the APIs it calls.

Other patterns