Skip to content

feat(hooks): switch PreToolUse to JSON permissionDecision protocol#6

Merged
HeinrichvH merged 1 commit intomainfrom
feat/json-deny-protocol
Apr 22, 2026
Merged

feat(hooks): switch PreToolUse to JSON permissionDecision protocol#6
HeinrichvH merged 1 commit intomainfrom
feat/json-deny-protocol

Conversation

@HeinrichvH
Copy link
Copy Markdown
Owner

Replace the exit-2 + stderr pattern with the documented JSON protocol: emit {"hookSpecificOutput": {"permissionDecision": "deny", "permissionDecisionReason": ...}} on stdout and exit 0 for all three blocking paths (cache hit, successful worker routing, strict-mode worker failure).

Claude Code's current rendering treats both protocols as "hook blocking error" in the transcript, so there is no user-visible UX change today. The switch is a semantic correctness improvement: we are using the documented hook-decision API rather than repurposing exit 2. If Anthropic adds a true result-override primitive (e.g. toolResultOverride) or changes the rendering for deny-with-reason, we inherit it for free.

Loose-mode fallback stays on exit 0 + stderr warning (unchanged). post_tool_use still uses exit 2 — untouched in this pass.

Tests updated to parse JSON stdout and assert permissionDecision: deny plus the reason text. All 43 pass.

Replace the exit-2 + stderr pattern with the documented JSON protocol:
emit `{"hookSpecificOutput": {"permissionDecision": "deny",
"permissionDecisionReason": ...}}` on stdout and exit 0 for all three
blocking paths (cache hit, successful worker routing, strict-mode worker
failure).

Claude Code's current rendering treats both protocols as "hook blocking
error" in the transcript, so there is no user-visible UX change today.
The switch is a semantic correctness improvement: we are using the
documented hook-decision API rather than repurposing exit 2. If Anthropic
adds a true result-override primitive (e.g. `toolResultOverride`) or
changes the rendering for `deny`-with-reason, we inherit it for free.

Loose-mode fallback stays on exit 0 + stderr warning (unchanged).
post_tool_use still uses exit 2 — untouched in this pass.

Tests updated to parse JSON stdout and assert `permissionDecision: deny`
plus the reason text. All 43 pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@HeinrichvH HeinrichvH merged commit dab9f7b into main Apr 22, 2026
3 checks passed
@HeinrichvH HeinrichvH deleted the feat/json-deny-protocol branch April 22, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant