Skip to content

fix: tolerate unknown Claude Code enum values in hook events#109

Open
punk-dev-robot wants to merge 1 commit into
eqtylab:mainfrom
punk-dev-robot:fix/hook-permission-mode-tolerance
Open

fix: tolerate unknown Claude Code enum values in hook events#109
punk-dev-robot wants to merge 1 commit into
eqtylab:mainfrom
punk-dev-robot:fix/hook-permission-mode-tolerance

Conversation

@punk-dev-robot
Copy link
Copy Markdown

@punk-dev-robot punk-dev-robot commented May 29, 2026

Summary

Claude Code hooks intermittently exited non-zero (most visibly UserPromptSubmit), showing a hook-error notice and silently dropping Block decisions.

permission_mode is typed as the PermissionMode enum, but Claude Code now sends values it doesn't model (e.g. dontAsk, auto). #[serde(default)] covers an absent field, not a present-but-unknown one: the engine evaluates the tolerant Value fine, but the typed re-parse for response formatting fails, ?-propagates, and exits 1 (a non-blocking hook error per spec).

  • Add #[serde(other)] Unknown to the externally-driven enums (PermissionMode, CompactTrigger, SessionSource, NotificationType, SessionEndReason); add documented Auto/DontAsk.
  • Demote per-invocation info!("Processing harness") to debug! so real errors surface.
  • Update claude_code README; add unit + CLI regression tests.

Claude Code hooks intermittently exited with a non-blocking error code
(most visibly for UserPromptSubmit), surfacing an INFO log line in the
transcript.

Root cause: `permission_mode` (part of CommonEventData, present on every
event) is typed as the `PermissionMode` enum, which only modeled four of
the six values Claude Code now sends. `#[serde(default)]` rescues an
absent field but not a present-but-unknown value. The engine evaluates the
tolerant `serde_json::Value` and succeeds, but the typed re-parse used for
response formatting (cupcake-cli/src/main.rs) then fails on values like
"dontAsk"/"auto", `?`-propagates, and the process exits 1. Per the Claude
Code hooks spec, exit 1 is a non-blocking error: the transcript shows a
hook-error notice plus the first stderr line. It also silently discarded
real Block decisions.

Changes:
- Add `#[serde(other)] Unknown` catch-all to the externally-driven event
  enums (PermissionMode, CompactTrigger, SessionSource, NotificationType,
  SessionEndReason) so deserialization never fails on a newer value; add
  the now-documented Auto/DontAsk PermissionMode variants.
- Demote the per-invocation `info!("Processing harness")` to `debug!` so a
  genuine error surfaces its real first stderr line, not noise.
- Update the claude_code README permission-mode list.
- Add regression tests: unit parse of dontAsk/unknown modes, and a CLI
  test asserting `cupcake eval` exits 0 with valid JSON for an unknown
  permission_mode.
@punk-dev-robot punk-dev-robot marked this pull request as ready for review May 29, 2026 09:22
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