Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions plugins/multicorn-shield/hooks/scripts/pre-tool-use.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Claude Code PreToolUse hook: asks Shield whether a tool call is allowed.
* Fail-open on API errors or missing config so local work keeps moving.
* Fail-closed on API errors once config is loaded. Fail-open only if Shield is not configured (no config file, no API key).
*/

"use strict";
Expand Down Expand Up @@ -484,9 +484,9 @@ async function main() {
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
process.stderr.write(
`[multicorn-shield] PreToolUse: Shield API unreachable (${msg}). Allowing tool.\n`,
`[multicorn-shield] PreToolUse: Action blocked: Shield API unreachable, cannot verify permissions. (${msg})\n`,
);
process.exit(0);
process.exit(2);
}

const parsed = safeJsonParse(bodyText);
Expand Down Expand Up @@ -514,9 +514,9 @@ async function main() {
if (statusCode === 201) {
if (data === null || typeof data !== "object") {
process.stderr.write(
"[multicorn-shield] PreToolUse: unexpected Shield response. Allowing tool.\n",
"[multicorn-shield] PreToolUse: Action blocked: unexpected Shield response, cannot verify permissions.\n",
);
process.exit(0);
process.exit(2);
}
const st = String(/** @type {Record<string, unknown>} */ (data).status || "").toLowerCase();
if (st === "approved") {
Expand All @@ -527,19 +527,21 @@ async function main() {
process.exit(2);
}
process.stderr.write(
"[multicorn-shield] PreToolUse: ambiguous Shield status. Allowing tool.\n",
"[multicorn-shield] PreToolUse: Action blocked: ambiguous Shield status, cannot verify permissions.\n",
);
process.exit(0);
process.exit(2);
}

process.stderr.write(
`[multicorn-shield] PreToolUse: Shield returned HTTP ${String(statusCode)}. Allowing tool.\n`,
`[multicorn-shield] PreToolUse: Action blocked: Shield returned HTTP ${String(statusCode)}, cannot verify permissions.\n`,
);
process.exit(0);
process.exit(2);
}

main().catch((e) => {
const msg = e instanceof Error ? e.message : String(e);
process.stderr.write(`[multicorn-shield] PreToolUse: error (${msg}). Allowing tool.\n`);
process.exit(0);
process.stderr.write(
`[multicorn-shield] PreToolUse: Action blocked: unexpected error, cannot verify permissions. (${msg})\n`,
);
process.exit(2);
});
Loading