modscode / コード参考書 / ツール呼び出しを止める(deny)
ツール呼び出しを止める(tool.call で deny)
settings.json の PreToolUse フックはシェルのスクリプトで止めますが、mod では on('tool.call', { tool: 'Bash' }, ...) で受け、next を呼ばずに { deny: '理由' } を返すだけで止まります。Claude は理由を読んで別の手を取ります。通すときは next(e)、書き換えて通すときは next({ ...e, command })。
最小の形
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)
})
}
modscode が公式ドキュメントの API で書いた最小の例です。自由に使えます。
実際の Mod のコード(6 本)
GitHub の公開 Mod から、図鑑が読んだコミットの該当行をそのまま引いています。見出しから Mod のページ(何をするか・良いところ・画面・コードが触るもの)へ、ファイル名から GitHub の該当行へ移れます。
写す前・入れる前に、必ず自分でコードを確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode は中身の安全を保証しません。
blast-radius deepseek-ai · ターミナル+デスクトップ · ★ 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 ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面
ライセンスの全文(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 · フックだけ · ★ 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 ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面
ライセンスの全文(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 · フックだけ · ★ 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 ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面
ライセンスの全文(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 · フックだけ · ★ 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 ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面
ライセンスの全文(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 · フックだけ · ★ 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 ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面
ライセンスの全文(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 · フックだけ · ★ 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 ライセンス。写すときは著作権表示を残してください。 この Mod のコードと画面
ライセンスの全文(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.
作り始める
フォルダーに .claude-plugin/plugin.json({"name": "my-mod"})と hooks/hooks.json({"modules": ["register.js"]})を置き、上のコードを hooks/register.js に保存して、claude --plugin-dir . で 1 セッションだけ読み込みます。claude plugin validate . で、フックするイベントと呼ぶ API の一覧が出ます。